using DTS.Common.Settings; using System; using System.ComponentModel; using DTS.Common.Enums; using DTS.Common.Events; using DTS.Common.Interface; using DTS.Common.Storage; using System.Collections.Generic; using System.Linq; using Prism.Events; namespace ISOSettings.Model { public class ISOSettingsModel : IISOSettingsModel { public void OnPropertyChanged(string propertyName) { } public ISOSettingsModel(IEventAggregator eventAggregator) { EventAggregator = eventAggregator; } private IEventAggregator EventAggregator { get; set; } public IISOSettingsData LoadData() { return new ISOSettingsData { ISOViewMode = ISOViewMode, ShowISOStringBuilder = ShowISOStringBuilder, ShowChannelCodeLookupHelper = ShowChannelCodeLookupHelper, UseISOCodeFilterMapping = UseISOCodeFilterMapping, UniqueISOCodesRequired = UniqueISOCodesRequired, ValidateTestObjectAndPosition = ValidateTestObjectAndPosition }; } public void SaveData(IISOSettingsData data) { try { ShowISOCodes = ((ISOSettingsData)data).ShowISOCodes; ShowUserCodes = ((ISOSettingsData)data).ShowUserCodes; ISOViewMode = ((ISOSettingsData)data).ISOViewMode; ShowISOStringBuilder = ((ISOSettingsData)data).ShowISOStringBuilder; ShowChannelCodeLookupHelper = ((ISOSettingsData)data).ShowChannelCodeLookupHelper; UseISOCodeFilterMapping = ((ISOSettingsData)data).UseISOCodeFilterMapping; var previousValue = UniqueISOCodesRequired; UniqueISOCodesRequired = ((ISOSettingsData)data).UniqueISOCodesRequired; var previousTestObjectAndPosition = ValidateTestObjectAndPosition; ValidateTestObjectAndPosition = ((ISOSettingsData)data).ValidateTestObjectAndPosition; //14215 Not able to Run Test, if this setting is changed we have to re-evaluate "IsComplete" for all tests //we have options for future optimization by selectively marking tests dirty based on whether they are already complete/dirty etc //for example there's no point in marking a tests setup that's already marked as dirty as dirty again, or if //we are going to UniqueISOCodesRequired as true and the test is already incomplete, we don't need to mark it dirty, etc. //16235 'Validate Test Object and Position' turned off, but both of my test setups are marked as not ready //revalidate on change of validate TestObject & Position if (UniqueISOCodesRequired != previousValue || ValidateTestObjectAndPosition != previousTestObjectAndPosition) { MarkAllTestsDirty(); } IsSaved = true; } catch (Exception ex) { EventAggregator.GetEvent().Publish(new NotificationContentEventArgs(ex.Message, ex.StackTrace, PopupWindowImage.Information, "DataPro")); } } /// /// gets a list of all test names in the db /// /// private IList GetAllTests() { var tests = new List(); var hr = DbOperations.TestSetupsGet(null, null, double.NaN, double.NaN, false, false, out var records, out var errors); if (0 == hr && null != records && records.Any()) { foreach (var record in records) { if (!tests.Contains(record.Name)) { tests.Add(record.Name); } } } return tests; } /// /// marks a given test as dirty /// /// private void MarkTestDirty(string test) { _ = DbOperations.TestSetupsMarkIsCompleteIsDirty(test, true, false, string.Empty); } /// /// 14215 Not able to Run Test /// when iso restrictions tests may become incomplete or complete, by setting tests to dirty the tests will be re-evaluated at a later point /// private void MarkAllTestsDirty() { var tests = GetAllTests(); if (tests.Any()) { foreach (var test in tests) { MarkTestDirty(test); } } } private const IsoSupportLevels ISOSupportLevelDefault = IsoSupportLevels.ISO_ONLY; public IsoSupportLevels ISOSupportLevel { get { var s = SettingsDB.GetGlobalValue(Keys.IsoSupportLevel.ToString(), ISOSupportLevelDefault.ToString()); return !Enum.TryParse(s, out IsoSupportLevels level) ? IsoSupportLevels.ISO_ONLY : level; } set => SettingsDB.SetGlobalValue(Keys.IsoSupportLevel.ToString(), value.ToString()); } private const bool ShowISOCodesDefault = true; /// /// controls whether ISOCodes are shown when user is in ISO mode some customers may run in ISO mode but still not care to see ISOCodes /// public bool ShowISOCodes { get => SettingsDB.GetGlobalValueBool(Keys.ShowISOCodes.ToString(), ShowISOCodesDefault); set => SettingsDB.SetGlobalValueBoolean(Keys.ShowISOCodes.ToString(), value); } private const bool ShowUserCodesDefault = false; /// /// controls whether User Codes are shown /// public bool ShowUserCodes { get => SettingsDB.GetGlobalValueBool(Keys.ShowUserCodes.ToString(), ShowUserCodesDefault); set => SettingsDB.SetGlobalValueBoolean(Keys.ShowUserCodes.ToString(), value); } public bool ValidChannelCodes => ShowISOCodes || ShowUserCodes; public IsoViewMode ISOViewMode { get { var showISO = ShowISOCodes; var showUser = ShowUserCodes; if (showISO && showUser) { return IsoViewMode.ISOAndUserCode; } if (!showISO && !showUser) { return IsoViewMode.ChannelNameOnly; } return showUser ? IsoViewMode.UserCodeOnly : IsoViewMode.ISOOnly; } set { switch (value) { case IsoViewMode.ISOAndUserCode: SettingsDB.SetGlobalValueBoolean(Keys.ShowISOCodes.ToString(), true); SettingsDB.SetGlobalValueBoolean(Keys.ShowUserCodes.ToString(), true); break; case IsoViewMode.ISOOnly: SettingsDB.SetGlobalValueBoolean(Keys.ShowISOCodes.ToString(), true); SettingsDB.SetGlobalValueBoolean(Keys.ShowUserCodes.ToString(), false); break; case IsoViewMode.UserCodeOnly: SettingsDB.SetGlobalValueBoolean(Keys.ShowISOCodes.ToString(), false); SettingsDB.SetGlobalValueBoolean(Keys.ShowUserCodes.ToString(), true); break; case IsoViewMode.ChannelNameOnly: SettingsDB.SetGlobalValueBoolean(Keys.ShowISOCodes.ToString(), false); SettingsDB.SetGlobalValueBoolean(Keys.ShowUserCodes.ToString(), false); break; } } } private const bool ShowISOStringBuilderDefault = true; /// /// controls whether ISOStringBuilder are shown when user is in ISO mode some customers may run in ISO mode but still not care to see ISOStringBuilder /// public bool ShowISOStringBuilder { get => SettingsDB.GetGlobalValueBool(Keys.ShowISOStringBuilder.ToString(), ShowISOStringBuilderDefault); set => SettingsDB.SetGlobalValueBoolean(Keys.ShowISOStringBuilder.ToString(), value); } private const bool ShowChannelCodeLookupHelperDefault = true; /// /// controls whether ChannelCodeLookupHelper are shown when user is in ISO mode some customers may run in ISO mode but still not care to see ChannelCodeLookupHelper /// public bool ShowChannelCodeLookupHelper { get => SettingsDB.GetGlobalValueBool(Keys.ShowChannelCodeLookupHelper.ToString(), ShowChannelCodeLookupHelperDefault); set => SettingsDB.SetGlobalValueBoolean(Keys.ShowChannelCodeLookupHelper.ToString(), value); } private const bool UseISOCodeFilterMappingDefault = true; public bool UseISOCodeFilterMapping { get => SettingsDB.GetGlobalValueBool(Keys.UseISOCodeFilterMapping.ToString(), UseISOCodeFilterMappingDefault); set => SettingsDB.SetGlobalValueBoolean(Keys.UseISOCodeFilterMapping.ToString(), value); } private const bool UniqueISOCodesRequiredDefault = true; public bool UniqueISOCodesRequired { get => SettingsDB.GetGlobalValueBool(Keys.UniqueISOCodesRequired.ToString(), UniqueISOCodesRequiredDefault); set => SettingsDB.SetGlobalValueBoolean(Keys.UniqueISOCodesRequired.ToString(), value); } private const bool AllowTransitionalDefault = false; public bool AllowTransitional { get => SettingsDB.GetGlobalValueBool(Keys.ISOSupportAllowTransitional.ToString(), AllowTransitionalDefault); set => SettingsDB.SetGlobalValueBoolean(Keys.ISOSupportAllowTransitional.ToString(), value); } private const bool AllowNonIsoDefault = false; public bool AllowNonISO { get => SettingsDB.GetGlobalValueBool(Keys.ISOSupport_Allow_NonISO.ToString(), AllowNonIsoDefault); set => SettingsDB.SetGlobalValueBoolean(Keys.ISOSupport_Allow_NonISO.ToString(), value); } private const bool UseUserCodeDefault = false; public bool UseUserCodes { get => SettingsDB.GetGlobalValueBool(Keys.UseUserCodes.ToString(), UseUserCodeDefault); set => SettingsDB.SetGlobalValueBoolean(Keys.UseUserCodes.ToString(), value); } private const bool ValidateTestObjectAndPositionDefault = false; /// /// Whether the ISO test object and position fields should be validated with respect to /// test setup validation /// 15457 add error validation against valid ISO test object and position controlled by a site bool in system settings /// public bool ValidateTestObjectAndPosition { get => SettingsDB.GetGlobalValueBool(Keys.ValidateTestPositionAndTestObject.ToString(), ValidateTestObjectAndPositionDefault); set => SettingsDB.SetGlobalValueBoolean(Keys.ValidateTestPositionAndTestObject.ToString(), value); } public event PropertyChangedEventHandler PropertyChanged; public bool IsSaved { get; private set; } } }