diff --git a/Step.Config/Config/maintenancesConfig.xml b/Step.Config/Config/maintenancesConfig.xml
index 9d4f37ad..3417b78f 100644
--- a/Step.Config/Config/maintenancesConfig.xml
+++ b/Step.Config/Config/maintenancesConfig.xml
@@ -8,7 +8,7 @@
10
01/12/1999
- interval
+ machine_interval
1
@@ -22,4 +22,15 @@
exp_date
2
+
+ 3
+
+ Test
+ Ita
+
+ 20
+ 01/12/1999
+ time_interval
+ 2
+
\ No newline at end of file
diff --git a/Step.Config/ServerConfig.cs b/Step.Config/ServerConfig.cs
index a7eb68e8..d0c84edd 100644
--- a/Step.Config/ServerConfig.cs
+++ b/Step.Config/ServerConfig.cs
@@ -15,6 +15,8 @@ namespace Step.Config
public static MachineModel MachineConfig;
public static List MaintenancesConfig;
+ public static List FunctionsAccessConfig;
+
public static AreasConfigModel ProductionConfig;
public static AreasConfigModel ToolingConfig;
public static AreasConfigModel ReportConfig;
diff --git a/Step.Config/ServerConfigController.cs b/Step.Config/ServerConfigController.cs
index c2c29c96..2e907db3 100644
--- a/Step.Config/ServerConfigController.cs
+++ b/Step.Config/ServerConfigController.cs
@@ -65,10 +65,10 @@ namespace Step.Config
LocalizedNames = x.Element("localizedNames").Elements().ToDictionary( // Read names list
y => y.Attribute("langKey").Value, y => y.Value
),
- Intervall = TimeSpan.FromHours(Convert.ToDouble(x.Element("interval").Value)),
+ Intervall = TimeSpan.FromMinutes(Convert.ToDouble(x.Element("interval").Value)),
Deadline = DateTime.Parse(x.Element("deadline").Value),
Type = x.Element("type").Value,
- CouterId = Convert.ToInt32(x.Element("counterId").Value)
+ CouterId = Convert.ToInt32(x.Element("counterId").Value)
}
)
.ToList();
diff --git a/Step.Database/Controllers/FunctionsAccessController.cs b/Step.Database/Controllers/FunctionsAccessController.cs
index e6de19a8..e668ebb4 100644
--- a/Step.Database/Controllers/FunctionsAccessController.cs
+++ b/Step.Database/Controllers/FunctionsAccessController.cs
@@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using static CMS_CORE_Library.DataStructures;
+using static Step.Config.ServerConfig;
namespace Step.Database.Controllers
{
@@ -31,7 +32,7 @@ namespace Step.Database.Controllers
.FirstOrDefault();
}
- public List GetFunctionAccess(int roleLevel)
+ public List GetFunctionsAccess(int roleLevel)
{
return dbCtx
.FunctionsAccess
@@ -47,11 +48,16 @@ namespace Step.Database.Controllers
.ToList();
}
- public List GetFunctionsMappedWithPlc(List functionalityList)
+ public List FindAll()
{
return dbCtx
.FunctionsAccess
- .ToList() // Find all function access
+ .ToList();
+ }
+
+ public List GetFunctionsMappedWithPlc(List functionalityList)
+ {
+ return FunctionsAccessConfig // Find all function access
.Select(f => new DTORuntimeFunctionalityModel()
{
Id = f.FunctionAccessId,
diff --git a/Step.Database/Controllers/MaintenancesController.cs b/Step.Database/Controllers/MaintenancesController.cs
index 43cc81e4..b125a45f 100644
--- a/Step.Database/Controllers/MaintenancesController.cs
+++ b/Step.Database/Controllers/MaintenancesController.cs
@@ -79,7 +79,7 @@ namespace Step.Database.Controllers
{
old.MaintenanceId = x.Id;
old.Deadline = x.Deadline;
- old.Intervall = x.Intervall.TotalMinutes;
+ old.Interval = x.Intervall.TotalMinutes;
old.Type = x.Type;
old.CounterId = x.CouterId;
return old;
@@ -96,7 +96,7 @@ namespace Step.Database.Controllers
{
MaintenanceId = x.Id,
Deadline = x.Deadline,
- Intervall = x.Intervall.TotalMinutes,
+ Interval = x.Intervall.TotalMinutes,
Type = x.Type,
CounterId = x.CouterId
})
diff --git a/Step.Database/DatabaseContext.cs b/Step.Database/DatabaseContext.cs
index f5e170a2..e865ff0d 100644
--- a/Step.Database/DatabaseContext.cs
+++ b/Step.Database/DatabaseContext.cs
@@ -37,7 +37,7 @@ namespace Step.Database
return new DatabaseContext();
}
- public static void TestDatabaseConnection()
+ public static void SetUpDbConnectionAndDbConfig()
{
try
{
@@ -63,6 +63,12 @@ namespace Step.Database
{
maintenancesController.CheckDifferencesFromDbAndXml();
}
+
+ using (FunctionsAccessController functionsAccess = new FunctionsAccessController())
+ {
+ FunctionsAccessConfig = functionsAccess.FindAll();
+ }
+
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
diff --git a/Step.Model/DTOModels/DTOExpiredMaintenanceModel.cs b/Step.Model/DTOModels/DTOExpiredMaintenanceModel.cs
index e644e15a..d0b71a60 100644
--- a/Step.Model/DTOModels/DTOExpiredMaintenanceModel.cs
+++ b/Step.Model/DTOModels/DTOExpiredMaintenanceModel.cs
@@ -4,7 +4,7 @@ namespace Step.Model.DTOModels
{
public class DTOExpiredMaintenanceModel
{
- public string Id { get; set; }
+ public int Id { get; set; }
public DateTime ExpirationDate { get; set; }
}
}
\ No newline at end of file
diff --git a/Step.Model/DatabaseModels/MaintenanceModel.cs b/Step.Model/DatabaseModels/MaintenanceModel.cs
index 5c7a6545..31222155 100644
--- a/Step.Model/DatabaseModels/MaintenanceModel.cs
+++ b/Step.Model/DatabaseModels/MaintenanceModel.cs
@@ -13,7 +13,7 @@ namespace Step.Model.DatabaseModels
public int MaintenanceId { get; set; }
[Column("intervall")]
- public double Intervall { get; set; }
+ public double Interval { get; set; }
[Column("deadline")]
public DateTime Deadline { get; set; }
diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs
index 4926b70d..467246be 100644
--- a/Step.NC/NcHandler.cs
+++ b/Step.NC/NcHandler.cs
@@ -337,12 +337,14 @@ namespace Step.NC
return cmsError;
}
- public CmsError GetExpiredMaintenances()
+ public CmsError GetExpiredMaintenances(out List expiredMaintenance)
{
- List expiredMaintenance = new List();
+ // Return value
+ expiredMaintenance = new List();
+ // List of PLC counters
List counters = new List();
-
+ // Populate counters
CmsError cmsError = numericalControl.PLC_RMachineCounters(ref counters);
if (cmsError.IsError())
return cmsError;
@@ -353,7 +355,7 @@ namespace Step.NC
List performedMaintenance = maintenancesController.FindLastMaintenance();
// Get all the active maintenances
- List maintenances = maintenancesController.FindAll();
+ List maintenances = maintenancesController.FindAll(); // TODO db or config file?
foreach (var maintenance in maintenances)
{
@@ -362,33 +364,67 @@ namespace Step.NC
switch (maintenance.Type)
{
- case "interval":
+ case MAINT_MACHINE_INTERVAL_TYPE:
{
// Get matching counter for the current maintenance
var counter = counters.Find(x => x.Id == maintenance.CounterId);
- // PLC - LASTPERFORMED >= MAINTENANCE_INTERVAL
- if (counter.Value - performed.CounterValue >= maintenance.Intervall)
+ int perfVal = 0;
+ if (performed != null)
+ perfVal = performed.CounterValue;
+
+ // MAINTENANCE_INTERVAL <= PLC - LASTPERFORMED
+ if (maintenance.Interval <= counter.Value - perfVal )
{
+ // Add item to return list
expiredMaintenance.Add(new DTOExpiredMaintenanceModel()
{
- Id = MAINTENANCE_PREFIX_ID + maintenance.MaintenanceId,
+ Id = maintenance.MaintenanceId,
ExpirationDate = DateTime.Now
});
}
}
break;
-
- case "exp_date":
+ case MAINT_EXPIRATION_DATE_TYPE:
{
+ // Already performed
+ if (performed != null)
+ break;
+ // DEADLINE <= NOW
if (maintenance.Deadline <= DateTime.Now)
+ // Add item to return list
expiredMaintenance.Add(new DTOExpiredMaintenanceModel()
{
- Id = MAINTENANCE_PREFIX_ID + maintenance.MaintenanceId,
+ Id = maintenance.MaintenanceId,
ExpirationDate = maintenance.Deadline
});
}
break;
+ case MAINT_TIME_INTERVAL_TYPE:
+ {
+ // Get last performed, default value is maintenance creation date
+ DateTime perfDate = maintenance.CreationDate;
+ if (performed != null)
+ perfDate = performed.Date;
+
+ // Now - last performed = elapsed interval since last maintenance
+ TimeSpan timePassedFromLastMaint = DateTime.Now.Subtract(performed.Date);
+ // Convert in minutes
+ double minutesPassedFromLastMaint = timePassedFromLastMaint.TotalMinutes;
+
+ // Interval - passed minutes since last maintenance
+ if(maintenance.Interval <= minutesPassedFromLastMaint)
+ {
+ // Exp date = now - ( expiration intervall)
+ DateTime expirationDate = DateTime.Now.Subtract(TimeSpan.FromMinutes(minutesPassedFromLastMaint - maintenance.Interval));
+ expiredMaintenance.Add(new DTOExpiredMaintenanceModel()
+ {
+ Id = maintenance.MaintenanceId,
+ ExpirationDate = expirationDate
+ });
+ }
+ }
+ break;
}
}
}
diff --git a/Step.Tasks/ThreadsFunctions.cs b/Step.Tasks/ThreadsFunctions.cs
index abaec1a7..04f56837 100644
--- a/Step.Tasks/ThreadsFunctions.cs
+++ b/Step.Tasks/ThreadsFunctions.cs
@@ -298,14 +298,14 @@ public static class ThreadsFunctions
sw.Restart();
if (ncHandler.numericalControl.NC_IsConnected())
- {
+ {
// Get Data from database and PLC
- libraryError = ncHandler.GetExpiredMaintenances();
+ libraryError = ncHandler.GetExpiredMaintenances(out List expiredMaintenances);
if (libraryError.errorCode != 0)
ManageLibraryError(libraryError);
- //else
+ else
// Send through signalR
- // MessageServices.Current.Publish(SEND_FUNCTIONALITY_DATA, null, functionsAccessList);
+ MessageServices.Current.Publish(SEND_EXPIRED_MAINTENANCES_DATA, null, expiredMaintenances);
}
else
TryNcConnection();
@@ -316,7 +316,7 @@ public static class ThreadsFunctions
ReadFunctionTimes++;
// Wait
- Thread.Sleep(200);
+ Thread.Sleep(30000);
}
}
catch (ThreadAbortException)
diff --git a/Step.Utils/Constants.cs b/Step.Utils/Constants.cs
index 1df2fcde..b7431f4c 100644
--- a/Step.Utils/Constants.cs
+++ b/Step.Utils/Constants.cs
@@ -83,9 +83,15 @@ namespace Step.Utils
public const string SEND_AXES = "SEND_AXES";
public const string SEND_PROCESSES_DATA = "SEND_PROCESSES_STATUS";
public const string SEND_FUNCTIONALITY_DATA = "SEND_FUNCTION_DATA";
+ public const string SEND_EXPIRED_MAINTENANCES_DATA = "SEND_EXPIRED_MAINTENANCES_DATA";
// ID prefix
public const string MAINTENANCE_PREFIX_ID = "MAINT_";
+
+ // Maintenances types
+ public const string MAINT_MACHINE_INTERVAL_TYPE = "machine_interval";
+ public const string MAINT_TIME_INTERVAL_TYPE = "time_interval";
+ public const string MAINT_EXPIRATION_DATE_TYPE = "exp_date";
}
}
diff --git a/Step/Controllers/WebApi/AuthorizationController.cs b/Step/Controllers/WebApi/AuthorizationController.cs
index a8da7d55..0262f202 100644
--- a/Step/Controllers/WebApi/AuthorizationController.cs
+++ b/Step/Controllers/WebApi/AuthorizationController.cs
@@ -23,7 +23,7 @@ namespace Step.Controllers.WebApi
var userRoleLevel = identity.Claims.Where(c => c.Type == ROLE_LEVEL_KEY).SingleOrDefault();
- List functionsList = acController.GetFunctionAccess(Convert.ToInt32(userRoleLevel.Value));
+ List functionsList = acController.GetFunctionsAccess(Convert.ToInt32(userRoleLevel.Value));
if (functionsList == null)
return NotFound();
diff --git a/Step/Controllers/WebApi/LanguageController.cs b/Step/Controllers/WebApi/LanguageController.cs
index d3814a60..2a706817 100644
--- a/Step/Controllers/WebApi/LanguageController.cs
+++ b/Step/Controllers/WebApi/LanguageController.cs
@@ -62,8 +62,9 @@ namespace Step.Controllers.WebApi
public static string GetValueFromMaintenanceNameList(Dictionary localizedNames, string language, int maintenanceId)
{
+ // Find text from names by language id
var value = localizedNames.Where(y => y.Key == language).FirstOrDefault();
-
+ // Set default value
if (value.Key == null)
return "Maintenance string not found for id: " + maintenanceId;
else
diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs
index 222ad929..2436c678 100644
--- a/Step/Listeners/ListenersHandler.cs
+++ b/Step/Listeners/ListenersHandler.cs
@@ -57,6 +57,10 @@ namespace Step.Listeners
{
SignalRListener.SendFunctionalityData(a);
}));
+ infos.Add(MessageServices.Current.Subscribe(SEND_EXPIRED_MAINTENANCES_DATA, async (a, b) =>
+ {
+ SignalRListener.SendExpMaintenancesData(a);
+ }));
}
public static void Stop()
diff --git a/Step/Listeners/SignalR/SignalRListener.cs b/Step/Listeners/SignalR/SignalRListener.cs
index e330d1bc..6ff9310f 100644
--- a/Step/Listeners/SignalR/SignalRListener.cs
+++ b/Step/Listeners/SignalR/SignalRListener.cs
@@ -59,5 +59,11 @@ namespace Step.Listeners.SignalR
var context = GlobalHost.ConnectionManager.GetHubContext();
context.Clients.Group("ncData").functionalityData(functionalityData);
}
+
+ public static void SendExpMaintenancesData(object expiredMaintenances)
+ {
+ var context = GlobalHost.ConnectionManager.GetHubContext();
+ context.Clients.Group("ncData").expiredMaintenances(expiredMaintenances);
+ }
}
}
diff --git a/Step/program.cs b/Step/program.cs
index 0573eae3..cb37a541 100644
--- a/Step/program.cs
+++ b/Step/program.cs
@@ -33,7 +33,7 @@ namespace Step
ServerConfigController.ReadStartupConfig();
- DatabaseContext.TestDatabaseConnection();
+ DatabaseContext.SetUpDbConnectionAndDbConfig();
// Start self host application
string configuredUri = "http://*:" + ServerStartupConfig.ServerPort.ToString();