コード例 #1
0
        public ControlSystemAlarmPropertyDetailsViewModel(ControlSystemAlarmPropertyValue controlSystemAlarmPropertyValue, int level)
        {
            CompositionInitializer.SatisfyImports(this);

            CloneAndSetNulls(controlSystemAlarmPropertyValue);

            mControlSystemAlarmPropertyValue = controlSystemAlarmPropertyValue;
            mLevel = level;
            LoadData();
        }
コード例 #2
0
        public ControlSystemAlarmPropertiesWrapViewModel(List<ControlSystemAlarmMappingCentum> alarmMappingCentums, ControlSystemAlarmPropertyValue propertyValue, int level, List<ControlSystemAlarmPriority> priorities,
            List<ControlSystemAlarmColour> colours, List<ControlSystemAlarmPurpose> puposes,
            List<ControlSystemAlarmResponse> responses, List<ControlSystemAlarmConsequence> consequenses)
        {
            mPropertyValue = propertyValue;

            mAlarmMappingCentums = alarmMappingCentums;
            Priorities = priorities;
            Colours = colours;
            Purposes = puposes;
            Responses = responses;
            Consequences = consequenses;
        }
コード例 #3
0
        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;
        }
コード例 #4
0
 private void CloneAndSetNulls(ControlSystemAlarmPropertyValue controlSystemAlarmPropertyValue)
 {
     CommonUtils.CloneObject(mClone, controlSystemAlarmPropertyValue, controlSystemAlarmPropertyValue.Id.ToString());
     //we need to set to ensure we have no NULLS in the Properties of type 'string'.  otherwise the 'string.Equals' will not pick up changes.
     mClone.Guidance += "";
     mClone.Notes += "";
     mClone.MaskingExpr += "";
     mClone.ActivationExpr += "";
     mClone.AlarmCalcExpr += "";
     mClone.MaskingExpr += "";
 }
コード例 #5
0
ファイル: AlarmMigrater.cs プロジェクト: barrett2474/CMS2
        private void ImportAlarmPropertyValues(CmsEntities cee, OldCmsEntities old)
        {
            Logger.Out("ImportControlSystemAlarmPropertyValues - start");
            var sw = new Stopwatch();
            sw.Start();

            var dicKeyValuePairs = LoadExistingPropertyValueKeys(cee);
            var newResponses = (from x in cee.ControlSystemAlarmResponses select x).ToList();
            var newPurposeListNames = (from x in cee.ControlSystemAlarmPurposes select x).ToList();
            var newConseqListNames = (from x in cee.ControlSystemAlarmConsequences select x).ToList();

            var newPriorityNames = (from x in cee.ControlSystemAlarmPriorities select x).ToList();
            var alarmProperties = (from x in cee.ControlSystemAlarmProperties select x).ToList();

            var oldAlarms = (from x in old.Alarms
                .Include("AlarmType")
                .Include("AlarmConsequence")
                .Include("AlarmPurpose")
                .Include("AlarmResponse")
                .Include("Element")
                .Include("Element.ElementTypical")
                .Include("Element.ControlModule")
                             select x).ToList();

            var index = 0;
            foreach (var oldAlarm in oldAlarms.OrderBy(x => x.Id))
            {

                var apv = new ControlSystemAlarmPropertyValue();

                //ControlSystemComponent
                ControlSystemComponent matchedNewCmsComponent;
                if (MatchNewComponentFailed(cee, oldAlarm, out matchedNewCmsComponent)) continue;

                //AlarmProperty
                ControlSystemAlarmProperty matchedAlarmProperty;
                if (MatchAlarmPropertyFailed(alarmProperties, oldAlarm, out matchedAlarmProperty)) continue;

                //checkforduplicate
                var kvp = new KeyValuePair<int, int>(matchedNewCmsComponent.Id, matchedAlarmProperty.Id);
                if (!dicKeyValuePairs.Contains(kvp))
                {
                    dicKeyValuePairs.Add(kvp);
                }
                else
                {
                    Logger.Out(string.Format("Skipping Alarm ID {0} - duplicate on ComponentId '{1}' and AlarmPropertyId '{2}'.", oldAlarm.Id, matchedNewCmsComponent.Id, matchedAlarmProperty.Id));
                    continue;
                }

                //ControlSystemComponentType
                ControlSystemComponentType matchedComponentType;
                if (MatchComponentTypeFailed(cee, old, oldAlarm, out matchedComponentType)) continue;

                //ReviewCompleted
                if (oldAlarm.Element == null || oldAlarm.Element.ControlModule == null)
                {
                    Logger.Out(string.Format("Element or ControlModule on Alarm ID {0} was null.  Trying to set the Review Completed values.", oldAlarm.Id));
                    continue;
                }

                if (oldAlarm.Detection)
                {
                    apv.ReviewCompleted = oldAlarm.Element.ControlModule.AlarmSettingsConfirmed;
                    apv.ReviewedCompletedById = oldAlarm.Element.ControlModule.AlarmSettingsConfirmedUserId;
                    apv.ReviewedCompletedDate = oldAlarm.Element.ControlModule.AlarmSettingsConfirmedDate;
                }

                //AlarmPurpose
                ControlSystemAlarmPurpose matchPurpose;
                if (MatchPurposeFailed(newPurposeListNames, oldAlarm, out matchPurpose)) continue;

                //AlarmConsequence
                ControlSystemAlarmConsequence matchConsequence;
                if (MatchConsequenceFailed(newConseqListNames, oldAlarm, out matchConsequence)) continue;

                //AlarmResponse
                ControlSystemAlarmResponse matchResponse;
                if (MatchResponseFailed(newResponses, oldAlarm, out matchResponse)) continue;

                //TestedBy

                if (oldAlarm.Tested)
                {
                    User matchedTestedUser;
                    if (!MatchTestebByUserFailed(cee, old, oldAlarm, out matchedTestedUser))
                    {
                        if (matchedTestedUser!=null)
                        {
                            apv.TestedUserId = matchedTestedUser.Id;
                            apv.TestedDate = oldAlarm.TestedDate;
                            apv.Tested = oldAlarm.Tested;
                        }
                    }
                }

                //ModifiedBy
                User matchedLastModifiedByUser;
                if (!MatchModifiedByUserFailed(cee, old, oldAlarm, out matchedLastModifiedByUser))
                {
                    if (matchedLastModifiedByUser!=null)
                    {
                        apv.ModifiedUserId = matchedLastModifiedByUser.Id;
                        apv.ModifiedDate = oldAlarm.ModifiedDate;
                    }

                }

                //Enabled (JIRA comment - https://jira.issgroup.com.au/browse/BODCMS-1840?focusedCommentId=80527&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-80527)
                apv.Enabled = oldAlarm.Detection;

                //Priority
                //step 1
                EngParameter matchedEngParam;
                if (MatchEngParamFailed(old, oldAlarm, out matchedEngParam))
                {
                    apv.PriorityId = null;
                }
                else
                {
                    //step 2
                    AlarmTable matchedAlarmTable;
                    if (MatchAlarmTableRecordFailed(old, oldAlarm, matchedEngParam, out matchedAlarmTable))
                    {
                        apv.PriorityId = null;
                    }
                    else
                    {
                        //step 3
                        if (matchedAlarmTable == null)
                        {
                            apv.PriorityId = null;
                        }
                        else
                        {
                            ControlSystemAlarmPriority matchedPriority;
                            if (MatchPriorityNameFailed(newPriorityNames, matchedAlarmTable, oldAlarm, out matchedPriority))
                            {
                                apv.PriorityId = null;
                            }

                            if (matchedPriority != null)
                            {
                                apv.PriorityId = matchedPriority.Id;
                            }
                        }
                    }
                }

                apv.ActivationExpr = oldAlarm.ActivationExpr;
                apv.AlarmCalcExpr = oldAlarm.AlarmCalcExpr;

                apv.AlarmCalcExprEnabled = oldAlarm.Calc;
                apv.ControlSystemAlarmPropertyId = matchedAlarmProperty.Id;

                apv.ControlSystemComponentId = matchedNewCmsComponent.Id;

                if (!string.IsNullOrEmpty(oldAlarm.Guidance))
                {
                    apv.Guidance = oldAlarm.Guidance.Trim();
                }

                if (!string.IsNullOrEmpty(oldAlarm.Notes))
                {
                    apv.Notes = oldAlarm.Notes.Trim();
                }

                apv.MaskingExpr = oldAlarm.MaskingCondition;

                //apv.Reportable = oldAlarm.Reportable; kim will do manually.
                apv.OnDelay = oldAlarm.OnDelay;
                apv.OffDelay = oldAlarm.OffDelay;

                if (matchConsequence != null)
                {
                    apv.ConsequenceId = matchConsequence.Id;
                }
                if (matchPurpose != null)
                {
                    apv.PurposeId = matchPurpose.Id;
                }
                if (matchResponse != null)
                {
                    apv.ResponseTimeId = matchResponse.Id;
                }

                cee.ControlSystemAlarmPropertyValues.Add(apv);
                index++;

                UpdateStatus(string.Format("Alarm PropertyValues: Mapped Alarm ID {0} ({1} of {2}).", oldAlarm.Id, index, oldAlarms.Count));

            }

            Logger.Out("Saving Alarm PropertyValues...");
            cee.SaveChanges();
            sw.Stop();
            Logger.Out(string.Format("Imported {0} out of {1} AlarmPropertyValues in {2} min, {3} sec. ", index, oldAlarms.Count, sw.Elapsed.Minutes, sw.Elapsed.Seconds));
            Logger.Out("");
            Logger.Out("");
        }
コード例 #6
0
            public ModifiedAlarmPropertyComparer(ControlSystemAlarmPropertyValue Original_In,
                ControlSystemAlarmPropertyValue Modified_In,
                List<ControlSystemAlarmPriority> priorities,
                List<ControlSystemAlarmPurpose> purposes,
                List<ControlSystemAlarmConsequence> consequences,
                List<ControlSystemAlarmResponse> responses,
                List<QuickUser> users)
            {
                mPriorities = priorities;
                mPurposes = purposes;
                mConsequences = consequences;
                mResponses = responses;
                mUsers = users;
                Original = Original_In;
                Modified = Modified_In;

                var result = BuildMessage();

                Result = result;
            }
コード例 #7
0
        private void SaveControlSystemAlarms(ControlSystem controlSystem)
        {
            using (var cee = new CmsEntities())
            {

                foreach (var component in controlSystem.ControlSystemComponents)
                {
                    List<int> ctapList = (from x in cee.ControlSystemComponentTypeAlarmProperties
                                          where x.ComponentTypeId == component.ControlSystemComponentTypeId
                                          select x.AlarmPropertyId).ToList();

                    var dbAlarmPropertyValues = (from x in cee.ControlSystemAlarmPropertyValues where x.ControlSystemComponentId == component.Id select x).ToList();

                    foreach (ControlSystemAlarmPropertyValue dbAlarmPropertyValue in dbAlarmPropertyValues)
                    {
                        cee.ControlSystemAlarmPropertyValues.Remove(dbAlarmPropertyValue);
                        cee.SaveChanges();
                    }

                    List<ControlSystemAlarmPropertyValue> newPVs = new List<ControlSystemAlarmPropertyValue>();

                    foreach (var pv in component.ControlSystemAlarmPropertyValues)
                    {
                        bool isInList = ctapList.IndexOf(pv.ControlSystemAlarmPropertyId) != -1;
                        if (!isInList) { continue; }//no business adding this...

                        //needed to new up to ensure decoupled.
                        ControlSystemAlarmPropertyValue insert = new ControlSystemAlarmPropertyValue
                        {
                            ActivationExpr = pv.ActivationExpr,
                            AlarmCalcExpr = pv.AlarmCalcExpr,
                            AlarmCalcExprEnabled = pv.AlarmCalcExprEnabled,
                            ColourId = pv.ColourId,
                            ConsequenceId = pv.ConsequenceId,
                            ControlSystemAlarmPropertyId = pv.ControlSystemAlarmPropertyId,
                            ControlSystemComponentId = component.Id,
                            Enabled = pv.Enabled,
                            Guidance = pv.Guidance,
                            MaskingExpr = pv.MaskingExpr,
                            Notes = pv.Notes,
                            OffDelay = pv.OffDelay,
                            OnDelay = pv.OnDelay,
                            PriorityId = pv.PriorityId,
                            PurposeId = pv.PurposeId,
                            Reportable = pv.Reportable,
                            ReportableSetById = pv.ReportableSetById,
                            ReportableSetDate = pv.ReportableSetDate,
                            ResponseTimeId = pv.ResponseTimeId,
                            ReviewedCompletedById = pv.ReviewedCompletedById,
                            ReviewCompleted = pv.ReviewCompleted,
                            ReviewedCompletedDate = pv.ReviewedCompletedDate,
                            Tested = pv.Tested,
                            TestedDate = pv.TestedDate,
                            TestedUserId = pv.TestedUserId,
                            ModifiedDate = pv.ModifiedDate,
                            ModifiedUserId = pv.ModifiedUserId
                        };

                        cee.ControlSystemAlarmPropertyValues.Add(insert);
                    }
                }
                cee.SaveChanges();
            }
        }
コード例 #8
0
        private void BuildAlarmRevisionHistory(int controlSystemId, int userId, List<ControlSystemComponent> controlSystemComponents, CmsEntities cee)
        {
            var modifiedList = new List<ControlSystemAlarmPropertyValue>();

            foreach (var component in controlSystemComponents)
            {
                if (component.ControlSystemAlarmPropertyValues != null && component.ControlSystemAlarmPropertyValues.Any())
                {
                    modifiedList.AddRange(component.ControlSystemAlarmPropertyValues);
                }
            }

            if (!modifiedList.Any()) { return; }

            var idList = (from x in modifiedList select x.Id).ToArray();
            var dbMatches = (from x in cee.ControlSystemAlarmPropertyValues where idList.Contains(x.Id) select x).ToList();

            var purposes = (from x in cee.ControlSystemAlarmPurposes select x).ToList();
            var consequences = (from x in cee.ControlSystemAlarmConsequences select x).ToList();
            var responses = (from x in cee.ControlSystemAlarmResponses select x).ToList();
            var priorities = (from x in cee.ControlSystemAlarmPriorities select x).ToList();
            var users = GetQuickUsersInternal(true, cee);

            var messages = new List<string>();

            foreach (var pv in modifiedList)
            {
                ControlSystemAlarmPropertyValue db;
                if (pv.Id != 0)
                {
                    db = (from x in dbMatches where x.Id == pv.Id select x).FirstOrDefault();
                }
                else
                {
                    db = new ControlSystemAlarmPropertyValue();
                }

                if (db != null)
                {
                    var propertyComparer = new ModifiedAlarmPropertyComparer(db, pv, priorities, purposes, consequences, responses, users);

                    if (!string.IsNullOrEmpty(propertyComparer.Result))
                    {
                        var heading = string.Format("[Component: {0}, Alarm: {1}] ", pv.ControlSystemComponent.Name, pv.ControlSystemAlarmProperty.Name);

                        messages.Add(heading);
                        messages.Add(propertyComparer.Result.TrimEnd(Environment.NewLine.ToCharArray()));
                    }
                }
            }

            var rh = new ControlSystemRevisionHistory();

            if (messages.Any())
            {
                var joined = string.Join(Environment.NewLine, messages);

                rh.Description = joined;
                rh.ControlSystemId = controlSystemId;
                rh.Date = DateTime.Now;
                rh.UserId = userId;
                rh.IsSystemMessage = true;

                var latestPrh = (from x in cee.ControlSystemRevisionHistories
                                 where x.ControlSystemId == controlSystemId
                                 select x.Revision).ToList();

                if (latestPrh.Count > 0)
                {
                    rh.Revision = latestPrh.AsQueryable().Max() + VERSIONINCREMENT;
                }
                else
                {
                    rh.Revision = VERSIONINCREMENT;
                }

                cee.ControlSystemRevisionHistories.Add(rh);
            }
        }
コード例 #9
0
        public List<ControlSystemAlarmPropertyValue> GetAlarmPropertyValuesRequiredForComponentType(int controlSystemComponentTypeId)
        {
            List<ControlSystemAlarmPropertyValue> result = new List<ControlSystemAlarmPropertyValue>();

            using (var cee = new CmsEntities())
            {

                List<ControlSystemComponentTypeAlarmProperty> properties =
                    (from x in cee.ControlSystemComponentTypeAlarmProperties
                         .Include("ControlSystemAlarmProperty")
                         .Include("ControlSystemAlarmProperty.ControlSystemUserInterfacePlatform")
                     where x.ComponentTypeId == controlSystemComponentTypeId
                     select x).ToList();

                foreach (ControlSystemComponentTypeAlarmProperty property in properties)
                {
                    ControlSystemAlarmPropertyValue pv = new ControlSystemAlarmPropertyValue
                    {
                        ControlSystemAlarmPropertyId = property.AlarmPropertyId,
                        ControlSystemAlarmProperty = property.ControlSystemAlarmProperty,
                        Enabled = false,
                        Reportable = false
                    };
                    result.Add(pv);
                }
                return result;
            }
        }