refactoring2
This commit is contained in:
@@ -38,92 +38,76 @@ namespace Simulator.Data
|
||||
|
||||
public IReadOnlyDictionary<ComponentType, DataMapper> DataMappers => _dataMapperDict;
|
||||
|
||||
private ComponentUIBinder _uiBinder;
|
||||
public ComponentUIBinder UIBinder => _uiBinder;
|
||||
|
||||
public ComponentPoolManager(Transform parentTransform)
|
||||
{
|
||||
_parentTransform = parentTransform;
|
||||
}
|
||||
|
||||
public void InitializeUIBinder()
|
||||
{
|
||||
_uiBinder = new ComponentUIBinder();
|
||||
_uiBinder.Initialize();
|
||||
}
|
||||
|
||||
public void InitializeAllPools()
|
||||
{
|
||||
InitializeSourcePoolAsync().ContinueWith(() =>
|
||||
{
|
||||
var mask = new DataMask();
|
||||
mask.ObjectName = "Source";
|
||||
mask.ObjectIdKey = "component_id";
|
||||
mask["component_id"] = "";
|
||||
mask["event_name"] = "";
|
||||
mask["timestamp"] = new DateTime();
|
||||
mask["data"] = new DataMask()
|
||||
{
|
||||
["entity_ids"] = new List<string>(),
|
||||
["total_entity"] = 0
|
||||
};
|
||||
_dataMapperDict.Add(ComponentType.Source, new DataMapper(mask));
|
||||
});
|
||||
InitializeSourcePoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Source, CreateDataMapper(ComponentType.Source)));
|
||||
InitializeSinkPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Sink, CreateDataMapper(ComponentType.Sink)));
|
||||
InitializeQueuePoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Queue, null));
|
||||
InitializeRackPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Rack, CreateDataMapper(ComponentType.Rack)));
|
||||
InitializeAsrsPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.ASRS, CreateDataMapper(ComponentType.ASRS)));
|
||||
InitializeRobotArmPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.RobotArm, CreateDataMapper(ComponentType.RobotArm)));
|
||||
InitializeProcessorPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Processor, CreateDataMapper(ComponentType.Processor)));
|
||||
InitializeWorkerPoolAsync().ContinueWith(() => _dataMapperDict.Add(ComponentType.Worker, CreateDataMapper(ComponentType.Worker)));
|
||||
}
|
||||
|
||||
InitializeSinkPoolAsync().ContinueWith(() =>
|
||||
private DataMapper CreateDataMapper(ComponentType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
var mask = new DataMask();
|
||||
mask.ObjectName = "Sink";
|
||||
mask.ObjectIdKey = "component_id";
|
||||
mask["component_id"] = "";
|
||||
mask["event_name"] = "";
|
||||
mask["timestamp"] = new DateTime();
|
||||
mask["data"] = new DataMask()
|
||||
{
|
||||
["entity_ids"] = new List<string>(),
|
||||
};
|
||||
_dataMapperDict.Add(ComponentType.Sink, new DataMapper(mask));
|
||||
});
|
||||
case ComponentType.Source:
|
||||
return new DataMapper(CreateEventMask("Source", new DataMask
|
||||
{
|
||||
["entity_ids"] = new List<string>(),
|
||||
["total_entity"] = 0
|
||||
}));
|
||||
case ComponentType.Sink:
|
||||
return new DataMapper(CreateEventMask("Sink", new DataMask
|
||||
{
|
||||
["entity_ids"] = new List<string>()
|
||||
}));
|
||||
case ComponentType.RobotArm:
|
||||
return new DataMapper(CreateEventMask("RobotArm", new DataMask
|
||||
{
|
||||
["entity_id"] = "",
|
||||
["processing_time"] = 0.0f,
|
||||
["from"] = "",
|
||||
["to"] = ""
|
||||
}));
|
||||
case ComponentType.Rack:
|
||||
return new DataMapper(new DataMask { ObjectName = "rack", ObjectIdKey = "component_id" });
|
||||
case ComponentType.ASRS:
|
||||
return new DataMapper(new DataMask { ObjectName = "asrs", ObjectIdKey = "component_id" });
|
||||
default:
|
||||
return new DataMapper(new DataMask());
|
||||
}
|
||||
}
|
||||
|
||||
InitializeQueuePoolAsync().ContinueWith(() =>
|
||||
private DataMask CreateEventMask(string objectName, DataMask dataMask)
|
||||
{
|
||||
var mask = new DataMask
|
||||
{
|
||||
_dataMapperDict.Add(ComponentType.Queue, null);
|
||||
});
|
||||
|
||||
InitializeRackPoolAsync().ContinueWith(() =>
|
||||
{
|
||||
var mask = new DataMask();
|
||||
mask.ObjectName = "rack";
|
||||
mask.ObjectIdKey = "component_id";
|
||||
_dataMapperDict.Add(ComponentType.Rack, new DataMapper(mask));
|
||||
});
|
||||
|
||||
InitializeAsrsPoolAsync().ContinueWith(() =>
|
||||
{
|
||||
var mask = new DataMask();
|
||||
mask.ObjectName = "asrs";
|
||||
mask.ObjectIdKey = "component_id";
|
||||
_dataMapperDict.Add(ComponentType.ASRS, new DataMapper(mask));
|
||||
});
|
||||
|
||||
InitializeRobotArmPoolAsync().ContinueWith(() =>
|
||||
{
|
||||
var mask = new DataMask();
|
||||
mask.ObjectName = "RobotArm";
|
||||
mask.ObjectIdKey = "component_id";
|
||||
mask["component_id"] = "";
|
||||
mask["event_name"] = "";
|
||||
mask["timestamp"] = new DateTime();
|
||||
mask["data"] = new DataMask()
|
||||
{
|
||||
["entity_id"] = "",
|
||||
["processing_time"] = 0.0f,
|
||||
["from"] = "",
|
||||
["to"] = ""
|
||||
};
|
||||
_dataMapperDict.Add(ComponentType.RobotArm, new DataMapper(mask));
|
||||
});
|
||||
|
||||
InitializeProcessorPoolAsync().ContinueWith(() =>
|
||||
{
|
||||
_dataMapperDict.Add(ComponentType.Processor, new DataMapper(new DataMask()));
|
||||
});
|
||||
|
||||
InitializeWorkerPoolAsync().ContinueWith(() =>
|
||||
{
|
||||
_dataMapperDict.Add(ComponentType.Worker, new DataMapper(new DataMask()));
|
||||
});
|
||||
ObjectName = objectName,
|
||||
ObjectIdKey = "component_id",
|
||||
["component_id"] = "",
|
||||
["event_name"] = "",
|
||||
["timestamp"] = new DateTime(),
|
||||
["data"] = dataMask
|
||||
};
|
||||
return mask;
|
||||
}
|
||||
|
||||
#region Pool Initialization
|
||||
@@ -198,96 +182,47 @@ namespace Simulator.Data
|
||||
{
|
||||
var registry = new Dictionary<string, ComponentBase>();
|
||||
|
||||
if (data.production_system != null)
|
||||
var ps = data.production_system;
|
||||
if (ps != null)
|
||||
{
|
||||
if (data.production_system.sources != null)
|
||||
{
|
||||
foreach (var component in data.production_system.sources)
|
||||
{
|
||||
var source = _sourcePool.GetItem($"{component.name}");
|
||||
source.componentType = ComponentType.Source;
|
||||
source.SetComponent(component);
|
||||
registry.Add(component.name, source);
|
||||
}
|
||||
}
|
||||
if (data.production_system.sinks != null)
|
||||
{
|
||||
foreach (var component in data.production_system.sinks)
|
||||
{
|
||||
var sink = _sinkPool.GetItem($"{component.name}");
|
||||
sink.componentType = ComponentType.Sink;
|
||||
sink.SetComponent(component);
|
||||
registry.Add(component.name, sink);
|
||||
}
|
||||
}
|
||||
if (data.production_system.racks != null)
|
||||
{
|
||||
foreach (var component in data.production_system.racks)
|
||||
{
|
||||
var rack = _rackPool.GetItem($"{component.name}");
|
||||
rack.componentType = ComponentType.Rack;
|
||||
rack.SetComponent(component);
|
||||
registry.Add(component.name, rack);
|
||||
}
|
||||
}
|
||||
if (data.production_system.asrs != null)
|
||||
{
|
||||
foreach (var component in data.production_system.asrs)
|
||||
{
|
||||
var asrs = _asrsPool.GetItem($"{component.name}");
|
||||
asrs.componentType = ComponentType.ASRS;
|
||||
asrs.SetComponent(component);
|
||||
registry.Add(component.name, asrs);
|
||||
}
|
||||
}
|
||||
if (data.production_system.robot_arms != null)
|
||||
{
|
||||
foreach (var component in data.production_system.robot_arms)
|
||||
{
|
||||
var robotArm = _robotArmPool.GetItem($"{component.name}");
|
||||
robotArm.componentType = ComponentType.RobotArm;
|
||||
robotArm.SetComponent(component);
|
||||
registry.Add(component.name, robotArm);
|
||||
}
|
||||
}
|
||||
if (data.production_system.processors != null)
|
||||
{
|
||||
foreach (var component in data.production_system.processors)
|
||||
{
|
||||
var processor = _processorPool.GetItem($"{component.name}");
|
||||
processor.componentType = ComponentType.Processor;
|
||||
processor.SetComponent(component);
|
||||
registry.Add(component.name, processor);
|
||||
}
|
||||
}
|
||||
SpawnGroup(ps.sources, _sourcePool, ComponentType.Source, (c, d) => c.SetComponent(d), registry);
|
||||
SpawnGroup(ps.sinks, _sinkPool, ComponentType.Sink, (c, d) => c.SetComponent(d), registry);
|
||||
SpawnGroup(ps.racks, _rackPool, ComponentType.Rack, (c, d) => c.SetComponent(d), registry);
|
||||
SpawnGroup(ps.asrs, _asrsPool, ComponentType.ASRS, (c, d) => c.SetComponent(d), registry);
|
||||
SpawnGroup(ps.robot_arms, _robotArmPool, ComponentType.RobotArm, (c, d) => c.SetComponent(d), registry);
|
||||
SpawnGroup(ps.processors, _processorPool, ComponentType.Processor, (c, d) => c.SetComponent(d), registry);
|
||||
}
|
||||
if (data.infrastructure != null)
|
||||
|
||||
var infra = data.infrastructure;
|
||||
if (infra != null)
|
||||
{
|
||||
if (data.infrastructure.queues != null)
|
||||
{
|
||||
foreach (var component in data.infrastructure.queues)
|
||||
{
|
||||
var queue = _queuePool.GetItem($"{component.name}");
|
||||
queue.componentType = ComponentType.Queue;
|
||||
queue.SetComponent(component);
|
||||
registry.Add(component.name, queue);
|
||||
}
|
||||
}
|
||||
if (data.infrastructure.resources != null)
|
||||
{
|
||||
foreach (var component in data.infrastructure.resources)
|
||||
{
|
||||
var worker = _workerPool.GetItem($"{component.name}");
|
||||
worker.componentType = ComponentType.Worker;
|
||||
worker.SetComponent(component);
|
||||
registry.Add(component.name, worker);
|
||||
}
|
||||
}
|
||||
SpawnGroup(infra.queues, _queuePool, ComponentType.Queue, (c, d) => c.SetComponent(d), registry);
|
||||
SpawnGroup(infra.resources, _workerPool, ComponentType.Worker, (c, d) => c.SetComponent(d), registry);
|
||||
}
|
||||
|
||||
return registry;
|
||||
}
|
||||
|
||||
private void SpawnGroup<TComp, TData>(
|
||||
List<TData> items,
|
||||
GameObjectPool<TComp> pool,
|
||||
ComponentType type,
|
||||
Action<TComp, TData> setup,
|
||||
Dictionary<string, ComponentBase> registry)
|
||||
where TComp : ComponentBase
|
||||
where TData : ComponentDataBase
|
||||
{
|
||||
if (items == null) return;
|
||||
foreach (var item in items)
|
||||
{
|
||||
var comp = pool.GetItem(item.name);
|
||||
comp.componentType = type;
|
||||
setup(comp, item);
|
||||
_uiBinder.BindStandardComponent(comp);
|
||||
registry.Add(item.name, comp);
|
||||
}
|
||||
}
|
||||
|
||||
public ComponentBase FindActiveItem(ComponentType type, string componentId)
|
||||
{
|
||||
switch (type)
|
||||
|
||||
Reference in New Issue
Block a user