private static List <UpdateItem> editStack(ITECObject sender, string propertyName,
                                                   object value, object oldValue, DBType type)
        {
            List <UpdateItem> outStack = new List <UpdateItem>();

            if (value is IList listValue && oldValue is IList)
            {
                if (listValue.Count == 0)
                {
                    return(new List <UpdateItem>());
                }
                var tables = DatabaseHelper.GetTables(new List <ITECObject>()
                {
                    sender, listValue[0] as ITECObject
                }, propertyName, type);
                foreach (var table in tables.Where(x => x.IndexString != ""))
                {
                    List <(Dictionary <string, string> data, Tuple <string, string> keyData)> dataList = DatabaseHelper.PrepareIndexData(sender, propertyName, table, type);
                    foreach (var item in dataList)
                    {
                        outStack.Add(new UpdateItem(Change.Edit, table.NameString, item.data, item.keyData));
                    }
                }
                return(outStack);
            }
Esempio n. 2
0
 bool ITypicalable.ContainsChildForProperty(string property, ITECObject item)
 {
     if (property == "Controllers" && item is TECController controller)
     {
         return(Controllers.Contains(controller));
     }
     else if (property == "Equipment" && item is TECEquipment equipment)
     {
         return(Equipment.Contains(equipment));
     }
     else if (property == "Panels" && item is TECPanel panel)
     {
         return(Panels.Contains(panel));
     }
     else if (property == "MiscCosts" && item is TECMisc misc)
     {
         return(MiscCosts.Contains(misc));
     }
     else if (property == "ScopeBranch" && item is TECScopeBranch branch)
     {
         return(ScopeBranches.Contains(branch));
     }
     else if (property == "ProposalItems" && item is TECProposalItem propItem)
     {
         return(ProposalItems.Contains(propItem));
     }
     else
     {
         return(this.ContainsChildForScopeProperty(property, item));
     }
 }
Esempio n. 3
0
 void ITypicalable.AddChildForProperty(string property, ITECObject item)
 {
     if (property == "Controllers" && item is TECController controller)
     {
         AddController(controller);
     }
     else if (property == "Equipment" && item is TECEquipment equipment)
     {
         Equipment.Add(equipment);
     }
     else if (property == "Panels" && item is TECPanel panel)
     {
         Panels.Add(panel);
     }
     else if (property == "MiscCosts" && item is TECMisc misc)
     {
         MiscCosts.Add(misc);
     }
     else if (property == "ScopeBranches" && item is TECScopeBranch branch)
     {
         ScopeBranches.Add(branch);
     }
     else if (property == "ProposalItems" && item is TECProposalItem propItem)
     {
         ProposalItems.Add(propItem);
     }
     else
     {
         this.AddChildForScopeProperty(property, item);
     }
 }
Esempio n. 4
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);
        }
Esempio n. 5
0
 private void register(ITECObject item)
 {
     registerTECObject(item);
     if (item is IRelatable saveable)
     {
         saveable.GetDirectChildren().ForEach(register);
     }
 }
        public static List <ITECObject> GetObjectPath(this IRelatable parent, ITECObject descendant)
        {
            List <ITECObject> path = new List <ITECObject>();

            getObjectPath(parent, descendant, path);
            path.Reverse();
            return(path);
        }
 private void raiseTypicalConstituents(Change change, ITECObject item)
 {
     TypicalConstituentChanged?.Invoke(change, item);
     if (item is IRelatable parent)
     {
         parent.GetDirectChildren().Where(x => x is ITypicalable typ && typ.IsTypical).
         ForEach(child => raiseTypicalConstituents(change, child));
     }
 }
 public TECChangedEventArgs(Change change, string propertyName, ITECObject sender,
                            object value, object oldValue)
     : base(propertyName)
 {
     Change   = change;
     Sender   = sender;
     Value    = value;
     OldValue = oldValue;
 }
 void ITypicalable.AddChildForProperty(string property, ITECObject item)
 {
     if (property == "Children" && item is IConnectable child)
     {
     }
     else
     {
         throw new Exception(String.Format("There is no compatible add method for the property {0} with an object of type {1}", property, item.GetType().ToString()));
     }
 }
        private static bool matchesObjectType(ITECObject item, List <Type> tableTypes)
        {
            if (tableTypes.Count != 1)
            {
                return(false);
            }
            Type tableType = tableTypes[0];

            return(item.GetType() == tableType || item.GetType().BaseType == tableType);
        }
 bool ITypicalable.ContainsChildForProperty(string property, ITECObject item)
 {
     if (property == "SubScope" && item is TECSubScope subScope)
     {
         return(this.SubScope.Contains(subScope));
     }
     else
     {
         return(this.ContainsChildForScopeProperty(property, item));
     }
 }
 void ITypicalable.AddChildForProperty(string property, ITECObject item)
 {
     if (property == "SubScope" && item is TECSubScope subScope)
     {
         this.SubScope.Add(subScope);
     }
     else
     {
         this.AddChildForScopeProperty(property, item);
     }
 }
Esempio n. 13
0
        private void repopulateGroups(ITECObject parent, ITECObject item, Action <FilteredConnectablesGroup,
                                                                                  IConnectable, IEnumerable <ITECObject> > action, List <ITECObject> parentPath = null)
        {
            parentPath = parentPath ?? new List <ITECObject>();
            if (parent != null)
            {
                parentPath.Add(parent);
            }
            if (item is IConnectable connectable)
            {
                parentPath.Add(item);
                execute(this.rootConnectableGroup);
                if (connectable is TECController)
                {
                    execute(this.rootControllerGroup);
                }

                void execute(FilteredConnectablesGroup relevantRoot)
                {
                    var closestRoot = relevantRoot;
                    var thisPath    = new List <ITECObject>();

                    thisPath.Add(connectable);
                    var start    = item;
                    var toRemove = new List <ITECObject>();

                    for (int x = parentPath.Count - 2; x >= 0; x--)
                    {
                        if (parentPath.Count == 0 || x < 0)
                        {
                            logger.Error("Connectable path had some issue getting the path to {0} from {1}", item, parent);
                            return;
                        }
                        if (!thisPath.Contains(parentPath[x]) && (parentPath[x] as IRelatable).GetDirectChildren().Contains(start))
                        {
                            thisPath.Insert(0, parentPath[x]);
                            start = parentPath[x];
                            if (relevantRoot.GetGroup(parentPath[x] as ITECScope) != null && closestRoot == relevantRoot)
                            {
                                closestRoot = relevantRoot.GetGroup(parentPath[x] as ITECScope);
                            }
                        }
                    }
                    action(closestRoot, connectable, thisPath);
                }
            }
            else if (item is IRelatable relatable)
            {
                foreach (ITECObject child in relatable.GetDirectChildren().Where(filterPredicate))
                {
                    repopulateGroups(item, child, action, parentPath);
                }
            }
        }
 private void raiseConstituents(Change change, ITECObject item)
 {
     InstanceConstituentChanged?.Invoke(change, item);
     if (item is IRelatable parent)
     {
         foreach (var child in parent.GetDirectChildren())
         {
             raiseConstituents(change, child);
         }
     }
 }
 bool ITypicalable.ContainsChildForProperty(string property, ITECObject item)
 {
     if (property == "Children" && item is IConnectable child)
     {
         return(Children.Contains(child));
     }
     else
     {
         throw new Exception(String.Format("There is no compatible property {0} with an object of type {1}", property, item.GetType().ToString()));
     }
 }
Esempio n. 16
0
 void ITypicalable.AddChildForProperty(string property, ITECObject item)
 {
     if (property == "Controllers" && item is TECController controller)
     {
         Controllers.Add(controller);
     }
     else
     {
         this.AddChildForScopeProperty(property, item);
     }
 }
Esempio n. 17
0
 bool ITypicalable.ContainsChildForProperty(string property, ITECObject item)
 {
     if (property == "Controllers" && item is TECController controller)
     {
         return(Controllers.Contains(controller));
     }
     else
     {
         return(this.ContainsChildForScopeProperty(property, item));
     }
 }
Esempio n. 18
0
 /// <summary>
 /// Generically references scope to instances of scope into a dictionary from a guid, guids dictionary
 /// </summary>
 /// <param name="characteristic"></param>
 /// <param name="instances"></param>
 /// <param name="referenceDict"></param>
 /// <param name="characteristicList"></param>
 private static void linkCharacteristicWithInstances(ITECObject characteristic, IList instances,
                                                     Dictionary <Guid, List <Guid> > referenceDict,
                                                     ObservableListDictionary <ITECObject> characteristicList)
 {
     foreach (ITECObject item in instances)
     {
         if (referenceDict[characteristic.Guid].Contains(item.Guid))
         {
             characteristicList.AddItem(characteristic, item);
         }
     }
 }
Esempio n. 19
0
 private void registerTECObject(ITECObject ob)
 {
     ob.TECChanged      += handleTECChanged;
     ob.PropertyChanged += raisePropertyChanged;
     if (ob is INotifyCostChanged costOb)
     {
         costOb.CostChanged += (e) => raiseCostChanged(ob, e);
     }
     if (ob is INotifyPointChanged pointOb)
     {
         pointOb.PointChanged += (e) => raisePointChanged(ob, e);
     }
 }
Esempio n. 20
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);
                }
            }
 protected override void addChildForProperty(string property, ITECObject item)
 {
     if (property == "ChildrenConnections")
     {
     }
     else if (property == "Points" && item is TECPoint point)
     {
         this.Points.Add(point);
     }
     else
     {
         this.AddChildForScopeProperty(property, item);
     }
 }
Esempio n. 22
0
 private void addToDictionary(string name, ITECObject item)
 {
     if (!nameDictionary.ContainsKey(name))
     {
         nameDictionary[name] = new List <ITECObject>()
         {
             item
         };
     }
     else
     {
         nameDictionary[name].Add(item);
     }
 }
Esempio n. 23
0
        /// <summary>
        /// Returns all connectable objects which are direct descendants of the provided parent and match the provided predicate
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="predicate"></param>
        /// <returns></returns>
        public static List <IConnectable> GetConnectables(ITECObject parent, Func <ITECObject, bool> predicate)
        {
            List <IConnectable> outList = new List <IConnectable>();

            if (parent is IConnectable connectable && predicate(parent))
            {
                outList.Add(connectable);
            }
            if (parent is IRelatable relatable)
            {
                relatable.GetDirectChildren().ForEach(x => outList.AddRange(GetConnectables(x, predicate)));
            }
            return(outList);
        }
Esempio n. 24
0
 public static void AddChildForScopeProperty <T>(this T typ, String property, ITECObject item) where T : TECScope, ITypicalable
 {
     if (property == "AssociatedCosts" && item is TECAssociatedCost cost)
     {
         typ.AssociatedCosts.Add(cost);
     }
     else if (property == "Tags" && item is TECTag tag)
     {
         typ.Tags.Add(tag);
     }
     else
     {
         throw new Exception(String.Format("There is no compatible add method for the property {0} with an object of type {1}", property, item.GetType().ToString()));
     }
 }
        public static string ToTECTypeString(this ITECObject obj)
        {
            var dict = stringDictionary;

            Type objType = obj.GetType();

            if (dict.ContainsKey(objType))
            {
                return(dict[objType]);
            }
            else
            {
                return("");
            }
        }
 protected override bool containsChildForProperty(string property, ITECObject item)
 {
     if (property == "ChildrenConnections")
     {
         return(true);
     }
     else if (property == "IOModules" && item is TECIOModule module)
     {
         return(this.IOModules.Contains(module));
     }
     else
     {
         return(this.ContainsChildForScopeProperty(property, item));
     }
 }
 protected override bool containsChildForProperty(string property, ITECObject item)
 {
     if (property == "ChildrenConnections")
     {
         return(true);
     }
     else if (property == "Points" && item is TECPoint point)
     {
         return(this.Points.Contains(point));
     }
     else
     {
         return(this.ContainsChildForScopeProperty(property, item));
     }
 }
 protected override void addChildForProperty(string property, ITECObject item)
 {
     if (property == "ChildrenConnections")
     {
     }
     else if (property == "IOModules" && item is TECIOModule module)
     {
         if (this.CanAddModule(module))
         {
             this.AddModule(module);
         }
     }
     else
     {
         this.AddChildForScopeProperty(property, item);
     }
 }
        public static Tuple <string, string> PrimaryKeyData(TableBase table, ITECObject item)
        {
            if (table.PrimaryKeys.Count != 1)
            {
                throw new Exception("Must have one primary key in table being updated.");
            }
            TableField field = table.PrimaryKeys[0];

            if (field.Property.DeclaringType.IsInstanceOfType(item))
            {
                Tuple <string, string> outData = new Tuple <string, string>(field.Name, objectToDBString(item.Guid));
                return(outData);
            }
            else
            {
                throw new Exception("Item does not match type of key.");
            }
        }
 protected override bool removeChildForProperty(string property, ITECObject item)
 {
     if (property == "ChildrenConnections")
     {
         return(true);
     }
     else if (property == "IOModules" && item is TECIOModule module)
     {
         if (this.CanRemoveModule(module))
         {
             return(this.IOModules.Remove(module));
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(this.RemoveChildForScopeProperty(property, item));
     }
 }