コード例 #1
0
        private void syncSubScope(TemplateSynchronizer <TECSubScope> synchronizer,
                                  TECSubScope template, TECSubScope changed, TECChangedEventArgs args)
        {
            if (changed != template)
            {
                syncItem(changed, template);
            }
            foreach (TECSubScope item in synchronizer.GetFullDictionary()[template].Where(item => item != changed))
            {
                syncItem(changed, item);
            }

            void syncItem(TECSubScope changedItem, TECSubScope subject)
            {
                subject.CopyChildrenFromScope(changedItem);

                subject.Points.ObservablyClear();
                subject.Devices.ObservablyClear();
                subject.Interlocks.ObservablyClear();

                foreach (TECPoint point in changedItem.Points)
                {
                    subject.AddPoint(new TECPoint(point));
                }
                foreach (IEndDevice device in changedItem.Devices)
                {
                    subject.AddDevice(device);
                }
                foreach (TECInterlockConnection connection in changedItem.Interlocks)
                {
                    subject.Interlocks.Add(connection);
                }
            }
        }
コード例 #2
0
        protected void notifyTECChanged(Change change, string propertyName, ITECObject sender,
                                        object value, object oldValue = null)
        {
            TECChangedEventArgs args = new TECChangedEventArgs(change, propertyName, sender, value, oldValue);

            TECChanged?.Invoke(args);
        }
コード例 #3
0
 private void scopeChanged(TECChangedEventArgs obj)
 {
     if (obj.PropertyName == "ScopeBranches")
     {
         raisePropertyChanged("Branches");
     }
 }
コード例 #4
0
        private void handleThisChanged(TECChangedEventArgs args)
        {
            if (Instances.Count > 0 && args.Value?.GetType() != typeof(TECSystem))
            {
                if (args.Change == Change.Add)
                {
                    handleAdd(args);
                    return;
                }
                else if (args.Change == Change.Remove)
                {
                    handleRemove(args);
                    return;
                }
                else if (args.Sender is TECController controller)
                {
                    handleControllerChanged(controller, args.PropertyName);
                }
                else if (args.Sender is TECPoint || args.Sender is TECMisc)
                {
                    handleValueChanged(args.Sender, args.PropertyName);
                    return;
                }

                if (IsSingleton)
                {
                    handleValueChanged(args.Sender, args.PropertyName);
                }
            }
        }
コード例 #5
0
        private void handleAdd(TECChangedEventArgs args)
        {
            ITypicalable      sender          = args.Sender as ITypicalable;
            List <ITECObject> parentInstances = new List <ITECObject>();

            if (args.Sender is TECTypical typ)
            {
                parentInstances.AddRange(Instances);
            }
            else
            {
                parentInstances = TypicalInstanceDictionary.GetInstances(sender as ITECObject);
            }
            foreach (ITECObject parentInstance in parentInstances)
            {
                ITypicalable instanceSender = parentInstance as ITypicalable;

                if (instanceSender == null)
                {
                    throw new Exception("Change occured from object which is not typicalable");
                }
                ITECObject instanceValue = args.Value as ITECObject;
                if (instanceValue == null)
                {
                    throw new Exception("Value to add is not ITECObject");
                }
                if (args.Value is ITypicalable typicalChild)
                {
                    if (sender is IRelatable relSender && relSender.IsDirectChildProperty(args.PropertyName))
                    {
                        instanceValue = typicalChild.CreateInstance(TypicalInstanceDictionary);
                        if (instanceValue != null)
                        {
                            TypicalInstanceDictionary.AddItem(args.Value as ITECObject, instanceValue);
                        }
                    }
                    else
                    {
                        var parentSystem = this.Instances
                                           .Where(x => x.IsDirectDescendant(parentInstance))
                                           .FirstOrDefault();

                        instanceValue = this.TypicalInstanceDictionary.GetInstances(typicalChild)
                                        .Where(x => parentSystem.IsDirectDescendant(x)).FirstOrDefault();
                    }
                }
                if (instanceValue != null)
                {
                    instanceSender.AddChildForProperty(args.PropertyName, instanceValue);
                }
            }
コード例 #6
0
 private void synchronizerChanged(TECChangedEventArgs obj)
 {
     notifyTECChanged(obj.Change, obj.PropertyName, obj.Sender, obj.Value);
 }
コード例 #7
0
        private void syncEquipment(TemplateSynchronizer <TECEquipment> synchronizer, TECEquipment template, TECEquipment changed, TECChangedEventArgs args)
        {
            if (!(args.Sender is TECEquipment))
            {
                return;
            }
            TECEquipment        item       = args.Sender as TECEquipment;
            TECSubScope         value      = args.Value as TECSubScope;
            List <TECEquipment> references = synchronizer.GetFullDictionary()[template];

            if (value != null && args.Change == Change.Add)
            {
                TECSubScope newTemplate = value;
                if (item == template)
                {
                    SubScopeSynchronizer.NewGroup(newTemplate);
                }
                else
                {
                    TECSubScope parentTemplate = SubScopeSynchronizer.GetTemplate(newTemplate);
                    if (parentTemplate != null)
                    {
                        SubScopeSynchronizer.RemoveItem(newTemplate);
                        newTemplate = SubScopeSynchronizer.NewItem(parentTemplate);
                    }
                    else
                    {
                        newTemplate = new TECSubScope(value);
                    }
                    template.SubScope.Add(newTemplate);
                    SubScopeSynchronizer.NewGroup(newTemplate);
                    SubScopeSynchronizer.LinkExisting(newTemplate, value);
                }
                foreach (TECEquipment reference in references.Where(obj => obj != item))
                {
                    reference.SubScope.Add(SubScopeSynchronizer.NewItem(newTemplate));
                }
            }
            else if (value != null && args.Change == Change.Remove)
            {
                TECSubScope subScopeTemplate = value;
                if (item != template)
                {
                    subScopeTemplate = SubScopeSynchronizer.GetTemplate(value);
                }
                template.SubScope.Remove(subScopeTemplate);
                List <TECSubScope> subScopeReferences = SubScopeSynchronizer.GetFullDictionary()[subScopeTemplate];
                foreach (TECEquipment reference in references)
                {
                    List <TECSubScope> toRemove = new List <TECSubScope>();
                    foreach (TECSubScope referenceSubScope in reference.SubScope)
                    {
                        if (subScopeReferences.Contains(referenceSubScope))
                        {
                            toRemove.Add(referenceSubScope);
                        }
                    }
                    foreach (TECSubScope thing in toRemove)
                    {
                        reference.SubScope.Remove(thing);
                    }
                }
                SubScopeSynchronizer.RemoveGroup(subScopeTemplate);
                if (SubScopeSynchronizer.GetTemplate(subScopeTemplate) != null)
                {
                    SubScopeSynchronizer.RemoveItem(subScopeTemplate);
                }
            }
            else
            {
                if (item != template)
                {
                    template.CopyChildrenFromScope(item);
                }
                foreach (TECEquipment reference in references.Where(obj => obj != item))
                {
                    reference.CopyChildrenFromScope(item);
                }
            }
        }