public AddEditAlarmPropertyViewModel()
 {
     //NEW
     AlarmProperty = new ControlSystemAlarmProperty();
     LoadData();
     InitialiseCommandButtons();
 }
        private ControlSystemComponent BuildClone(ControlSystemComponent controlSystemComponent)
        {
            var clone = new ControlSystemComponent();
            CommonUtils.CloneObject(clone, controlSystemComponent, "");
            clone.ControlSystemComponentTypeId = controlSystemComponent.ControlSystemComponentTypeId;
            clone.ControlSystemComponentType = controlSystemComponent.ControlSystemComponentType;

            foreach (var pv in controlSystemComponent.ControlSystemAlarmPropertyValues)
            {
                var pvClone = new ControlSystemAlarmPropertyValue();
                CommonUtils.CloneObject(pvClone, pv, "");
                clone.ControlSystemAlarmPropertyValues.Add(pvClone);

                var propClone = new ControlSystemAlarmProperty();
                CommonUtils.CloneObject(propClone, pv.ControlSystemAlarmProperty, "");

                propClone.ControlSystemUserInterfacePlatform = pv.ControlSystemAlarmProperty.ControlSystemUserInterfacePlatform;
                propClone.UserInterfacePlatformId = pv.ControlSystemAlarmProperty.UserInterfacePlatformId;

                pvClone.ControlSystemAlarmProperty = propClone;
                pvClone.ControlSystemAlarmPropertyId = propClone.Id;

            }

            return clone;
        }
예제 #3
0
        private void ImportAlarmProperties(CmsEntities cee, OldCmsEntities old)
        {
            Logger.Out("ImportAlarmProperties - start");
            var sw = new Stopwatch();
            sw.Start();

            var index = 0;
            var alarmTypesCount = (from x in old.AlarmTypes select x).Count();

            ControlSystemUserInterfacePlatform centumUIP = (from x in cee.ControlSystemUserInterfacePlatforms where x.Name.Equals("centum", StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

            var newAlarmPropertyNames = cee.ControlSystemAlarmProperties.Select(x => x.Name).ToList();

            foreach (var oldAlarmType in old.AlarmTypes.OrderBy(x => x.Id))
            {
                if (!newAlarmPropertyNames.Contains(oldAlarmType.Name))
                {
                    var alarmProperty = new ControlSystemAlarmProperty
                    {
                        Name = oldAlarmType.Name,
                        Description = oldAlarmType.Description,
                    };

                    if (centumUIP != null)
                    {
                        alarmProperty.UserInterfacePlatformId = centumUIP.Id;
                    }

                    //TuningPropertyId
                    ControlSystemTuningProperty tuningProperty = (from x in cee.ControlSystemTuningProperties where x.Name.Equals(oldAlarmType.TuningParameterTypeName, StringComparison.CurrentCultureIgnoreCase) select x).FirstOrDefault();

                    if (tuningProperty != null)
                    {
                        alarmProperty.TuningPropertyId = tuningProperty.Id;
                    }

                    cee.ControlSystemAlarmProperties.Add(alarmProperty);

                    newAlarmPropertyNames.Add(alarmProperty.Name);
                    index++;
                }
                else
                {
                    Logger.Out(string.Format("Skipped Alarm Property {0} , {1} as it already exist ...", oldAlarmType.Id, oldAlarmType.Name));
                }

                UpdateStatus(string.Format("Importing Alarm Property '{0}' ({1} of {2}).", oldAlarmType.Name, index, alarmTypesCount));
            }

            Logger.Out("Saving AlarmProperties...");
            cee.SaveChanges();
            sw.Stop();
            Logger.Out(string.Format("Imported {0} out of {1} AlarmProperties in {2} min, {3} sec.", index, alarmTypesCount, sw.Elapsed.Minutes, sw.Elapsed.Seconds));
            Logger.Out("");
            Logger.Out("");
        }
예제 #4
0
        private static bool MatchAlarmPropertyFailed(List<ControlSystemAlarmProperty> alarmProperties, Alarm oldAlarm, out ControlSystemAlarmProperty matchedProperty)
        {
            matchedProperty = (from x in alarmProperties
                               where x.Name.Equals(oldAlarm.AlarmType.Name, StringComparison.CurrentCultureIgnoreCase)
                               select x).FirstOrDefault();

            if (matchedProperty == null)
            {
                Logger.Out(string.Format("MatchAlarmPropertyFailed on Alarm ID {0}:- could not match Alarm Property using Name '{1}'.", oldAlarm.Id, oldAlarm.AlarmType.Name));
                return true;
            }
            return false;
        }
        private void LoadData(int alarmPropertyId)
        {
            var getAlarmColoursTask = DatabaseLoader.GetControlSystemAlarmColours();
            var getPriorityListTask = DatabaseLoader.GetControlSystemAlarmPriorities();
            var getGetAllControlSystemAlarmMappingCentumsTask = DatabaseLoader.GetControlSystemAlarmMappingCentums(alarmPropertyId);
            var getCentumControlSystemAlarmPropertiesTask = DatabaseLoader.GetCentumControlSystemAlarmProperties();

            var tasks = new List<Task>
            {
                getAlarmColoursTask,
                getPriorityListTask,
                getGetAllControlSystemAlarmMappingCentumsTask,
                getCentumControlSystemAlarmPropertiesTask
            };

            Task.Factory.ContinueWhenAll(tasks.ToArray(), xx =>
            {
                CMS.UiFactory.StartNew(() =>
                {
                    mColours = getAlarmColoursTask.Result;
                    mPriorities = getPriorityListTask.Result;
                    ExistingCentums = getGetAllControlSystemAlarmMappingCentumsTask.Result;

                    mSelectedProperty = (from x in getCentumControlSystemAlarmPropertiesTask.Result where x.Id == alarmPropertyId select x).FirstOrDefault();

                    if (mSelectedProperty != null)
                    {

                        LoadCentumControls(mSelectedProperty.Id);}

                    RaisePropertyChanged("SelectedProperty");
                    OnDataLoaded();
                });
            });
        }
        public DbOperationResult<ControlSystemAlarmProperty> SaveControlSystemAlarmProperty(ControlSystemAlarmProperty controlSystemAlarmProperty)
        {
            var result = new DbOperationResult<ControlSystemAlarmProperty>();

            try
            {
                using (var cee = new CmsEntities())
                {
                    var original = (from x in cee.ControlSystemAlarmProperties where x.Id == controlSystemAlarmProperty.Id select x).FirstOrDefault();

                    if (original == null)
                    {
                        cee.ControlSystemAlarmProperties.Add(controlSystemAlarmProperty);
                        cee.SaveChanges();
                        result.EntityResult = controlSystemAlarmProperty;
                    }
                    else
                    {
                        cee.Entry(original).CurrentValues.SetValues(controlSystemAlarmProperty);
                        cee.SaveChanges();
                        result.EntityResult = original;
                    }
                }
            }
            catch (Exception ex)
            {
                log.Error("", ex, ex.ToString());
                result.ServerErrorMessages.Add(string.Format("Could not Save ControlSystem Alarm Property.{0}{1}", Environment.NewLine, ex.Message));
            }
            return result;
        }