diff --git a/Libs/CMS_CORE_Library.dll b/Libs/CMS_CORE_Library.dll index e1ad7996..4f9a670a 100644 Binary files a/Libs/CMS_CORE_Library.dll and b/Libs/CMS_CORE_Library.dll differ diff --git a/Step.Database/Controllers/NcToolManagerController.cs b/Step.Database/Controllers/NcToolManagerController.cs index 818a2809..bd55d479 100644 --- a/Step.Database/Controllers/NcToolManagerController.cs +++ b/Step.Database/Controllers/NcToolManagerController.cs @@ -173,7 +173,7 @@ namespace Step.Database.Controllers return dtoShanks; } - public List FindMagazinePositions() + public List FindMagazinesPositions() { List positions = dbCtx .MagazinePositions @@ -264,8 +264,10 @@ namespace Step.Database.Controllers { DbNcToolModel tool = FindTool(toolId); + var shankId = tool.ShankId; // Update db model SupportFunctions.CopyProperties(dtoTool, tool); + tool.ShankId = shankId; // Save dbCtx.SaveChanges(); @@ -346,10 +348,12 @@ namespace Step.Database.Controllers return dbShank; } - public void DeleteShank(int shankId) + public DbNcShankModel DeleteShank(int shankId) { DbNcShankModel shank = FindShankWithTools(shankId); DeleteShank(shank); + + return shank; } public void DeleteShank(DbNcShankModel shank) @@ -361,6 +365,7 @@ namespace Step.Database.Controllers public DbNcMagazinePositionModel UpdatePosition(DbNcMagazinePositionModel dbPos, DTONcMagazinePositionModel dtoPos) { + dbCtx.MagazinePositions.Attach(dbPos); dbPos.Type = dtoPos.Type; dbPos.Disabled = dtoPos.Disabled; diff --git a/Step.Database/DatabaseContext.cs b/Step.Database/DatabaseContext.cs index 0cbc2950..25186446 100644 --- a/Step.Database/DatabaseContext.cs +++ b/Step.Database/DatabaseContext.cs @@ -82,25 +82,19 @@ namespace Step.Database AllFunctionalityDisabled = functionsAccess.FindAllFunctionsAndDisableAll(); } } - catch (MySql.Data.MySqlClient.MySqlException ex) - { - if (ex.Number == 0) - { - //dbContext.Database.Initialize(true); - } - else if (ex.Number == 1042) // Can't find MySQLServer - { - Manage(ERROR_LEVEL.FATAL, ex); - } - else - { - Manage(ERROR_LEVEL.ERROR, ex); - } - } catch (Exception ex) { Manage(ERROR_LEVEL.FATAL, ex); } + + + //catch (MySql.Data.MySqlClient.MySqlException ex) + //{ + // if (ex.Number == 1042) // Can't find MySQLServer + // Manage(ERROR_LEVEL.FATAL, ex); + // else + // Manage(ERROR_LEVEL.ERROR, ex); + //} } public static void FindOrCreateMachineUniqueId() diff --git a/Step.Model/Constants.cs b/Step.Model/Constants.cs index 2add83ef..da1d3014 100644 --- a/Step.Model/Constants.cs +++ b/Step.Model/Constants.cs @@ -139,6 +139,7 @@ namespace Step.Model public const string SEND_NC_STATUS = "NC_STATUS"; public const string SEND_THREADS_STATUS = "THREAD_STATUS"; public const string SHOW_MSG_UI = "SHOW_MSG_UI"; + public const string SEND_ERROR_TO_UI = "SEND_ERROR_TO_UI"; // MVVM Messages to signalR tasks public const string SEND_ALARMS = "SEND_ALARMS"; diff --git a/Step.Model/DTOModels/DTOHeadModel.cs b/Step.Model/DTOModels/DTOHeadModel.cs index 0957ee60..84f9a8d2 100644 --- a/Step.Model/DTOModels/DTOHeadModel.cs +++ b/Step.Model/DTOModels/DTOHeadModel.cs @@ -40,6 +40,11 @@ return true; } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } public class DTOSpindleModel : DTOHeadModel @@ -69,6 +74,11 @@ // Call Parent equals return base.Equals(item); } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } public class DTOAbrasiveWaterJet : DTOHeadModel @@ -98,6 +108,11 @@ // Call Parent equals return base.Equals(item); } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } public class DTOWaterJet : DTOHeadModel @@ -119,5 +134,10 @@ // Call Parent equals return base.Equals(item); } + + public override int GetHashCode() + { + return base.GetHashCode(); + } } } \ No newline at end of file diff --git a/Step.Model/DTOModels/ToolModels/DTONcFamilyModel.cs b/Step.Model/DTOModels/ToolModels/DTONcFamilyModel.cs index 655882ed..787e9b11 100644 --- a/Step.Model/DTOModels/ToolModels/DTONcFamilyModel.cs +++ b/Step.Model/DTOModels/ToolModels/DTONcFamilyModel.cs @@ -82,7 +82,9 @@ namespace Step.Model.DTOModels.ToolModels public static explicit operator DTONewNcFamilyModel(DbNcFamilyModel obj) { // Get bit values - var coolingByte = new BitArray(obj.CoolingByte); + BitArray coolingByte = new BitArray(obj.CoolingByte); + bool[] bits = new bool[8]; + coolingByte.CopyTo(bits, 0); return new DTONcFamilyModel() { @@ -94,14 +96,14 @@ namespace Step.Model.DTOModels.ToolModels TcpTable = obj.TcpTable, Gamma = obj.Gamma, RotationType = obj.RotationType, - Cooling = coolingByte[0], - Cooling1 = coolingByte[1], - Cooling2 = coolingByte[2], - Cooling3 = coolingByte[3], - Cooling4 = coolingByte[4], - Cooling5 = coolingByte[5], - Cooling6 = coolingByte[6], - Cooling7 = coolingByte[7], + Cooling = bits[0], + Cooling1 = bits[1], + Cooling2 = bits[2], + Cooling3 = bits[3], + Cooling4 = bits[4], + Cooling5 = bits[5], + Cooling6 = bits[6], + Cooling7 = bits[7], MaxSpeed = obj.MaxSpeed, MaxLoad = obj.MaxLoad, MinLoadDynamicCompensation = obj.MinLoadDynamicCompensation, @@ -165,7 +167,9 @@ namespace Step.Model.DTOModels.ToolModels } // Get bit values - var coolingByte = new BitArray(obj.CoolingByte); + BitArray coolingByte = new BitArray(obj.CoolingByte); + bool[] bits = new bool[8]; + coolingByte.CopyTo(bits, 0); return new DTONcFamilyModel() { @@ -177,14 +181,14 @@ namespace Step.Model.DTOModels.ToolModels TcpTable = obj.TcpTable, Gamma = obj.Gamma, RotationType = obj.RotationType, - Cooling = coolingByte[0], - Cooling1 = coolingByte[1], - Cooling2 = coolingByte[2], - Cooling3 = coolingByte[3], - Cooling4 = coolingByte[4], - Cooling5 = coolingByte[5], - Cooling6 = coolingByte[6], - Cooling7 = coolingByte[7], + Cooling = bits[0], + Cooling1 = bits[1], + Cooling2 = bits[2], + Cooling3 = bits[3], + Cooling4 = bits[4], + Cooling5 = bits[5], + Cooling6 = bits[6], + Cooling7 = bits[7], MaxSpeed = obj.MaxSpeed, MaxLoad = obj.MaxLoad, MinLoadDynamicCompensation = obj.MinLoadDynamicCompensation, diff --git a/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs b/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs index c9183093..0f0de267 100644 --- a/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs +++ b/Step.Model/DTOModels/ToolModels/DTONcToolModel.cs @@ -41,7 +41,9 @@ namespace Step.Model.DTOModels.ToolModels public static explicit operator DTONcTool(DbNcToolModel obj) { // Get bit values - var statusBit = new BitArray(obj.Status); + var statusBits = new BitArray(obj.Status); + bool[] bits = new bool[8]; + statusBits.CopyTo(bits, 0); return new DTONcTool() { @@ -50,11 +52,11 @@ namespace Step.Model.DTOModels.ToolModels OffsetLength = obj.OffsetLength, ResidualLife = obj.ResidualLife, ResidualRevive = obj.ResidualRevive, - Disabled = statusBit[0], - Broken = statusBit[1], - Measured = statusBit[2], - ClockwiseRotation = statusBit[3], - CounterClockwiseRotation = statusBit[4], + Disabled = bits[0], + Broken = bits[1], + Measured = bits[2], + ClockwiseRotation = bits[3], + CounterClockwiseRotation = bits[4], }; } @@ -92,7 +94,9 @@ namespace Step.Model.DTOModels.ToolModels public static explicit operator DTONcToolModel(DbNcToolModel obj) { // Get bit values - var statusBit = new BitArray(obj.Status); + var statusBits = new BitArray(obj.Status); + bool[] bits = new bool[8]; + statusBits.CopyTo(bits, 0); return new DTONcToolModel() { @@ -102,11 +106,11 @@ namespace Step.Model.DTOModels.ToolModels OffsetLength = obj.OffsetLength, ResidualLife = obj.ResidualLife, ResidualRevive = obj.ResidualRevive, - Disabled = statusBit[0], - Broken = statusBit[1], - Measured = statusBit[2], - ClockwiseRotation = statusBit[3], - CounterClockwiseRotation = statusBit[4], + Disabled = bits[0], + Broken = bits[1], + Measured = bits[2], + ClockwiseRotation = bits[3], + CounterClockwiseRotation = bits[4], }; } @@ -144,7 +148,9 @@ namespace Step.Model.DTOModels.ToolModels public static explicit operator DTONewNcToolModel(DbNcToolModel obj) { // Get bit values - var statusBit = new BitArray(obj.Status); + var statusBits = new BitArray(obj.Status); + bool[] bits = new bool[8]; + statusBits.CopyTo(bits, 0); return new DTONewNcToolModel() { @@ -153,11 +159,11 @@ namespace Step.Model.DTOModels.ToolModels OffsetLength = obj.OffsetLength, ResidualLife = obj.ResidualLife, ResidualRevive = obj.ResidualRevive, - Disabled = statusBit[0], - Broken = statusBit[1], - Measured = statusBit[2], - ClockwiseRotation = statusBit[3], - CounterClockwiseRotation = statusBit[4], + Disabled = bits[0], + Broken = bits[1], + Measured = bits[2], + ClockwiseRotation = bits[3], + CounterClockwiseRotation = bits[4], OffsetId1 = obj.OffsetId1, OffsetId2 = obj.OffsetId2, OffsetId3 = obj.OffsetId3 diff --git a/Step.Model/DatabaseModels/RoleModel.cs.d.ts b/Step.Model/DatabaseModels/RoleModel.cs.d.ts deleted file mode 100644 index 6c9eab71..00000000 --- a/Step.Model/DatabaseModels/RoleModel.cs.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module server { - interface roleModel { - roleId: number; - name: string; - level: number; - } -} diff --git a/Step.Model/DatabaseModels/UserModel.cs.d.ts b/Step.Model/DatabaseModels/UserModel.cs.d.ts deleted file mode 100644 index 6293daa4..00000000 --- a/Step.Model/DatabaseModels/UserModel.cs.d.ts +++ /dev/null @@ -1,130 +0,0 @@ -declare module server { - interface userModel { - userId: number; - username: string; - firstName: string; - lastName: string; - password: string; - securityStamp: string; - _language: string; - language: { - parent: any; - lCID: number; - keyboardLayoutId: number; - name: string; - ietfLanguageTag: string; - displayName: string; - nativeName: string; - englishName: string; - twoLetterISOLanguageName: string; - threeLetterISOLanguageName: string; - threeLetterWindowsLanguageName: string; - compareInfo: { - name: string; - lCID: number; - version: { - fullVersion: number; - sortId: any; - }; - }; - textInfo: { - aNSICodePage: number; - oEMCodePage: number; - macCodePage: number; - eBCDICCodePage: number; - lCID: number; - cultureName: string; - isReadOnly: boolean; - listSeparator: string; - isRightToLeft: boolean; - }; - isNeutralCulture: boolean; - cultureTypes: any; - numberFormat: { - currencyDecimalDigits: number; - currencyDecimalSeparator: string; - isReadOnly: boolean; - currencyGroupSizes: number[]; - numberGroupSizes: number[]; - percentGroupSizes: number[]; - currencyGroupSeparator: string; - currencySymbol: string; - naNSymbol: string; - currencyNegativePattern: number; - numberNegativePattern: number; - percentPositivePattern: number; - percentNegativePattern: number; - negativeInfinitySymbol: string; - negativeSign: string; - numberDecimalDigits: number; - numberDecimalSeparator: string; - numberGroupSeparator: string; - currencyPositivePattern: number; - positiveInfinitySymbol: string; - positiveSign: string; - percentDecimalDigits: number; - percentDecimalSeparator: string; - percentGroupSeparator: string; - percentSymbol: string; - perMilleSymbol: string; - nativeDigits: string[]; - digitSubstitution: any; - }; - dateTimeFormat: { - aMDesignator: string; - calendar: { - minSupportedDateTime: Date; - maxSupportedDateTime: Date; - algorithmType: any; - isReadOnly: boolean; - eras: number[]; - twoDigitYearMax: number; - }; - dateSeparator: string; - firstDayOfWeek: any; - calendarWeekRule: any; - fullDateTimePattern: string; - longDatePattern: string; - longTimePattern: string; - monthDayPattern: string; - pMDesignator: string; - rFC1123Pattern: string; - shortDatePattern: string; - shortTimePattern: string; - sortableDateTimePattern: string; - timeSeparator: string; - universalSortableDateTimePattern: string; - yearMonthPattern: string; - abbreviatedDayNames: string[]; - shortestDayNames: string[]; - dayNames: string[]; - abbreviatedMonthNames: string[]; - monthNames: string[]; - isReadOnly: boolean; - nativeCalendarName: string; - abbreviatedMonthGenitiveNames: string[]; - monthGenitiveNames: string[]; - }; - calendar: { - minSupportedDateTime: Date; - maxSupportedDateTime: Date; - algorithmType: any; - isReadOnly: boolean; - eras: number[]; - twoDigitYearMax: number; - }; - optionalCalendars: { - minSupportedDateTime: Date; - maxSupportedDateTime: Date; - algorithmType: any; - isReadOnly: boolean; - eras: number[]; - twoDigitYearMax: number; - }[]; - useUserOverride: boolean; - isReadOnly: boolean; - }; - roleId: number; - role: server.RoleModel; - } -} diff --git a/Step.Model/Step.Model.csproj b/Step.Model/Step.Model.csproj index e18c4fdb..e3a2421f 100644 --- a/Step.Model/Step.Model.csproj +++ b/Step.Model/Step.Model.csproj @@ -130,16 +130,6 @@ - - True - True - RoleModel.cs - - - True - True - UserModel.cs - True True diff --git a/Step.NC/NcHandler.cs b/Step.NC/NcHandler.cs index c6c3b8a8..f09dcb49 100644 --- a/Step.NC/NcHandler.cs +++ b/Step.NC/NcHandler.cs @@ -1067,7 +1067,7 @@ namespace Step.NC public CmsError UnloadToolInMagazine(int magazineId, int positionId) { - return numericalControl.TOOLS_WUnloadToolInMagazine(magazineId, positionId); + return numericalControl.TOOLS_WUnloadToolFromMagazine(magazineId, positionId); } public CmsError LoadTooolIntoShank(int shankId, int positionId, int toolId) @@ -1102,72 +1102,52 @@ namespace Step.NC public CmsError UpdateTool(int toolId, DTONewNcToolModel newTool, out DTONcToolModel toolWithOffsets) { toolWithOffsets = new DTONcToolModel(); - // Start edit - CmsError cmsError = numericalControl.TOOLS_WStartEditData(); - if (cmsError.IsError()) - return cmsError; using (NcToolManagerController toolsManager = new NcToolManagerController()) { using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) { - // Update Tool + // Update database tool Tool DbNcToolModel dbTool = toolsManager.UpdateTool(toolId, newTool); - - // Populate tool offset - cmsError = GetToolData(dbTool, ref toolWithOffsets); + // Populate updated tool with offset data + CmsError cmsError = GetToolData(dbTool, ref toolWithOffsets); if (cmsError.IsError()) { dbContextTransaction.Rollback(); return cmsError; } + bool startIsActive = false; + + // Check if tool is loaded into a shank if (dbTool.ShankId != null) { - // Check if shank is loaded in magazine + // Check if shank is loaded into magazine DbNcShankModel shank = toolsManager.FindShankWithTools(dbTool.ShankId.Value); if (shank.MagazineId != null) { + startIsActive = true; + // Create backup of data stored on the NC and block file accesses + cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + return cmsError; + } + // Update tool cmsError = UpdateNcTools(toolsManager); - ManageToolManagerError(cmsError, dbContextTransaction); - - return cmsError; } } + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + return NO_ERROR; } } } - public void DeleteNcTool(DbNcToolModel tool) - { - using (NcToolManagerController toolsManager = new NcToolManagerController()) - { - using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) - { - // Delete DB tool - toolsManager.DeleteTool(tool.ToolId); - - if (tool.ShankId != null) - { - // If tool is mounted than update Nc data - DbNcShankModel shank = toolsManager.FindShankWithTools(tool.ShankId.Value); - if (shank.MagazineId != null) - { - // Update Nc data - CmsError cmsError = UpdateNcTools(toolsManager); - ManageToolManagerError(cmsError, dbContextTransaction); - } - } - - dbContextTransaction.Rollback(); - } - } - } - public CmsError UpdateNcTools(NcToolManagerController toolsManager = null) { if (toolsManager == null) @@ -1190,6 +1170,129 @@ namespace Step.NC return numericalControl.TOOLS_WUpdateTools(tools); } + public CmsError DeleteNcTool(DbNcToolModel tool) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + { + // Delete db tool + toolsManager.DeleteTool(tool.ToolId); + + bool startIsActive = false; + CmsError cmsError = NO_ERROR; + + if (tool.ShankId != null) + { + // If tool is mounted than update Nc data + DbNcShankModel shank = toolsManager.FindShankWithTools(tool.ShankId.Value); + if (shank.MagazineId != null) + { + startIsActive = true; + // Create backup of data stored on the NC and block file accesses + cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + return cmsError; + } + + // Update Nc data + cmsError = UpdateNcTools(toolsManager); + } + } + + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + + return cmsError; + } + } + } + + public CmsError UpdateShank(int shankId, DTONewNcShankModel dtoShank, out DTONcShankModel shank) + { + shank = new DTONcShankModel(); + + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + { + bool startIsActive = false; + CmsError cmsError = NO_ERROR; + + // Update db data + shank = (DTONcShankModel)toolsManager.UpdateShank(shankId, dtoShank); + if (shank.MagazineId != null) + { + startIsActive = true; + // Create backup of data stored on the NC and block file accesses + cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + return cmsError; + } + + // Update nc data + cmsError = UpdateNcShank(toolsManager); + } + + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + + return cmsError; + } + } + } + + public CmsError DeleteNcShank(int shankId) + { + using (NcToolManagerController toolsManager = new NcToolManagerController()) + { + using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + { + // Create backup of data stored on the NC and block file accesses + CmsError cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + return cmsError; + + // Delete database shank + DbNcShankModel deletedShank = toolsManager.DeleteShank(shankId); + bool startIsActive = false; + if (deletedShank.MagazineId != null) + { + startIsActive = true; + // Create backup of data stored on the NC and block file accesses + cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + return cmsError; + } + + // Update nc data + cmsError = UpdateNcShank(toolsManager); + } + + ManageErrorAndTransaction(cmsError, dbContextTransaction, startIsActive); + + return cmsError; + } + } + } + + private CmsError UpdateNcShank(NcToolManagerController toolsManager) + { + // Get mounted shanks + List shanks = toolsManager + .FindShanks() + .Where(x => x.MagazineId != null) + .Select(x => (NcShankModel)x) + .ToList(); + + // Update nc data + return numericalControl.TOOLS_WUpdateShanks(shanks); + } + public DTONcFamilyModel AddFamily(DTONewNcFamilyModel family) { using (NcToolManagerController toolsManager = new NcToolManagerController()) @@ -1201,36 +1304,49 @@ namespace Step.NC public CmsError UpdateFamily(int familyId, DTONewNcFamilyModel family, out DTONcFamilyModel newFamily) { newFamily = new DTONcFamilyModel(); - // Start edit - CmsError cmsError = numericalControl.TOOLS_WStartEditData(); - if (cmsError.IsError()) - return cmsError; using (NcToolManagerController toolsManager = new NcToolManagerController()) { - cmsError = StartEditData(); using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) { // Update db family newFamily = (DTONcFamilyModel)toolsManager.UpdateFamily(familyId, family); - // Update nc families + + // Create backup of data stored on the NC and block file accesses + CmsError cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + { + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); + return cmsError; + } + + // Update Nc families cmsError = UpdateNcFamily(toolsManager); - ManageToolManagerError(cmsError, dbContextTransaction); + + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); return cmsError; } } } - public void DeleteNcFamily(DbNcFamilyModel family) + public CmsError DeleteNcFamily(DbNcFamilyModel family) { using (NcToolManagerController toolsManager = new NcToolManagerController()) { using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) { + // Create backup of data stored on the NC and block file accesses + CmsError cmsError = numericalControl.TOOLS_WStartEditData(); + if (cmsError.IsError()) + return cmsError; + toolsManager.DeleteFamily(family); - // Update nc families - CmsError cmsError = UpdateNcFamily(toolsManager); - ManageToolManagerError(cmsError, dbContextTransaction); + // Update Nc families + cmsError = UpdateNcFamily(toolsManager); + + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); + + return cmsError; } } } @@ -1260,130 +1376,61 @@ namespace Step.NC // Update nc families return numericalControl.TOOLS_WUpdateFamilies(families); } - - public DTONcShankModel AddShank(DTONewNcShankModel shank) + + public CmsError UpdateMagazinePosition(DbNcMagazinePositionModel dbPos, DTONcMagazinePositionModel dtoPos, out DTONcMagazinePositionModel magPos) { + magPos = new DTONcMagazinePositionModel(); + using (NcToolManagerController toolsManager = new NcToolManagerController()) { - return (DTONcShankModel)toolsManager.AddShank(shank); - } - } - - public CmsError UpdateShank(int shankId, DTONewNcShankModel dtoShank, out DTONcShankModel shank) - { - shank = new DTONcShankModel(); - // Start edit - CmsError cmsError = numericalControl.TOOLS_WStartEditData(); - if (cmsError.IsError()) - return cmsError; - using (NcToolManagerController toolsManager = new NcToolManagerController()) - { - using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) + using (DbContextTransaction dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) { - // Update db data - shank = (DTONcShankModel)toolsManager.UpdateShank(shankId, dtoShank); - if (shank.MagazineId != null) + // Create backup of data stored on the NC and block file accesses + CmsError cmsError = StartEditData(); + if (cmsError.IsError()) { - // Update nc data - cmsError = UpdateNcShank(toolsManager); - ManageToolManagerError(cmsError, dbContextTransaction); + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); return cmsError; } - return NO_ERROR; - } - } - } - - public void DeleteNcShank(int shankId) - { - using (NcToolManagerController toolsManager = new NcToolManagerController()) - { - using (var dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) - { - // Delete database shank - toolsManager.DeleteShank(shankId); - - // Update nc data - CmsError cmsError = UpdateNcShank(toolsManager); - ManageToolManagerError(cmsError, dbContextTransaction); - } - } - } - - private CmsError UpdateNcShank(NcToolManagerController toolsManager) - { - // Get mounted shanks - List shanks = toolsManager - .FindShanks() - .Where(x => x.MagazineId != null) - .Select(x => (NcShankModel)x) - .ToList(); - - // Update nc data - return numericalControl.TOOLS_WUpdateShanks(shanks); - } - - public CmsError UpdateMagazinePosition(DbNcMagazinePositionModel dbPos, DTONcMagazinePositionModel dtoPos, out DTONcMagazinePositionModel magPos) - { - using (NcToolManagerController toolsManager = new NcToolManagerController()) - { - CmsError cmsError = StartEditData(); - using (DbContextTransaction dbContextTransaction = toolsManager.dbCtx.Database.BeginTransaction()) - { + // Update database data magPos = (DTONcMagazinePositionModel)toolsManager.UpdatePosition(dbPos, dtoPos); - - // Get magazine positions - List positions = toolsManager.FindMagazinePositions() + + // Get magazines positions + List positions = toolsManager.FindMagazinesPositions() .Select(x => (NcMagazinePositionModel)x) .ToList(); - - // Update nc data + // Update Nc data cmsError = numericalControl.TOOLS_WUpdateMagazinePositions(positions); - ManageToolManagerError(cmsError, dbContextTransaction); + + ManageErrorAndTransaction(cmsError, dbContextTransaction, true); return cmsError; } } } - private void ManageToolManagerError(CmsError cmsError, DbContextTransaction dbContextTransaction) + private void ManageErrorAndTransaction(CmsError cmsError, DbContextTransaction dbContextTransaction, bool ncStartIsActive) { + // Check cmsError, manage transaction and if startIsActive = true manage Nc backup created with TOOLS_WStartEditData() if (cmsError.IsError()) { // Close transaction dbContextTransaction.Rollback(); // Restore backup - numericalControl.TOOLS_WRestoreBackup(); + if(ncStartIsActive) + numericalControl.TOOLS_WRestoreBackup(); } else { // Close transaction dbContextTransaction.Commit(); - numericalControl.TOOLS_WStopEditData(); + // Stop editing ncData + if (ncStartIsActive) + numericalControl.TOOLS_WStopEditData(); } } - //public DTONcMagazinePositionModel LoadToolInMagazine(byte magazineId, byte positionId, DbNcShankModel shank) - //{ - // using (NcToolManagerController toolsManager = new NcToolManagerController()) - // { - // // Update shank data - // DTONcMagazinePositionModel magPos = (DTONcMagazinePositionModel)toolsManager.LoadShankInMagazine(magazineId, positionId, shank); - // // Set magazineId - // magPos.ShankId = shank.ShankId; - - // return magPos; - // } - //} - - //public DTONcShankModel UnloadToolInMagazine(byte magazineId, byte positionId, DbNcShankModel shank) - //{ - // using (NcToolManagerController toolsManager = new NcToolManagerController()) - // { - // return toolsManager.UnloadShankInMagazine(magazineId, positionId, shank); - // } - //} public DTONcShankModel LoadIntoShank(DbNcToolModel tool, int shankId) { @@ -1416,7 +1463,7 @@ namespace Step.NC using (NcToolManagerController toolsManager = new NcToolManagerController()) { // Get database configured positions - List dbPositions = toolsManager.FindMagazinePositions(); + List dbPositions = toolsManager.FindMagazinesPositions(); if (dbPositions.Count <= 0) { CmsError cmsError = GetMagazineConfiguration(out List config); @@ -1488,7 +1535,7 @@ namespace Step.NC return cmsError; // Get magazine positions - List positions = toolsManager.FindMagazinePositions() + List positions = toolsManager.FindMagazinesPositions() .Select(x => (NcMagazinePositionModel)x) .ToList(); cmsError = numericalControl.TOOLS_WUpdateMagazinePositions(positions); diff --git a/Step.UI/ServerControlWindow.Designer.cs b/Step.UI/ServerControlWindow.Designer.cs index 933df0c1..7748999d 100644 --- a/Step.UI/ServerControlWindow.Designer.cs +++ b/Step.UI/ServerControlWindow.Designer.cs @@ -37,24 +37,6 @@ namespace Step.UI this.StopServerItem = new System.Windows.Forms.ToolStripMenuItem(); this.openUiButton = new MetroFramework.Controls.MetroButton(); this.metroTabControl1 = new MetroFramework.Controls.MetroTabControl(); - this.NCInfo = new MetroFramework.Controls.MetroTabPage(); - this.CHNcConnected = new MetroFramework.Controls.MetroCheckBox(); - this.TXTTime = new MetroFramework.Controls.MetroTextBox(); - this.TXTLang = new MetroFramework.Controls.MetroTextBox(); - this.TXTNCProc = new MetroFramework.Controls.MetroTextBox(); - this.TXTSftVers = new MetroFramework.Controls.MetroTextBox(); - this.TXTCMSMach = new MetroFramework.Controls.MetroTextBox(); - this.TXTNcSerial = new MetroFramework.Controls.MetroTextBox(); - this.TXTName = new MetroFramework.Controls.MetroTextBox(); - this.TXTType = new MetroFramework.Controls.MetroTextBox(); - this.metroLabel8 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel7 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel6 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel5 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel4 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel3 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel2 = new MetroFramework.Controls.MetroLabel(); - this.metroLabel1 = new MetroFramework.Controls.MetroLabel(); this.ThreadsInfo = new MetroFramework.Controls.MetroTabPage(); this.LISTThreadStatus = new MetroFramework.Controls.MetroListView(); this.columnHeader1 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); @@ -62,9 +44,11 @@ namespace Step.UI this.stopServerButton = new MetroFramework.Controls.MetroButton(); this.TestJSButton = new MetroFramework.Controls.MetroButton(); this.TXTstatus = new MetroFramework.Controls.MetroTextBox(); + this.TXTType = new System.Windows.Forms.Label(); + this.CHNcConnected = new MetroFramework.Controls.MetroCheckBox(); + this.label1 = new System.Windows.Forms.Label(); this.NotifyIconMenu.SuspendLayout(); this.metroTabControl1.SuspendLayout(); - this.NCInfo.SuspendLayout(); this.ThreadsInfo.SuspendLayout(); this.SuspendLayout(); // @@ -95,7 +79,7 @@ namespace Step.UI // openUiButton // this.openUiButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.openUiButton.Location = new System.Drawing.Point(12, 381); + this.openUiButton.Location = new System.Drawing.Point(8, 371); this.openUiButton.Name = "openUiButton"; this.openUiButton.Size = new System.Drawing.Size(104, 42); this.openUiButton.TabIndex = 1; @@ -106,385 +90,14 @@ namespace Step.UI // // metroTabControl1 // - this.metroTabControl1.Controls.Add(this.NCInfo); this.metroTabControl1.Controls.Add(this.ThreadsInfo); - this.metroTabControl1.Location = new System.Drawing.Point(12, 56); + this.metroTabControl1.Location = new System.Drawing.Point(8, 26); this.metroTabControl1.Name = "metroTabControl1"; this.metroTabControl1.SelectedIndex = 0; this.metroTabControl1.Size = new System.Drawing.Size(328, 323); this.metroTabControl1.TabIndex = 7; this.metroTabControl1.UseSelectable = true; // - // NCInfo - // - this.NCInfo.Controls.Add(this.CHNcConnected); - this.NCInfo.Controls.Add(this.TXTTime); - this.NCInfo.Controls.Add(this.TXTLang); - this.NCInfo.Controls.Add(this.TXTNCProc); - this.NCInfo.Controls.Add(this.TXTSftVers); - this.NCInfo.Controls.Add(this.TXTCMSMach); - this.NCInfo.Controls.Add(this.TXTNcSerial); - this.NCInfo.Controls.Add(this.TXTName); - this.NCInfo.Controls.Add(this.TXTType); - this.NCInfo.Controls.Add(this.metroLabel8); - this.NCInfo.Controls.Add(this.metroLabel7); - this.NCInfo.Controls.Add(this.metroLabel6); - this.NCInfo.Controls.Add(this.metroLabel5); - this.NCInfo.Controls.Add(this.metroLabel4); - this.NCInfo.Controls.Add(this.metroLabel3); - this.NCInfo.Controls.Add(this.metroLabel2); - this.NCInfo.Controls.Add(this.metroLabel1); - this.NCInfo.HorizontalScrollbarBarColor = true; - this.NCInfo.HorizontalScrollbarHighlightOnWheel = false; - this.NCInfo.HorizontalScrollbarSize = 10; - this.NCInfo.Location = new System.Drawing.Point(4, 38); - this.NCInfo.Name = "NCInfo"; - this.NCInfo.Size = new System.Drawing.Size(320, 281); - this.NCInfo.TabIndex = 0; - this.NCInfo.Text = "NC Info"; - this.NCInfo.VerticalScrollbarBarColor = true; - this.NCInfo.VerticalScrollbarHighlightOnWheel = false; - this.NCInfo.VerticalScrollbarSize = 10; - // - // CHNcConnected - // - this.CHNcConnected.AutoCheck = false; - this.CHNcConnected.AutoSize = true; - this.CHNcConnected.Location = new System.Drawing.Point(173, 17); - this.CHNcConnected.Name = "CHNcConnected"; - this.CHNcConnected.Size = new System.Drawing.Size(81, 15); - this.CHNcConnected.TabIndex = 50; - this.CHNcConnected.Text = "Connected"; - this.CHNcConnected.UseSelectable = true; - // - // TXTTime - // - // - // - // - this.TXTTime.CustomButton.Image = null; - this.TXTTime.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTTime.CustomButton.Name = ""; - this.TXTTime.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTTime.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTTime.CustomButton.TabIndex = 1; - this.TXTTime.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTTime.CustomButton.UseSelectable = true; - this.TXTTime.CustomButton.Visible = false; - this.TXTTime.Lines = new string[0]; - this.TXTTime.Location = new System.Drawing.Point(173, 241); - this.TXTTime.MaxLength = 32767; - this.TXTTime.Name = "TXTTime"; - this.TXTTime.PasswordChar = '\0'; - this.TXTTime.ReadOnly = true; - this.TXTTime.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTTime.SelectedText = ""; - this.TXTTime.SelectionLength = 0; - this.TXTTime.SelectionStart = 0; - this.TXTTime.ShortcutsEnabled = true; - this.TXTTime.Size = new System.Drawing.Size(138, 23); - this.TXTTime.TabIndex = 49; - this.TXTTime.UseSelectable = true; - this.TXTTime.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTTime.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTLang - // - // - // - // - this.TXTLang.CustomButton.Image = null; - this.TXTLang.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTLang.CustomButton.Name = ""; - this.TXTLang.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTLang.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTLang.CustomButton.TabIndex = 1; - this.TXTLang.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTLang.CustomButton.UseSelectable = true; - this.TXTLang.CustomButton.Visible = false; - this.TXTLang.Lines = new string[0]; - this.TXTLang.Location = new System.Drawing.Point(173, 212); - this.TXTLang.MaxLength = 32767; - this.TXTLang.Name = "TXTLang"; - this.TXTLang.PasswordChar = '\0'; - this.TXTLang.ReadOnly = true; - this.TXTLang.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTLang.SelectedText = ""; - this.TXTLang.SelectionLength = 0; - this.TXTLang.SelectionStart = 0; - this.TXTLang.ShortcutsEnabled = true; - this.TXTLang.Size = new System.Drawing.Size(138, 23); - this.TXTLang.TabIndex = 48; - this.TXTLang.UseSelectable = true; - this.TXTLang.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTLang.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTNCProc - // - // - // - // - this.TXTNCProc.CustomButton.Image = null; - this.TXTNCProc.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTNCProc.CustomButton.Name = ""; - this.TXTNCProc.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTNCProc.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTNCProc.CustomButton.TabIndex = 1; - this.TXTNCProc.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTNCProc.CustomButton.UseSelectable = true; - this.TXTNCProc.CustomButton.Visible = false; - this.TXTNCProc.Lines = new string[0]; - this.TXTNCProc.Location = new System.Drawing.Point(173, 183); - this.TXTNCProc.MaxLength = 32767; - this.TXTNCProc.Name = "TXTNCProc"; - this.TXTNCProc.PasswordChar = '\0'; - this.TXTNCProc.ReadOnly = true; - this.TXTNCProc.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTNCProc.SelectedText = ""; - this.TXTNCProc.SelectionLength = 0; - this.TXTNCProc.SelectionStart = 0; - this.TXTNCProc.ShortcutsEnabled = true; - this.TXTNCProc.Size = new System.Drawing.Size(138, 23); - this.TXTNCProc.TabIndex = 47; - this.TXTNCProc.UseSelectable = true; - this.TXTNCProc.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTNCProc.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTSftVers - // - // - // - // - this.TXTSftVers.CustomButton.Image = null; - this.TXTSftVers.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTSftVers.CustomButton.Name = ""; - this.TXTSftVers.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTSftVers.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTSftVers.CustomButton.TabIndex = 1; - this.TXTSftVers.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTSftVers.CustomButton.UseSelectable = true; - this.TXTSftVers.CustomButton.Visible = false; - this.TXTSftVers.Lines = new string[0]; - this.TXTSftVers.Location = new System.Drawing.Point(173, 154); - this.TXTSftVers.MaxLength = 32767; - this.TXTSftVers.Name = "TXTSftVers"; - this.TXTSftVers.PasswordChar = '\0'; - this.TXTSftVers.ReadOnly = true; - this.TXTSftVers.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTSftVers.SelectedText = ""; - this.TXTSftVers.SelectionLength = 0; - this.TXTSftVers.SelectionStart = 0; - this.TXTSftVers.ShortcutsEnabled = true; - this.TXTSftVers.Size = new System.Drawing.Size(138, 23); - this.TXTSftVers.TabIndex = 46; - this.TXTSftVers.UseSelectable = true; - this.TXTSftVers.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTSftVers.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTCMSMach - // - // - // - // - this.TXTCMSMach.CustomButton.Image = null; - this.TXTCMSMach.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTCMSMach.CustomButton.Name = ""; - this.TXTCMSMach.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTCMSMach.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTCMSMach.CustomButton.TabIndex = 1; - this.TXTCMSMach.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTCMSMach.CustomButton.UseSelectable = true; - this.TXTCMSMach.CustomButton.Visible = false; - this.TXTCMSMach.Lines = new string[0]; - this.TXTCMSMach.Location = new System.Drawing.Point(173, 125); - this.TXTCMSMach.MaxLength = 32767; - this.TXTCMSMach.Name = "TXTCMSMach"; - this.TXTCMSMach.PasswordChar = '\0'; - this.TXTCMSMach.ReadOnly = true; - this.TXTCMSMach.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTCMSMach.SelectedText = ""; - this.TXTCMSMach.SelectionLength = 0; - this.TXTCMSMach.SelectionStart = 0; - this.TXTCMSMach.ShortcutsEnabled = true; - this.TXTCMSMach.Size = new System.Drawing.Size(138, 23); - this.TXTCMSMach.TabIndex = 45; - this.TXTCMSMach.UseSelectable = true; - this.TXTCMSMach.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTCMSMach.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTNcSerial - // - // - // - // - this.TXTNcSerial.CustomButton.Image = null; - this.TXTNcSerial.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTNcSerial.CustomButton.Name = ""; - this.TXTNcSerial.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTNcSerial.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTNcSerial.CustomButton.TabIndex = 1; - this.TXTNcSerial.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTNcSerial.CustomButton.UseSelectable = true; - this.TXTNcSerial.CustomButton.Visible = false; - this.TXTNcSerial.Lines = new string[0]; - this.TXTNcSerial.Location = new System.Drawing.Point(173, 96); - this.TXTNcSerial.MaxLength = 32767; - this.TXTNcSerial.Name = "TXTNcSerial"; - this.TXTNcSerial.PasswordChar = '\0'; - this.TXTNcSerial.ReadOnly = true; - this.TXTNcSerial.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTNcSerial.SelectedText = ""; - this.TXTNcSerial.SelectionLength = 0; - this.TXTNcSerial.SelectionStart = 0; - this.TXTNcSerial.ShortcutsEnabled = true; - this.TXTNcSerial.Size = new System.Drawing.Size(138, 23); - this.TXTNcSerial.TabIndex = 44; - this.TXTNcSerial.UseSelectable = true; - this.TXTNcSerial.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTNcSerial.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTName - // - // - // - // - this.TXTName.CustomButton.Image = null; - this.TXTName.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTName.CustomButton.Name = ""; - this.TXTName.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTName.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTName.CustomButton.TabIndex = 1; - this.TXTName.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTName.CustomButton.UseSelectable = true; - this.TXTName.CustomButton.Visible = false; - this.TXTName.Lines = new string[0]; - this.TXTName.Location = new System.Drawing.Point(173, 67); - this.TXTName.MaxLength = 32767; - this.TXTName.Name = "TXTName"; - this.TXTName.PasswordChar = '\0'; - this.TXTName.ReadOnly = true; - this.TXTName.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTName.SelectedText = ""; - this.TXTName.SelectionLength = 0; - this.TXTName.SelectionStart = 0; - this.TXTName.ShortcutsEnabled = true; - this.TXTName.Size = new System.Drawing.Size(138, 23); - this.TXTName.TabIndex = 43; - this.TXTName.UseSelectable = true; - this.TXTName.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTName.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // TXTType - // - // - // - // - this.TXTType.CustomButton.Image = null; - this.TXTType.CustomButton.Location = new System.Drawing.Point(116, 1); - this.TXTType.CustomButton.Name = ""; - this.TXTType.CustomButton.Size = new System.Drawing.Size(21, 21); - this.TXTType.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; - this.TXTType.CustomButton.TabIndex = 1; - this.TXTType.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; - this.TXTType.CustomButton.UseSelectable = true; - this.TXTType.CustomButton.Visible = false; - this.TXTType.Lines = new string[0]; - this.TXTType.Location = new System.Drawing.Point(173, 38); - this.TXTType.MaxLength = 32767; - this.TXTType.Name = "TXTType"; - this.TXTType.PasswordChar = '\0'; - this.TXTType.ReadOnly = true; - this.TXTType.ScrollBars = System.Windows.Forms.ScrollBars.None; - this.TXTType.SelectedText = ""; - this.TXTType.SelectionLength = 0; - this.TXTType.SelectionStart = 0; - this.TXTType.ShortcutsEnabled = true; - this.TXTType.Size = new System.Drawing.Size(138, 23); - this.TXTType.TabIndex = 42; - this.TXTType.UseSelectable = true; - this.TXTType.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); - this.TXTType.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); - // - // metroLabel8 - // - this.metroLabel8.AutoSize = true; - this.metroLabel8.Location = new System.Drawing.Point(103, 245); - this.metroLabel8.Name = "metroLabel8"; - this.metroLabel8.Size = new System.Drawing.Size(64, 19); - this.metroLabel8.TabIndex = 41; - this.metroLabel8.Text = "NC Time:"; - this.metroLabel8.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel7 - // - this.metroLabel7.AutoSize = true; - this.metroLabel7.Location = new System.Drawing.Point(75, 216); - this.metroLabel7.Name = "metroLabel7"; - this.metroLabel7.Size = new System.Drawing.Size(92, 19); - this.metroLabel7.TabIndex = 40; - this.metroLabel7.Text = "NC Language:"; - this.metroLabel7.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel6 - // - this.metroLabel6.AutoSize = true; - this.metroLabel6.Location = new System.Drawing.Point(85, 187); - this.metroLabel6.Name = "metroLabel6"; - this.metroLabel6.Size = new System.Drawing.Size(82, 19); - this.metroLabel6.TabIndex = 39; - this.metroLabel6.Text = "Processes N:"; - this.metroLabel6.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel5 - // - this.metroLabel5.AutoSize = true; - this.metroLabel5.Location = new System.Drawing.Point(34, 158); - this.metroLabel5.Name = "metroLabel5"; - this.metroLabel5.Size = new System.Drawing.Size(133, 19); - this.metroLabel5.TabIndex = 38; - this.metroLabel5.Text = "NC Software Version:"; - this.metroLabel5.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel4 - // - this.metroLabel4.AutoSize = true; - this.metroLabel4.Location = new System.Drawing.Point(62, 129); - this.metroLabel4.Name = "metroLabel4"; - this.metroLabel4.Size = new System.Drawing.Size(105, 19); - this.metroLabel4.TabIndex = 37; - this.metroLabel4.Text = "CMS Machine Id"; - this.metroLabel4.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel3 - // - this.metroLabel3.AutoSize = true; - this.metroLabel3.Location = new System.Drawing.Point(89, 100); - this.metroLabel3.Name = "metroLabel3"; - this.metroLabel3.Size = new System.Drawing.Size(78, 19); - this.metroLabel3.TabIndex = 36; - this.metroLabel3.Text = "Nc Serial N:"; - this.metroLabel3.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel2 - // - this.metroLabel2.AutoSize = true; - this.metroLabel2.Location = new System.Drawing.Point(117, 71); - this.metroLabel2.Name = "metroLabel2"; - this.metroLabel2.Size = new System.Drawing.Size(50, 19); - this.metroLabel2.TabIndex = 35; - this.metroLabel2.Text = "Model:"; - this.metroLabel2.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // - // metroLabel1 - // - this.metroLabel1.AutoSize = true; - this.metroLabel1.Location = new System.Drawing.Point(112, 42); - this.metroLabel1.Name = "metroLabel1"; - this.metroLabel1.Size = new System.Drawing.Size(55, 19); - this.metroLabel1.TabIndex = 34; - this.metroLabel1.Text = "Vendor:"; - this.metroLabel1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; - // // ThreadsInfo // this.ThreadsInfo.Controls.Add(this.LISTThreadStatus); @@ -512,13 +125,13 @@ namespace Step.UI this.LISTThreadStatus.Font = new System.Drawing.Font("Segoe UI", 12F); this.LISTThreadStatus.FullRowSelect = true; this.LISTThreadStatus.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None; - this.LISTThreadStatus.Location = new System.Drawing.Point(0, 3); + this.LISTThreadStatus.Location = new System.Drawing.Point(-4, 0); this.LISTThreadStatus.MultiSelect = false; this.LISTThreadStatus.Name = "LISTThreadStatus"; this.LISTThreadStatus.OwnerDraw = true; this.LISTThreadStatus.Scrollable = false; this.LISTThreadStatus.ShowGroups = false; - this.LISTThreadStatus.Size = new System.Drawing.Size(324, 288); + this.LISTThreadStatus.Size = new System.Drawing.Size(328, 275); this.LISTThreadStatus.TabIndex = 2; this.LISTThreadStatus.UseCompatibleStateImageBehavior = false; this.LISTThreadStatus.UseSelectable = true; @@ -539,7 +152,7 @@ namespace Step.UI // stopServerButton // this.stopServerButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.stopServerButton.Location = new System.Drawing.Point(234, 381); + this.stopServerButton.Location = new System.Drawing.Point(230, 371); this.stopServerButton.Name = "stopServerButton"; this.stopServerButton.Size = new System.Drawing.Size(106, 42); this.stopServerButton.TabIndex = 3; @@ -551,7 +164,7 @@ namespace Step.UI // TestJSButton // this.TestJSButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.TestJSButton.Location = new System.Drawing.Point(122, 381); + this.TestJSButton.Location = new System.Drawing.Point(118, 371); this.TestJSButton.Name = "TestJSButton"; this.TestJSButton.Size = new System.Drawing.Size(106, 42); this.TestJSButton.TabIndex = 2; @@ -568,9 +181,9 @@ namespace Step.UI // // this.TXTstatus.CustomButton.Image = null; - this.TXTstatus.CustomButton.Location = new System.Drawing.Point(334, 1); + this.TXTstatus.CustomButton.Location = new System.Drawing.Point(324, 2); this.TXTstatus.CustomButton.Name = ""; - this.TXTstatus.CustomButton.Size = new System.Drawing.Size(21, 21); + this.TXTstatus.CustomButton.Size = new System.Drawing.Size(25, 25); this.TXTstatus.CustomButton.Style = MetroFramework.MetroColorStyle.Blue; this.TXTstatus.CustomButton.TabIndex = 1; this.TXTstatus.CustomButton.Theme = MetroFramework.MetroThemeStyle.Light; @@ -579,7 +192,7 @@ namespace Step.UI this.TXTstatus.Enabled = false; this.TXTstatus.Lines = new string[] { "..."}; - this.TXTstatus.Location = new System.Drawing.Point(-1, 434); + this.TXTstatus.Location = new System.Drawing.Point(-1, 427); this.TXTstatus.MaxLength = 32767; this.TXTstatus.Name = "TXTstatus"; this.TXTstatus.PasswordChar = '\0'; @@ -589,23 +202,56 @@ namespace Step.UI this.TXTstatus.SelectionLength = 0; this.TXTstatus.SelectionStart = 0; this.TXTstatus.ShortcutsEnabled = true; - this.TXTstatus.Size = new System.Drawing.Size(356, 23); + this.TXTstatus.Size = new System.Drawing.Size(352, 30); this.TXTstatus.TabIndex = 8; this.TXTstatus.Text = "..."; this.TXTstatus.UseSelectable = true; this.TXTstatus.WaterMarkColor = System.Drawing.Color.FromArgb(((int)(((byte)(109)))), ((int)(((byte)(109)))), ((int)(((byte)(109))))); this.TXTstatus.WaterMarkFont = new System.Drawing.Font("Segoe UI", 12F, System.Drawing.FontStyle.Italic, System.Drawing.GraphicsUnit.Pixel); // + // TXTType + // + this.TXTType.AutoSize = true; + this.TXTType.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.TXTType.Location = new System.Drawing.Point(179, 348); + this.TXTType.Name = "TXTType"; + this.TXTType.Size = new System.Drawing.Size(51, 13); + this.TXTType.TabIndex = 53; + this.TXTType.Text = "NcType"; + // + // CHNcConnected + // + this.CHNcConnected.AutoCheck = false; + this.CHNcConnected.ForeColor = System.Drawing.SystemColors.ControlText; + this.CHNcConnected.Location = new System.Drawing.Point(246, 345); + this.CHNcConnected.Name = "CHNcConnected"; + this.CHNcConnected.Size = new System.Drawing.Size(81, 20); + this.CHNcConnected.TabIndex = 52; + this.CHNcConnected.Text = "Connected"; + this.CHNcConnected.UseSelectable = true; + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(134, 348); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(44, 13); + this.label1.TabIndex = 54; + this.label1.Text = "Vendor:"; + // // ServerControlWindow // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(350, 457); + this.Controls.Add(this.label1); + this.Controls.Add(this.TXTType); + this.Controls.Add(this.CHNcConnected); this.Controls.Add(this.TXTstatus); + this.Controls.Add(this.TestJSButton); this.Controls.Add(this.stopServerButton); this.Controls.Add(this.metroTabControl1); this.Controls.Add(this.openUiButton); - this.Controls.Add(this.TestJSButton); this.ForeColor = System.Drawing.SystemColors.ControlText; this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon"))); this.Margin = new System.Windows.Forms.Padding(2); @@ -618,10 +264,9 @@ namespace Step.UI this.Theme = MetroFramework.MetroThemeStyle.Default; this.NotifyIconMenu.ResumeLayout(false); this.metroTabControl1.ResumeLayout(false); - this.NCInfo.ResumeLayout(false); - this.NCInfo.PerformLayout(); this.ThreadsInfo.ResumeLayout(false); this.ResumeLayout(false); + this.PerformLayout(); } @@ -631,24 +276,6 @@ namespace Step.UI private System.Windows.Forms.ToolStripMenuItem StopServerItem; private MetroFramework.Controls.MetroButton openUiButton; private MetroFramework.Controls.MetroTabControl metroTabControl1; - private MetroFramework.Controls.MetroTabPage NCInfo; - private MetroFramework.Controls.MetroCheckBox CHNcConnected; - private MetroFramework.Controls.MetroTextBox TXTTime; - private MetroFramework.Controls.MetroTextBox TXTLang; - private MetroFramework.Controls.MetroTextBox TXTNCProc; - private MetroFramework.Controls.MetroTextBox TXTSftVers; - private MetroFramework.Controls.MetroTextBox TXTCMSMach; - private MetroFramework.Controls.MetroTextBox TXTNcSerial; - private MetroFramework.Controls.MetroTextBox TXTName; - private MetroFramework.Controls.MetroTextBox TXTType; - private MetroFramework.Controls.MetroLabel metroLabel8; - private MetroFramework.Controls.MetroLabel metroLabel7; - private MetroFramework.Controls.MetroLabel metroLabel6; - private MetroFramework.Controls.MetroLabel metroLabel5; - private MetroFramework.Controls.MetroLabel metroLabel4; - private MetroFramework.Controls.MetroLabel metroLabel3; - private MetroFramework.Controls.MetroLabel metroLabel2; - private MetroFramework.Controls.MetroLabel metroLabel1; private MetroFramework.Controls.MetroButton stopServerButton; private MetroFramework.Controls.MetroButton TestJSButton; private MetroFramework.Controls.MetroTabPage ThreadsInfo; @@ -656,5 +283,8 @@ namespace Step.UI private System.Windows.Forms.ColumnHeader columnHeader1; private System.Windows.Forms.ColumnHeader columnHeader2; private MetroFramework.Controls.MetroTextBox TXTstatus; + private Label TXTType; + private MetroFramework.Controls.MetroCheckBox CHNcConnected; + private Label label1; } } \ No newline at end of file diff --git a/Step.UI/ServerControlWindow.cs b/Step.UI/ServerControlWindow.cs index 08458d99..42bbf327 100644 --- a/Step.UI/ServerControlWindow.cs +++ b/Step.UI/ServerControlWindow.cs @@ -42,7 +42,7 @@ namespace Step.UI MessageServices.Current.Subscribe(SHOW_MSG_UI, (a, b) => { - this.Invoke((MethodInvoker)delegate () { this.Focus(); MessageBox.Show(a.ToString()); }); + Invoke((MethodInvoker)delegate () { Focus(); MessageBox.Show(a.ToString()); }); }); } @@ -139,122 +139,92 @@ namespace Step.UI private void InitializeMessageListeners() { - MVVMListeners = new List(); - MVVMListeners.Add(MessageServices.Current.Subscribe(SEND_MESSAGE, (a, b) => + MVVMListeners = new List { + MessageServices.Current.Subscribe(SEND_MESSAGE, (a, b) => + { // Cast object to ErrorMessageModel ErrorMessageModel message = (ErrorMessageModel)a; // If error has a fatal level, icon must be error message.ErrorLevel = message.ErrorLevel > (int)ERROR_LEVEL.ERROR ? (int)ERROR_LEVEL.ERROR : message.ErrorLevel; - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () - { + if (!this.IsDisposed) + this.Invoke((MethodInvoker)delegate () + { // Open BalloonTip with data StepNotifyIcon.ShowBalloonTip(1000, message.Title, message.Message, (ToolTipIcon)message.ErrorLevel); //ShowMessage on UI TXTstatus.Text = "[" + DateTime.Now.ToString("T") + "] " + message.Message; - }); - })); - - MVVMListeners.Add(MessageServices.Current.Subscribe(SEND_NC_STATUS, (a, b) => - { - bool newNcStatus = (bool)a; - - if (ncStatus != newNcStatus) + }); + }), + // NC status handler + MessageServices.Current.Subscribe(SEND_NC_STATUS, (a, b) => { - ncStatus = newNcStatus; - string title = "NC not connected"; - string message = "Check NC connection"; - ToolTipIcon toolTipIcon = ToolTipIcon.Error; + bool newNcStatus = (bool)a; - if (ncStatus == true) + if (ncStatus != newNcStatus) { - title = "Nc connection established"; - message = "Comunication started"; - toolTipIcon = ToolTipIcon.Info; - } + ncStatus = newNcStatus; + string title = "NC not connected"; + string message = "Check NC connection"; + ToolTipIcon toolTipIcon = ToolTipIcon.Error; - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () + if (ncStatus) { - StepNotifyIcon.ShowBalloonTip(1000, title, message, toolTipIcon); - TXTstatus.Text = "[" + DateTime.Now.ToString("T") + "] " + title; - }); - } + title = "Nc connection established"; + message = "Comunication started"; + toolTipIcon = ToolTipIcon.Info; + } - if (ncStatus) - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () - { - StepNotifyIcon.Icon = Properties.Resources.Step_Icon; - }); - else - { - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () + if (!IsDisposed) + Invoke((MethodInvoker)delegate () { - TXTName.Text = ""; - TXTNcSerial.Text = ""; - TXTCMSMach.Text = ""; - TXTSftVers.Text = ""; - TXTNCProc.Text = ""; - TXTTime.Text = ""; - TXTLang.Text = ""; - StepNotifyIcon.Icon = Properties.Resources.Step_Disconnected; + // Show balloon with new status + StepNotifyIcon.ShowBalloonTip(1000, title, message, toolTipIcon); + TXTstatus.Text = "[" + DateTime.Now.ToString("T") + "] " + title; }); } - //Other type - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () - { - CHNcConnected.Checked = ncStatus; - }); - })); + if (ncStatus) + if (!IsDisposed) + Invoke((MethodInvoker)delegate () + { + StepNotifyIcon.Icon = Properties.Resources.Step_Icon; + }); - MVVMListeners.Add(MessageServices.Current.Subscribe(SEND_THREADS_STATUS, (a, b) => - { //Other type - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () - { - if (!isUpdatingThreads) + if (!IsDisposed) + Invoke((MethodInvoker)delegate () { - isUpdatingThreads = true; - Dictionary Threads = new Dictionary((Dictionary)a); + CHNcConnected.Checked = ncStatus; + }); + }), + // Threads status handler + MessageServices.Current.Subscribe(SEND_THREADS_STATUS, (a, b) => + { + //Other type + if (!IsDisposed) + Invoke((MethodInvoker)delegate () + { + if (!isUpdatingThreads) + { + isUpdatingThreads = true; + Dictionary Threads = new Dictionary((Dictionary)a); //Begin the update LISTThreadStatus.BeginUpdate(); //clear the List LISTThreadStatus.Items.Clear(); //Add all items foreach (KeyValuePair Thr in Threads) - LISTThreadStatus.Items.Add(new ListViewItem(new string[] { Thr.Key, Thr.Value })); + LISTThreadStatus.Items.Add(new ListViewItem(new string[] { Thr.Key, Thr.Value })); //End the update LISTThreadStatus.EndUpdate(); - isUpdatingThreads = false; - } - }); - })); - - MVVMListeners.Add(MessageServices.Current.Subscribe(SEND_GENERIC_DATA, (a, b) => - { - DTONcGenericDataModel data = (DTONcGenericDataModel)a; - - //Other type - if (!this.IsDisposed) - this.Invoke((MethodInvoker)delegate () - { - TXTName.Text = data.NcModel; - TXTNcSerial.Text = data.SerialNumber; - TXTCMSMach.Text = data.CmsMachineIdNumber; - TXTSftVers.Text = data.NcSoftwareVersion; - TXTNCProc.Text = data.ProcessNumber.ToString(); - TXTLang.Text = data.Language; - TXTTime.Text = data.DateTime.ToShortDateString() + " " + data.DateTime.ToShortTimeString(); - }); - })); + isUpdatingThreads = false; + } + }); + }) + }; } } } \ No newline at end of file diff --git a/Step/Controllers/WebApi/NcToolManagerController.cs b/Step/Controllers/WebApi/NcToolManagerController.cs index b48bb968..3d4b5cf9 100644 --- a/Step/Controllers/WebApi/NcToolManagerController.cs +++ b/Step/Controllers/WebApi/NcToolManagerController.cs @@ -4,7 +4,6 @@ using Step.Model.DTOModels.ToolModels; using Step.NC; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; -using System.Linq; using System.Web.Http; using static CMS_CORE_Library.DataStructures; using static Step.Config.ServerConfig; @@ -51,25 +50,26 @@ namespace Step.Controllers.WebApi if (shank == null) return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); } + else + { + // If option is not active create a shank + DTONewNcShankModel newShank = new DTONewNcShankModel() + { + Balluf = 0, + MagazinePositionType = 0 + }; + + // Create a new shank + DbNcShankModel ncShank = toolsManager.AddShank(newShank); + // Connect tool to new shank + dtoTool.ShankId = ncShank.ShankId; + } } using (NcHandler ncHandler = new NcHandler()) { ncHandler.Connect(); - // Check option - if (!ToolManagerConfig.ShankOptIsActive) - { - // if option is not active create a shank - DTONcShankModel newShank = new DTONcShankModel() - { - Balluf = 0, - MagazinePositionType = 0 - }; - // Add new shank - DTONcShankModel ncShank = ncHandler.AddShank(newShank); - // Set tool shank id - dtoTool.ShankId = ncShank.Id; - } + // Add tool DTONcToolModel newTool = ncHandler.AddTool(dtoTool); @@ -91,7 +91,7 @@ namespace Step.Controllers.WebApi if (tool == null) return NotFound(); - if(tool.FamilyId != dtoTool.FamilyId) + if (tool.FamilyId != dtoTool.FamilyId) { // Check if family exists DbNcFamilyModel fam = toolsManager.FindFamily(dtoTool.FamilyId); @@ -130,7 +130,9 @@ namespace Step.Controllers.WebApi // If option is active find & delete tool shank DbNcShankModel shank = toolsManager.FindShankWithTools(tool.ShankId.Value); - ncHandler.DeleteNcShank(shank.ShankId); + CmsError cmsError = ncHandler.DeleteNcShank(shank.ShankId); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); } ncHandler.DeleteNcTool(tool); @@ -162,10 +164,10 @@ namespace Step.Controllers.WebApi if (!ToolManagerConfig.ShankOptIsActive) return BadRequest(API_ERROR_KEYS.OPTION_NOT_ACTIVE); - using (NcHandler ncHandler = new NcHandler()) + using (NcToolManagerController toolsManager = new NcToolManagerController()) { - ncHandler.Connect(); - DTONcShankModel shank = ncHandler.AddShank(dtoShank); + DTONcShankModel shank = (DTONcShankModel)toolsManager.AddShank(dtoShank); + return Ok(shank); } } @@ -185,9 +187,12 @@ namespace Step.Controllers.WebApi using (NcHandler ncHandler = new NcHandler()) { - ncHandler.Connect(); + CmsError cmsError = ncHandler.Connect(); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + // Update shank - CmsError cmsError = ncHandler.UpdateShank(shankId, dtoShank, out DTONcShankModel newShank); + cmsError = ncHandler.UpdateShank(shankId, dtoShank, out DTONcShankModel newShank); if (cmsError.IsError()) return BadRequest(cmsError.localizationKey); @@ -208,9 +213,13 @@ namespace Step.Controllers.WebApi using (NcHandler ncHandler = new NcHandler()) { - ncHandler.Connect(); + CmsError cmsError = ncHandler.Connect(); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); - ncHandler.DeleteNcShank(shank.ShankId); + cmsError = ncHandler.DeleteNcShank(shank.ShankId); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); return Ok(); } @@ -229,7 +238,10 @@ namespace Step.Controllers.WebApi using (NcHandler ncHandler = new NcHandler()) { - ncHandler.Connect(); + CmsError cmsError = ncHandler.Connect(); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + DTONcFamilyModel newFamily = ncHandler.AddFamily(dtoFamily); return Ok(newFamily); @@ -262,9 +274,12 @@ namespace Step.Controllers.WebApi using (NcHandler ncHandler = new NcHandler()) { - ncHandler.Connect(); + CmsError cmsError = ncHandler.Connect(); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + // Update into db and NC - CmsError cmsError = ncHandler.UpdateFamily(familyId, dtoFamily, out DTONcFamilyModel newFamily); + cmsError = ncHandler.UpdateFamily(familyId, dtoFamily, out DTONcFamilyModel newFamily); if (cmsError.IsError()) return BadRequest(cmsError.localizationKey); @@ -285,9 +300,14 @@ namespace Step.Controllers.WebApi using (NcHandler ncHandler = new NcHandler()) { - ncHandler.Connect(); + CmsError cmsError = ncHandler.Connect(); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); + //Delete - ncHandler.DeleteNcFamily(family); + cmsError = ncHandler.DeleteNcFamily(family); + if (cmsError.IsError()) + return BadRequest(cmsError.localizationKey); return Ok(); } @@ -303,7 +323,7 @@ namespace Step.Controllers.WebApi { using (NcToolManagerController toolsManager = new NcToolManagerController()) { - List magazines = toolsManager.FindMagazinePositions(); + List magazines = toolsManager.FindMagazinesPositions(); return Ok(magazines); } @@ -335,6 +355,7 @@ namespace Step.Controllers.WebApi using (NcHandler ncHandler = new NcHandler()) { + ncHandler.Connect(); CmsError cmsError = ncHandler.UpdateMagazinePosition(pos, dtoPos, out DTONcMagazinePositionModel newPos); if (cmsError.IsError()) return BadRequest(cmsError.localizationKey); @@ -396,10 +417,10 @@ namespace Step.Controllers.WebApi // Check if magazine position exists DbNcMagazinePositionModel magPos = toolsManager.FindMagazinePosition(magazineId, positionId); - if(magPos == null) + if (magPos == null) return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); // Check if the mag pos is disabled - if(magPos.Disabled == true) + if (magPos.Disabled == true) return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); using (NcHandler ncHandler = new NcHandler()) @@ -407,7 +428,6 @@ namespace Step.Controllers.WebApi // Get Configuration ncHandler.Connect(); - // Check if shank can fit CmsError cmsError = ncHandler.CheckIfShankCanFit( magazineId, @@ -426,8 +446,6 @@ namespace Step.Controllers.WebApi return Ok(magazinePos); } - - } [Route("magazine/{magazineId:int}/unload/position/{positionId:int}"), HttpPut] @@ -465,7 +483,6 @@ namespace Step.Controllers.WebApi return Ok(responseShank); } } - [Route("shank/{shankId:int}/load/tool/{toolId:int}"), HttpPut] public IHttpActionResult LoadToolIntoShank(int shankId, int toolId) @@ -482,7 +499,7 @@ namespace Step.Controllers.WebApi return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); tool = toolsManager.FindTool(toolId); - if(tool== null) + if (tool == null) return BadRequest(API_ERROR_KEYS.INCORRECT_PARAMETERS); } @@ -507,11 +524,10 @@ namespace Step.Controllers.WebApi // if (cmsError.IsError()) // return BadRequest(cmsError.localizationKey); - // return Ok(); // } //} - + //[Route("stop_edit_data"), HttpPut] //public IHttpActionResult StopEdit() //{ @@ -538,7 +554,6 @@ namespace Step.Controllers.WebApi if (cmsError.IsError()) return BadRequest(cmsError.localizationKey); - return Ok(); } } diff --git a/Step/Listeners/ListenersHandler.cs b/Step/Listeners/ListenersHandler.cs index d3f74f19..0f4ed919 100644 --- a/Step/Listeners/ListenersHandler.cs +++ b/Step/Listeners/ListenersHandler.cs @@ -19,60 +19,60 @@ namespace Step.Listeners public static void Start() { - infos.Add(MessageServices.Current.Subscribe(SEND_ALARMS, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_ALARMS, (a, b) => { SignalRListener.SendAlarmsToClient(a as DTOAlarmsModel); })); - infos.Add(MessageServices.Current.Subscribe(SEND_POWER_ON_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_POWER_ON_DATA, (a, b) => { SignalRListener.SendPowerOnDataToClient(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_NC_STATUS, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_NC_STATUS, (a, b) => { SignalRListener.SendNcNetworkStatus(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_PROCESSES_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_PROCESSES_DATA, (a, b) => { SignalRListener.SendProcessesData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_FUNCTIONALITY_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_FUNCTIONALITY_DATA, (a, b) => { SignalRListener.SendFunctionalityData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_EXPIRED_MAINTENANCES_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_EXPIRED_MAINTENANCES_DATA, (a, b) => { SignalRListener.SendExpMaintenancesData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_NC_SOFTKEYS_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_NC_SOFTKEYS_DATA, (a, b) => { SignalRListener.SendNcSoftKeysData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_USER_SOFTKEYS_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_USER_SOFTKEYS_DATA, (a, b) => { SignalRListener.SendUserSoftKeysData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_HEADS_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_HEADS_DATA, (a, b) => { SignalRListener.SendHeadsData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_AXIS_NAMES_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_AXIS_NAMES_DATA, (a, b) => { SignalRListener.SendAxesNamesData(a); })); - infos.Add(MessageServices.Current.Subscribe(SEND_MAGAZINES_STATUS, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(SEND_MAGAZINES_STATUS, (a, b) => { SignalRListener.SendMagazinesStatus(a); })); - infos.Add(MessageServices.Current.Subscribe(BROADCAST_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(BROADCAST_DATA, (a, b) => { SignalRListener.BroadcastData(); })); - infos.Add(MessageServices.Current.Subscribe(UPDATE_TOOLS_DATA, async (a, b) => + infos.Add(MessageServices.Current.Subscribe(UPDATE_TOOLS_DATA, (a, b) => { SignalRDatabaseHandler.UpdateToolsData(a); })); diff --git a/Step/program.cs b/Step/program.cs index bd2bf7a7..225097d5 100644 --- a/Step/program.cs +++ b/Step/program.cs @@ -79,6 +79,7 @@ namespace Step StopRequest.WaitOne(); LogInfo("Application closed"); } + // Stop Threads ThreadsHandler.Close(); // Stop messageservice listeners