Added new library with maintenances counters
Added maintenances thread
This commit is contained in:
Lucio Maranta
2018-02-14 17:33:05 +01:00
parent ff11711599
commit ac91aa08aa
19 changed files with 586 additions and 114 deletions
+63 -77
View File
@@ -1,25 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using CMS_CORE;
using CMS_CORE.Demo;
using CMS_CORE.Fanuc;
using CMS_CORE.Osai;
using CMS_CORE.Siemens;
using Step.NC;
using static Step.Config.ServerConfig;
using static Step.Utils.Constants;
using TeamDev.SDK.MVVM;
using System.Diagnostics;
using static Step.Utils.Constants;
namespace Step.Core
{
public static class ThreadsHandler
{
private static List<Action> ThreadFunctionsList = new List<Action>
public static class ThreadsHandler
{
private static List<Action> ThreadFunctionsList = new List<Action>
{
ThreadsFunctions.ReadAlarms,
ThreadsFunctions.ReadNcGenericInfo,
@@ -27,71 +16,68 @@ namespace Step.Core
ThreadsFunctions.ReadPowerOnData,
ThreadsFunctions.StatThread,
ThreadsFunctions.ReadProcessesPPStatus,
ThreadsFunctions.ReadEnabledFunctionality
ThreadsFunctions.ReadEnabledFunctionality,
ThreadsFunctions.ReadExpiredMaintenances
};
private volatile static List<Thread> RunningThreadsList = new List<Thread>();
internal volatile static Dictionary<String, String> RunningThreadStatus = new Dictionary<String, String>();
public static void Start()
{
ThreadsFunctions.TryNcConnection();
}
private volatile static List<Thread> RunningThreadsList = new List<Thread>();
internal volatile static Dictionary<String, String> RunningThreadStatus = new Dictionary<String, String>();
public static void StartWorkers()
{
RunningThreadStatus.Clear();
// For each function run in the list a thread
ThreadFunctionsList.ForEach(threadFunction =>
{
// Run new Thread in the list
Thread t = new Thread(() =>
threadFunction()
);
t.Start();
// Add thread to running threads list
lock (RunningThreadsList)
RunningThreadsList.Add(t);
RunningThreadStatus.Add(threadFunction.Method.Name, "---");
});
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
}
public static void Stop()
{
// Stop each thread
lock (RunningThreadsList)
RunningThreadsList.ForEach(thread =>
{
thread.Abort();
});
// Remove threads from running status
lock (RunningThreadsList)
RunningThreadsList.Clear();
RunningThreadStatus.Clear();
RunningThreadStatus.Add("TryNcConnection", "---");
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
}
public static void Close()
{
//Abort Nc Read Threads
RunningThreadsList.ForEach(thread =>
public static void Start()
{
thread.Abort();
});
ThreadsFunctions.TryNcConnection();
}
//Abort Connect Thread
ThreadsFunctions.AbortNcConnection();
public static void StartWorkers()
{
RunningThreadStatus.Clear();
// For each function run in the list a thread
ThreadFunctionsList.ForEach(threadFunction =>
{
// Run new Thread in the list
Thread t = new Thread(() =>
threadFunction()
);
t.Start();
// Add thread to running threads list
lock (RunningThreadsList)
RunningThreadsList.Add(t);
RunningThreadStatus.Add(threadFunction.Method.Name, "---");
});
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
}
public static void Stop()
{
// Stop each thread
lock (RunningThreadsList)
RunningThreadsList.ForEach(thread =>
{
thread.Abort();
});
// Remove threads from running status
lock (RunningThreadsList)
RunningThreadsList.Clear();
RunningThreadStatus.Clear();
RunningThreadStatus.Add("TryNcConnection", "---");
MessageServices.Current.Publish(SEND_THREADS_STATUS, null, RunningThreadStatus);
}
public static void Close()
{
//Abort Nc Read Threads
RunningThreadsList.ForEach(thread =>
{
thread.Abort();
});
//Abort Connect Thread
ThreadsFunctions.AbortNcConnection();
}
}
}
}
}