|
@@ -28,7 +28,7 @@ namespace WCS.Core
|
|
|
|
|
|
#region Static
|
|
|
static List<World> _Worlds;
|
|
|
- public static List<World> Worlds
|
|
|
+ internal static List<World> Worlds
|
|
|
{
|
|
|
get
|
|
|
{
|
|
@@ -43,6 +43,7 @@ namespace WCS.Core
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public static void StartAll()
|
|
|
{
|
|
|
//MM_BeginPeriod(1);
|
|
@@ -236,7 +237,45 @@ namespace WCS.Core
|
|
|
DoLogics(wt.Items);
|
|
|
sw.Stop();
|
|
|
wt.Total = sw.ElapsedMilliseconds;
|
|
|
- list.AddSafe(wt);
|
|
|
+ list.AddSafe(wt);
|
|
|
+
|
|
|
+ DoAddtional();
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ ConcurrentQueue<Action> Actions = new ConcurrentQueue<Action>();
|
|
|
+ void DoAddtional()
|
|
|
+ {
|
|
|
+ while (Actions.TryDequeue(out Action? action))
|
|
|
+ {
|
|
|
+ if (action == null)
|
|
|
+ throw new Exception("World.DoAddtional未知错误!");
|
|
|
+ action();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ internal T _Do<TWorld,T>(Func<TWorld,T> func) where TWorld:World
|
|
|
+ {
|
|
|
+ var flag = false;
|
|
|
+ T result=default(T);
|
|
|
+ Actions.Enqueue(() =>
|
|
|
+ {
|
|
|
+ result = func((TWorld)this);
|
|
|
+ flag = true;
|
|
|
+ });
|
|
|
+ while (!flag)
|
|
|
+ Thread.Sleep(1);
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ internal void _Do<TWorld>(Action<TWorld> action) where TWorld : World
|
|
|
+ {
|
|
|
+ _Do<TWorld, int>(w =>
|
|
|
+ {
|
|
|
+ action(w);
|
|
|
+ return 1;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
void LoadPlcData(List<WorkTimes> list)
|
|
@@ -319,11 +358,18 @@ namespace WCS.Core
|
|
|
|
|
|
public T GetSystem<T>() where T : SystemBase
|
|
|
{
|
|
|
- var sys = SystemGroups.SelectMany(v => v.Value).Where(v => v.GetType() == typeof(T)).FirstOrDefault() as T;
|
|
|
+ var sys = Systems.Where(v => v.GetType() == typeof(T)).FirstOrDefault() as T;
|
|
|
if (sys == null)
|
|
|
throw new Exception($"世界{GetType().Name}中不存在系统{typeof(T).Name}");
|
|
|
return sys;
|
|
|
}
|
|
|
+
|
|
|
+ public SystemBase[] Systems
|
|
|
+ {
|
|
|
+ get {
|
|
|
+ return SystemGroups.SelectMany(v => v.Value).ToArray();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|