Example #1
0
 public IEnumerable <DatabaseObject> GetEffectiveNestingChildren(DatabaseObjectType type, bool directChildrenOnly)
 {
     if (directChildrenOnly)
     {
         foreach (DatabaseObject item in publicGetEffectiveNestingChildren(new StringBin(), type))
         {
             if (type == null || item.Type == type)
             {
                 yield return(item);
             }
         }
     }
     else
     {
         foreach (DatabaseObject databaseObject in GetEffectiveNestingChildren(null, directChildrenOnly: true))
         {
             if (type == null || databaseObject.Type == type)
             {
                 yield return(databaseObject);
             }
             foreach (DatabaseObject effectiveNestingChild in databaseObject.GetEffectiveNestingChildren(type, directChildrenOnly: false))
             {
                 yield return(effectiveNestingChild);
             }
         }
     }
 }
Example #2
0
 public DatabaseObject(DatabaseObjectType databaseObjectType, Guid guid, string name, object value)
 {
     if (!databaseObjectType.IsInitialized)
     {
         throw new InvalidOperationException($"InitializeRelations of DatabaseObjectType \"{databaseObjectType.Name}\" not called.");
     }
     m_databaseObjectType = databaseObjectType;
     m_guid = guid;
     Name   = name;
     if (value != null)
     {
         Value = value;
     }
 }
Example #3
0
 public DatabaseObject FindEffectiveNestedChild(string name, DatabaseObjectType type, bool directChildrenOnly, bool throwIfNotFound)
 {
     foreach (DatabaseObject effectiveNestingChild in GetEffectiveNestingChildren(type, directChildrenOnly))
     {
         if (effectiveNestingChild.Name == name)
         {
             return(effectiveNestingChild);
         }
     }
     if (throwIfNotFound)
     {
         throw new InvalidOperationException($"Required database object \"{name}\" not found in database object \"{Name}\"");
     }
     return(null);
 }
Example #4
0
 public DatabaseObject FindDatabaseObject(Guid guid, DatabaseObjectType type, bool throwIfNotFound)
 {
     m_databaseObjectsByGuid.TryGetValue(guid, out DatabaseObject value);
     if (value != null)
     {
         if (type != null && value.Type != type)
         {
             throw new InvalidOperationException($"Database object {guid} has invalid type. Expected {type.Name}, found {value.Type.Name}.");
         }
     }
     else if (throwIfNotFound)
     {
         throw new InvalidOperationException($"Required database object {guid} not found.");
     }
     return(value);
 }
Example #5
0
 public IEnumerable <DatabaseObject> GetExplicitNestingChildren(DatabaseObjectType type, bool directChildrenOnly)
 {
     foreach (DatabaseObject databaseObject in publicNestingChildren)
     {
         if (type == null || databaseObject.Type == type)
         {
             yield return(databaseObject);
         }
         if (!directChildrenOnly)
         {
             foreach (DatabaseObject explicitNestingChild in databaseObject.GetExplicitNestingChildren(type, directChildrenOnly: false))
             {
                 yield return(explicitNestingChild);
             }
         }
     }
 }
 public void InitializeRelations(IEnumerable <DatabaseObjectType> allowedNestingParents, IEnumerable <DatabaseObjectType> allowedInheritanceParents, DatabaseObjectType nestedValueType)
 {
     if (IsInitialized)
     {
         throw new InvalidOperationException("InitializeRelations of this DatabaseObjectType was already called.");
     }
     m_allowedNestingParents     = ((allowedNestingParents != null) ? allowedNestingParents.Distinct().ToList() : new List <DatabaseObjectType>(0));
     m_allowedInheritanceParents = ((allowedInheritanceParents != null) ? allowedInheritanceParents.Distinct().ToList() : new List <DatabaseObjectType>(0));
     m_nestedValueType           = nestedValueType;
     foreach (DatabaseObjectType allowedNestingParent in m_allowedNestingParents)
     {
         allowedNestingParent.m_allowedNestingChildren.Add(this);
     }
     foreach (DatabaseObjectType allowedInheritanceParent in allowedInheritanceParents)
     {
         allowedInheritanceParent.m_allowedInheritanceChildren.Add(this);
     }
 }
Example #7
0
        private static DatabaseObject publicLoadDatabaseObject(XElement node, Database database, Dictionary <DatabaseObject, Guid> nestingParents, Dictionary <DatabaseObject, Guid> inheritanceParents, Dictionary <Guid, Guid> guidTranslation)
        {
            Guid   guid            = XmlUtils.GetAttributeValue(node, "Guid", Guid.Empty);
            string attributeValue  = XmlUtils.GetAttributeValue(node, "Name", string.Empty);
            string attributeValue2 = XmlUtils.GetAttributeValue(node, "Description", string.Empty);
            Guid   attributeValue3 = XmlUtils.GetAttributeValue(node, "NestingParent", Guid.Empty);
            Guid   attributeValue4 = XmlUtils.GetAttributeValue(node, "InheritanceParent", Guid.Empty);
            string attributeValue5 = XmlUtils.GetAttributeValue(node, "Type", string.Empty);

            if (guid == Guid.Empty)
            {
                guid = Guid.NewGuid();
            }
            if (guidTranslation != null)
            {
                Guid guid2 = Guid.NewGuid();
                guidTranslation.Add(guid, guid2);
                guid = guid2;
            }
            DatabaseObjectType databaseObjectType = database.FindDatabaseObjectType(node.Name.ToString(), throwIfNotFound: true);
            object             value = null;

            if (!string.IsNullOrEmpty(attributeValue5))
            {
                Type type = TypeCache.FindType(attributeValue5, skipSystemAssemblies: false, throwIfNotFound: true);
                value = XmlUtils.GetAttributeValue(node, "Value", type);
            }
            DatabaseObject databaseObject = new DatabaseObject(databaseObjectType, guid, attributeValue, value);

            databaseObject.Description = attributeValue2;
            if (nestingParents != null && attributeValue3 != Guid.Empty)
            {
                nestingParents.Add(databaseObject, attributeValue3);
            }
            if (inheritanceParents != null && attributeValue4 != Guid.Empty)
            {
                inheritanceParents.Add(databaseObject, attributeValue4);
            }
            foreach (DatabaseObject item in publicLoadDatabaseObjectsList(node, database, nestingParents, inheritanceParents, guidTranslation))
            {
                item.NestingParent = databaseObject;
            }
            return(databaseObject);
        }
Example #8
0
        public static Database LoadDatabase(XElement node)
        {
            Dictionary <string, DatabaseObjectType> dictionary = new Dictionary <string, DatabaseObjectType>();
            XElement xElement = XmlUtils.FindChildElement(node, "DatabaseObjectTypes", throwIfNotFound: true);

            foreach (XElement item in xElement.Elements())
            {
                string             attributeValue  = XmlUtils.GetAttributeValue <string>(item, "Name");
                string             attributeValue2 = XmlUtils.GetAttributeValue <string>(item, "DefaultInstanceName");
                string             attributeValue3 = XmlUtils.GetAttributeValue <string>(item, "IconName");
                int                attributeValue4 = XmlUtils.GetAttributeValue <int>(item, "Order");
                bool               attributeValue5 = XmlUtils.GetAttributeValue <bool>(item, "SupportsValue");
                bool               attributeValue6 = XmlUtils.GetAttributeValue <bool>(item, "MustInherit");
                int                attributeValue7 = XmlUtils.GetAttributeValue <int>(item, "NameLengthLimit");
                bool               attributeValue8 = XmlUtils.GetAttributeValue <bool>(item, "SaveStandalone");
                DatabaseObjectType value           = new DatabaseObjectType(attributeValue, attributeValue2, attributeValue3, attributeValue4, attributeValue5, attributeValue6, attributeValue7, attributeValue8);
                dictionary.Add(attributeValue, value);
            }
            foreach (XElement item2 in xElement.Elements())
            {
                string attributeValue9         = XmlUtils.GetAttributeValue <string>(item2, "Name");
                string attributeValue10        = XmlUtils.GetAttributeValue <string>(item2, "AllowedNestingParents");
                string attributeValue11        = XmlUtils.GetAttributeValue <string>(item2, "AllowedInheritanceParents");
                string attributeValue12        = XmlUtils.GetAttributeValue <string>(item2, "NestedValueType");
                List <DatabaseObjectType> list = new List <DatabaseObjectType>();
                string[] array = attributeValue10.Split(new char[2]
                {
                    ',',
                    ' '
                }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string text in array)
                {
                    if (!dictionary.TryGetValue(text, out DatabaseObjectType value2))
                    {
                        throw new InvalidOperationException($"Database object type \"{text}\" not found.");
                    }
                    list.Add(value2);
                }
                List <DatabaseObjectType> list2 = new List <DatabaseObjectType>();
                array = attributeValue11.Split(new char[2]
                {
                    ',',
                    ' '
                }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string text2 in array)
                {
                    if (!dictionary.TryGetValue(text2, out DatabaseObjectType value3))
                    {
                        throw new InvalidOperationException($"Database object type \"{text2}\" not found.");
                    }
                    list2.Add(value3);
                }
                DatabaseObjectType value4 = null;
                if (!string.IsNullOrEmpty(attributeValue12) && !dictionary.TryGetValue(attributeValue12, out value4))
                {
                    throw new InvalidOperationException($"Database object type \"{attributeValue12}\" not found.");
                }
                dictionary[attributeValue9].InitializeRelations(list, list2, value4);
            }
            foreach (XElement item3 in XmlUtils.FindChildElement(node, "Assemblies", throwIfNotFound: true).Elements())
            {
                Assembly.Load(new AssemblyName(XmlUtils.GetAttributeValue <string>(item3, "Name")));
            }
            XElement node2    = XmlUtils.FindChildElement(node, "DatabaseObjects", throwIfNotFound: true);
            Database database = new Database(new DatabaseObject(guid: XmlUtils.GetAttributeValue <Guid>(node2, "RootGuid"), databaseObjectType: dictionary["Root"], name: "Root", value: null), dictionary.Values);

            foreach (DatabaseObject item4 in LoadDatabaseObjectsList(node2, database))
            {
                item4.NestingParent = database.Root;
            }
            return(database);
        }
Example #9
0
 public DatabaseObject FindDatabaseObject(string name, DatabaseObjectType type, bool throwIfNotFound)
 {
     return(Root.FindExplicitNestedChild(name, type, directChildrenOnly: false, throwIfNotFound));
 }
Example #10
0
 private IEnumerable <DatabaseObject> publicGetEffectiveNestingChildren(StringBin names, DatabaseObjectType type)
 {
     if (Type.AllowedNestingChildren.Count != 0)
     {
         foreach (DatabaseObject explicitNestingChild in GetExplicitNestingChildren(type, directChildrenOnly: true))
         {
             if (!names.Contains(explicitNestingChild.Name))
             {
                 names.Add(explicitNestingChild.Name);
                 yield return(explicitNestingChild);
             }
         }
         DatabaseObject effectiveInheritanceParent = EffectiveInheritanceParent;
         if (effectiveInheritanceParent != null)
         {
             foreach (DatabaseObject item in effectiveInheritanceParent.publicGetEffectiveNestingChildren(names, type))
             {
                 yield return(item);
             }
         }
     }
 }
Example #11
0
 public DatabaseObject(DatabaseObjectType databaseObjectType, string name)
     : this(databaseObjectType, Guid.NewGuid(), name, null)
 {
 }
Example #12
0
 public DatabaseObject(DatabaseObjectType databaseObjectType, string name, object value)
     : this(databaseObjectType, Guid.NewGuid(), name, value)
 {
 }