diff --git a/Step.Config/serverConfig.xml b/Step.Config/Config/areasConfig.xml similarity index 71% rename from Step.Config/serverConfig.xml rename to Step.Config/Config/areasConfig.xml index ce103f0f..d725992b 100644 --- a/Step.Config/serverConfig.xml +++ b/Step.Config/Config/areasConfig.xml @@ -1,17 +1,5 @@ - + - - DEMO - true - 127.0.0.1 - 8080 - Ares 37 OF - - - 9000 - en - true - true diff --git a/Step.Config/serverConfigValidator.xsd b/Step.Config/Config/areasConfigValidator.xsd similarity index 70% rename from Step.Config/serverConfigValidator.xsd rename to Step.Config/Config/areasConfigValidator.xsd index 61f5a345..ae2b4dbf 100644 --- a/Step.Config/serverConfigValidator.xsd +++ b/Step.Config/Config/areasConfigValidator.xsd @@ -3,31 +3,10 @@ - - - - - - - - - - - - - - - - - - - - - - + @@ -97,19 +76,11 @@ + - - - - - - - - - \ No newline at end of file diff --git a/Step.Config/Config/serverConfig.xml b/Step.Config/Config/serverConfig.xml new file mode 100644 index 00000000..18a16bce --- /dev/null +++ b/Step.Config/Config/serverConfig.xml @@ -0,0 +1,15 @@ + + + + DEMO + true + 127.0.0.1 + 8080 + Ares 37 OF + + + 9000 + en + true + + \ No newline at end of file diff --git a/Step.Config/Config/serverConfigValidator.xsd b/Step.Config/Config/serverConfigValidator.xsd new file mode 100644 index 00000000..adecf615 --- /dev/null +++ b/Step.Config/Config/serverConfigValidator.xsd @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Step.Config/ServerConfigController.cs b/Step.Config/ServerConfigController.cs index 496a6fb2..eb796a57 100644 --- a/Step.Config/ServerConfigController.cs +++ b/Step.Config/ServerConfigController.cs @@ -15,17 +15,10 @@ namespace Step.Config { public static void ReadStartupConfig() { - // Read validation file - XmlSchemaSet readerSettings = new XmlSchemaSet(); - try { - // Add Schema - readerSettings.Add(null, BASE_PATH + "\\" + STARTUP_CONFIG_SCHEMA_PATH); - // Open file reader - XDocument xmlConfigFile = XDocument.Load(BASE_PATH + "\\" + STARTUP_CONFIG_PATH); - // Validate file - xmlConfigFile.Validate(readerSettings, ValidationHandler); + // Get server file handler + XDocument xmlConfigFile = GetXmlHandlerWithValidator(SERVER_CONFIG_SCHEMA_PATH, SERVER_CONFIG_PATH); // Read nc Config with LINQ NcConfig = xmlConfigFile @@ -40,7 +33,7 @@ namespace Step.Config }).FirstOrDefault(); // Read server config with LINQ and save into static config - ServerConfig.ServerStartupConfig = xmlConfigFile + ServerStartupConfig = xmlConfigFile .Descendants(SERVER_CONFIG_KEY) .Select(x => new ServerConfigModel() { // Set server config model data @@ -49,6 +42,9 @@ namespace Step.Config EnableDirectoryBrowsing = Convert.ToBoolean(x.Element("enableDirectoryBrowsing").Value) }).FirstOrDefault(); + // Get Areas file handler + xmlConfigFile = GetXmlHandlerWithValidator(AREAS_CONFIG_SCHEMA_PATH, AREAS_CONFIG_PATH); + // Read areas config with LINQ xmlConfigFile .Descendants(AREAS_CONFIG_KEY) // Get areas config node @@ -63,6 +59,20 @@ namespace Step.Config } } + private static XDocument GetXmlHandlerWithValidator(string configSchemaFilePath, string configFilePath) + { + // Create new instance + XmlSchemaSet readerSettings = new XmlSchemaSet(); + // Add Schema + readerSettings.Add(null, BASE_PATH + "\\" + configSchemaFilePath ); + + // Open file reader + XDocument xmlConfigFile = XDocument.Load(BASE_PATH + "\\" + configFilePath); + // Validate file + xmlConfigFile.Validate(readerSettings, ValidationHandler); + + return xmlConfigFile; + } private static void SetAreaValueByName(XElement element) { diff --git a/Step.Config/Step.Config.csproj b/Step.Config/Step.Config.csproj index 7ccc228e..7ccb48ae 100644 --- a/Step.Config/Step.Config.csproj +++ b/Step.Config/Step.Config.csproj @@ -47,7 +47,10 @@ - + + PreserveNewest + + Always Designer @@ -63,10 +66,16 @@ - + PreserveNewest Designer + + + Designer + Always + + \ No newline at end of file diff --git a/Step.Database/Controllers/FunctionsAccessController.cs b/Step.Database/Controllers/FunctionsAccessController.cs index c0f08dbd..e6de19a8 100644 --- a/Step.Database/Controllers/FunctionsAccessController.cs +++ b/Step.Database/Controllers/FunctionsAccessController.cs @@ -1,8 +1,8 @@ -using System; +using Step.Model.DatabaseModels; +using Step.Model.DTOModels; +using System; using System.Collections.Generic; using System.Linq; -using Step.Model.DatabaseModels; -using Step.Model.DTOModels; using static CMS_CORE_Library.DataStructures; namespace Step.Database.Controllers @@ -47,12 +47,12 @@ namespace Step.Database.Controllers .ToList(); } - public List GetFunctionsMappedWithPlc(List functionalityList) + public List GetFunctionsMappedWithPlc(List functionalityList) { return dbCtx .FunctionsAccess .ToList() // Find all function access - .Select(f => new DTORuntimeFunctionAccessModel() + .Select(f => new DTORuntimeFunctionalityModel() { Id = f.FunctionAccessId, Name = f.Name, @@ -71,4 +71,4 @@ namespace Step.Database.Controllers return functionalityList[id - 1].IsActive; } } -} +} \ No newline at end of file diff --git a/Step.Database/Controllers/MachinesController.cs b/Step.Database/Controllers/MachinesController.cs index bb98bd01..aeea468d 100644 --- a/Step.Database/Controllers/MachinesController.cs +++ b/Step.Database/Controllers/MachinesController.cs @@ -39,14 +39,16 @@ namespace Step.Database.Controllers public MachineModel Create(string uniqueId) { + // Create database machine model MachineModel machine = new MachineModel() { MachineId = 1, Model = NcConfig.NcName, UniqueId = uniqueId }; - + // Add to database dbCtx.Machines.Add(machine); + // Commit changes dbCtx.SaveChanges(); return machine; @@ -54,12 +56,14 @@ namespace Step.Database.Controllers public void UpdateMachineName(int id, string name) { + // Find machine by id MachineModel machine = FindById(id); - if(machine != null) + if (machine != null) { + // Update machine name machine.Model = name; dbCtx.SaveChanges(); } } } -} +} \ No newline at end of file diff --git a/Step.Database/Controllers/MachinesUsersController.cs b/Step.Database/Controllers/MachinesUsersController.cs index 85c54043..906f7df6 100644 --- a/Step.Database/Controllers/MachinesUsersController.cs +++ b/Step.Database/Controllers/MachinesUsersController.cs @@ -1,10 +1,7 @@ using Step.Model.DatabaseModels; using Step.Model.DTOModels; using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Step.Database.Controllers { @@ -37,20 +34,26 @@ namespace Step.Database.Controllers { return dbCtx .MachinesUsers - .Include("Role") + .Include("Role") // Join with Role, Machine, User .Include("Machine") .Include("User") .Where(x => x.MachineUserId == id) .FirstOrDefault(); - } public MachineUserModel Create(int machineId, int userId, int roleId) { - MachineUserModel machine = new MachineUserModel() { MachineId = machineId, UserId = userId, RoleId = roleId }; + // Create database model + MachineUserModel machine = new MachineUserModel() { + MachineId = machineId, + UserId = userId, + RoleId = roleId + }; + // Add into database dbCtx.MachinesUsers.Add( machine ); + // Commit changes dbCtx.SaveChanges(); return machine; @@ -61,7 +64,7 @@ namespace Step.Database.Controllers RoleModel role = dbCtx .MachinesUsers .Include("Role") - .Where(x => x.MachineId == machineId && x.UserId == userId) + .Where(x => x.MachineId == machineId && x.UserId == userId) // Find by machine id and user id, joining with role .FirstOrDefault().Role; return new DTORoleModel() @@ -71,4 +74,4 @@ namespace Step.Database.Controllers }; } } -} +} \ No newline at end of file diff --git a/Step.Database/Controllers/SessionsController.cs b/Step.Database/Controllers/SessionsController.cs index 1adfd1d3..fb3e2577 100644 --- a/Step.Database/Controllers/SessionsController.cs +++ b/Step.Database/Controllers/SessionsController.cs @@ -1,9 +1,6 @@ using Step.Model.DatabaseModels; using System; -using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace Step.Database.Controllers { @@ -38,7 +35,7 @@ namespace Step.Database.Controllers .RemoveRange( // Delete rows dbCtx .Sessions - .Where(x => x.MachineUserId == machineUserId) // Find all the session with matching machineUserId + .Where(x => x.MachineUserId == machineUserId) // Find all the session with matching machineUserId ); // Commit changes dbCtx.SaveChanges(); @@ -70,4 +67,4 @@ namespace Step.Database.Controllers dbCtx.SaveChanges(); } } -} +} \ No newline at end of file diff --git a/Step.Database/Controllers/UsersController.cs b/Step.Database/Controllers/UsersController.cs index d64e9045..67c4b31b 100644 --- a/Step.Database/Controllers/UsersController.cs +++ b/Step.Database/Controllers/UsersController.cs @@ -1,10 +1,9 @@ -using System; -using System.Data.Entity.Migrations; +using Step.Model.DatabaseModels; +using Step.Model.DTOModels; +using System; using System.Globalization; using System.Linq; using System.Web.Helpers; -using Step.Model.DatabaseModels; -using Step.Model.DTOModels; using static Step.Config.ServerConfig; namespace Step.Database.Controllers @@ -48,6 +47,7 @@ namespace Step.Database.Controllers Language = language }; } + public static UserModel CreateUserModel(string username, string password, string firstName, string lastName, CultureInfo language) { return CreateUserModel(0, username, password, firstName, lastName, language); @@ -59,12 +59,13 @@ namespace Step.Database.Controllers UserModel userDatabaseModel = dbCtx.Users.Where(u => u.UserId == userId).FirstOrDefault(); DTORoleModel roleModel = null; + // Find user role through machineUser table using (MachinesUsersController machinesUsersControler = new MachinesUsersController()) { roleModel = machinesUsersControler.GetUserRole(MachineConfig.MachineId, userId); } - return new DTOUserModel() + return new DTOUserModel() // Return DTOUserModel { Id = userDatabaseModel.UserId, Username = userDatabaseModel.Username, @@ -106,9 +107,11 @@ namespace Step.Database.Controllers public void CreateCmsDefaultUserIfNotExists(int machineId) { + // Find if there is a cms standard user UserModel user = FindByUsername("cms"); if (user == null) { + // If not exist add new user user = dbCtx.Users.Add( CreateUserModel("cms", "cms", "cms", "cms", new CultureInfo("en")) ); @@ -116,7 +119,7 @@ namespace Step.Database.Controllers // Commit changes dbCtx.SaveChanges(); } - + // Add user to local machine users if not exists using (MachinesUsersController machinesUsersController = new MachinesUsersController()) { MachineUserModel machineUser = machinesUsersController.FindByUserId(machineId, user.UserId); @@ -130,11 +133,11 @@ namespace Step.Database.Controllers { UserModel user = FindById(userId); - if(user != null) + if (user != null) { user.Language = newLanguage; dbCtx.SaveChanges(); } } } -} +} \ No newline at end of file diff --git a/Step.Model/DTOModels/DTORuntimeFunctionAccessModel.cs b/Step.Model/DTOModels/DTORuntimeFunctionAccessModel.cs index 8f9b7e16..59672af0 100644 --- a/Step.Model/DTOModels/DTORuntimeFunctionAccessModel.cs +++ b/Step.Model/DTOModels/DTORuntimeFunctionAccessModel.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Step.Model.DTOModels { - public class DTORuntimeFunctionAccessModel + public class DTORuntimeFunctionalityModel { public int Id { get; set; } diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index b30b053e..68b9a0ef 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -1,20 +1,18 @@ -using System; -using System.Collections.Generic; -using static Step.Utils.Constants; -using static Step.Config.ServerConfig; -using CMS_CORE; +using CMS_CORE; using CMS_CORE.Demo; using CMS_CORE.Fanuc; -using CMS_CORE.Siemens; using CMS_CORE.Osai; +using CMS_CORE.Siemens; +using Step.Database.Controllers; using Step.Model.DTOModels; +using System; +using System.Collections.Generic; using System.Globalization; -using static Step.Utils.ExceptionManager; +using System.Reflection; using static CMS_CORE.Nc; using static CMS_CORE_Library.DataStructures; -using System.Reflection; -using Step.Database.Controllers; -using Step.Model.DatabaseModels; +using static Step.Config.ServerConfig; +using static Step.Utils.Constants; namespace Step.NC { @@ -42,7 +40,6 @@ namespace Step.NC return null; } - public Nc SetNumericalControl() { // Return new Numerical control instance choosed from the configuration @@ -50,10 +47,13 @@ namespace Step.NC { case NC_VENDOR.DEMO: return new Nc_Demo(NcConfig.NcIpAddress, NcConfig.NcPort); + case NC_VENDOR.FANUC: return new Nc_Fanuc(NcConfig.NcIpAddress, NcConfig.NcPort, 2000); + case NC_VENDOR.SIEMENS: return new Nc_Siemens(2000); + case NC_VENDOR.OSAI: return new Nc_Osai(NcConfig.NcIpAddress, NcConfig.NcPort, 2000); } @@ -124,7 +124,7 @@ namespace Step.NC genericData.PlcVersion = "1.0.0"; // Get PLC version genericData.UnitOfMeasurement = "mm"; - // Get Server version + // Get Server version genericData.ServerVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString(); //Get Library Version genericData.CoreLibraryVersion = "2.0.0"; @@ -160,7 +160,7 @@ namespace Step.NC if (cmsError.errorCode != 0) return cmsError; - // For each process + // For each process for (ushort i = 1; i <= maxProcNumber; i++) { // Get process active alarms @@ -203,14 +203,13 @@ namespace Step.NC { axes = new List(); - // Get NC max process number ushort maxProcNumber = 0; CmsError cmsError = numericalControl.NC_RProcessesNum(ref maxProcNumber); if (cmsError.errorCode != 0) return cmsError; - // For each process + // For each process for (ushort i = 1; i <= maxProcNumber; i++) { cmsError = GetAxesPositionsByProcess(i, out DTOAxesModel axis); @@ -251,21 +250,24 @@ namespace Step.NC public CmsError GetPowerOnData(out DTOPowerOnDataModel resultPowerOnData) { resultPowerOnData = new DTOPowerOnDataModel(); + // Init object PreAndPostPowerOnModel prePostPowerOn = new PreAndPostPowerOnModel { PostPowerOn = new PostPowerOnModel(), PrePowerOn = new PrePowerOnModel() }; + // Read pre and post power on data CmsError cmsError = numericalControl.PLC_RPowerOnData(ref prePostPowerOn); if (cmsError.IsError()) return cmsError; + // Set return object resultPowerOnData.PrePowerOn = prePostPowerOn.PrePowerOn; resultPowerOnData.PostPowerOn = prePostPowerOn.PostPowerOn; - // Read axes procedure data from + // Read axes procedure data from cmsError = numericalControl.PLC_RAxesResetData(ref resultPowerOnData.AxisReset); return cmsError; @@ -314,10 +316,10 @@ namespace Step.NC return cmsError; } - public CmsError GetFunctionsMappedWithNC(out List functionsAccessList) + public CmsError GetFunctionsMappedWithNC(out List functionsAccessList) { - functionsAccessList = new List(); - // Read plc functionality + functionsAccessList = new List(); + // Read plc functionality List functionalityList = null; CmsError cmsError = numericalControl.PLC_RFunctionAccess(ref functionalityList); @@ -338,9 +340,10 @@ namespace Step.NC { return new CmsError(0, ""); } + public CmsError RefreshAlarm(string id) { return new CmsError(0, ""); } } -} +} \ No newline at end of file diff --git a/Step.Tasks/ThreadsFunctions.cs b/Step.Tasks/ThreadsFunctions.cs index 6c400ee1..4cad1f8d 100644 --- a/Step.Tasks/ThreadsFunctions.cs +++ b/Step.Tasks/ThreadsFunctions.cs @@ -1,14 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Threading; +using Step.Core; using Step.Model.DTOModels; -using TeamDev.SDK.MVVM; using Step.NC; -using Step.Core; +using System.Collections.Generic; +using System.Diagnostics; +using System.Threading; +using TeamDev.SDK.MVVM; +using static CMS_CORE_Library.DataStructures; using static Step.Utils.Constants; using static Step.Utils.ExceptionManager; -using System.Diagnostics; -using static CMS_CORE_Library.DataStructures; public static class ThreadsFunctions { @@ -23,6 +22,7 @@ public static class ThreadsFunctions private static Thread ConnThread; #region Nc Threads + public static void ReadAlarms() { NcHandler ncHandler = new NcHandler(); @@ -34,7 +34,6 @@ public static class ThreadsFunctions if (libraryError.errorCode != 0) ManageLibraryError(libraryError); - while (true) { sw.Restart(); @@ -109,7 +108,6 @@ public static class ThreadsFunctions } } - public static void ReadAxes() { NcHandler ncHandler = new NcHandler(); @@ -239,8 +237,7 @@ public static class ThreadsFunctions } } - - public static void ReadRuntimeFunctionAccess() + public static void ReadEnabledFunctionality() { NcHandler ncHandler = new NcHandler(); Stopwatch sw = new Stopwatch(); @@ -259,7 +256,7 @@ public static class ThreadsFunctions if (ncHandler.numericalControl.NC_IsConnected()) { // Get Data from NC - libraryError = ncHandler.GetFunctionsMappedWithNC(out List functionsAccessList); + libraryError = ncHandler.GetFunctionsMappedWithNC(out List functionsAccessList); if (libraryError.errorCode != 0) ManageLibraryError(libraryError); else @@ -284,7 +281,7 @@ public static class ThreadsFunctions } } - #endregion + #endregion Nc Threads #region SupportFunctions @@ -344,26 +341,36 @@ public static class ThreadsFunctions case CMS_ERROR_CODES.NC_PROD_ERROR: Manage(ERROR_LEVEL.WARNING, cmsError.message); break; + case CMS_ERROR_CODES.NOT_CONNECTED: TryNcConnection(); // If not connected try reconnection break; + case CMS_ERROR_CODES.PROC_NOT_FOUND: break; + case CMS_ERROR_CODES.FUNCTION_NOT_ALLOWED: break; + case CMS_ERROR_CODES.BIT_NOT_IN_RANGE: break; + case CMS_ERROR_CODES.BYTE_NOT_IN_RANGE: break; + case CMS_ERROR_CODES.INTERNAL_ERROR: break; + case CMS_ERROR_CODES.INCORRECT_PARAMETERS: break; + case CMS_ERROR_CODES.NC_LANGUAGE_ERROR: break; + case CMS_ERROR_CODES.SIEMENS_ENVIRONMENT_NOT_FOUND: Manage(ERROR_LEVEL.FATAL, cmsError.message); break; + case CMS_ERROR_CODES.SIEMENS_HMI_NOT_RUNNING: Manage(ERROR_LEVEL.WARNING, cmsError.message); TryNcConnection(); // If not connected try reconnection @@ -371,7 +378,6 @@ public static class ThreadsFunctions } } - internal static void StatThread() { while (true) @@ -423,7 +429,6 @@ public static class ThreadsFunctions } } - private static void StatReset() { ReadAlarmsTimer = 0; @@ -433,5 +438,6 @@ public static class ThreadsFunctions ReadAxesTimer = 0; ReadAxesTimes = 0; } - #endregion -} + + #endregion SupportFunctions +} \ No newline at end of file diff --git a/Step.Tasks/ThreadsHandler.cs b/Step.Tasks/ThreadsHandler.cs index f1891d2b..34990992 100644 --- a/Step.Tasks/ThreadsHandler.cs +++ b/Step.Tasks/ThreadsHandler.cs @@ -27,7 +27,7 @@ namespace Step.Core ThreadsFunctions.ReadPowerOnData, ThreadsFunctions.StatThread, ThreadsFunctions.ReadProcessesPPStatus, - ThreadsFunctions.ReadRuntimeFunctionAccess + ThreadsFunctions.ReadEnabledFunctionality }; private volatile static List RunningThreadsList = new List(); internal volatile static Dictionary RunningThreadStatus = new Dictionary(); diff --git a/Step.Utils/Constants.cs b/Step.Utils/Constants.cs index 08387dc6..47260dbf 100644 --- a/Step.Utils/Constants.cs +++ b/Step.Utils/Constants.cs @@ -56,8 +56,13 @@ namespace Step.Utils // Filenames public static readonly string BASE_PATH = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); - public const string STARTUP_CONFIG_SCHEMA_PATH = "serverConfigValidator.xsd"; - public const string STARTUP_CONFIG_PATH = "serverConfig.xml"; + public const string CONFIG_DIRECTORY = "Config\\"; + public const string SERVER_CONFIG_SCHEMA_PATH = CONFIG_DIRECTORY + "serverConfigValidator.xsd"; + public const string SERVER_CONFIG_PATH = CONFIG_DIRECTORY + "serverConfig.xml"; + + public const string AREAS_CONFIG_SCHEMA_PATH = CONFIG_DIRECTORY + "areasConfigValidator.xsd"; + public const string AREAS_CONFIG_PATH = CONFIG_DIRECTORY + "areasConfig.xml"; + public static string WEBSITE_DIRECTORY = Path.Combine(BASE_PATH, "..", "wwwroot"); public static string LANGUAGE_PACK_DIRECTORY = BASE_PATH + "\\languages\\"; public static string LANGUAGE_SCHEMA_PATH = BASE_PATH + "\\LanguageValidator.xsd"; diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs index d3c71acb..222ad929 100644 --- a/Step/Listeners/ListenersHandler.cs +++ b/Step/Listeners/ListenersHandler.cs @@ -1,7 +1,7 @@ -using System.Collections.Generic; -using Step.Listeners.Database; +using Step.Listeners.Database; using Step.Listeners.SignalR; using Step.Model.DTOModels; +using System.Collections.Generic; using TeamDev.SDK.MVVM; using static Step.Utils.Constants; @@ -64,4 +64,4 @@ namespace Step.Listeners MessageServices.Current.UnSubscribe(infos.ToArray()); } } -} +} \ No newline at end of file