Beispiel #1
0
 public void AddDatabaseObject(DatabaseObject databaseObject, bool checkThatGuidsAreUnique)
 {
     if (databaseObject.m_database != null)
     {
         throw new InvalidOperationException("public error: database object is already in a database.");
     }
     if (!m_databaseObjectTypes.Contains(databaseObject.Type))
     {
         throw new InvalidOperationException($"Database object type \"{databaseObject.Type.Name}\" is not supported by the database.");
     }
     if (checkThatGuidsAreUnique)
     {
         if (databaseObject.Guid != Guid.Empty && m_databaseObjectsByGuid.ContainsKey(databaseObject.Guid))
         {
             throw new InvalidOperationException($"Database object {databaseObject.Guid} is already present in the database.");
         }
         foreach (DatabaseObject explicitNestingChild in databaseObject.GetExplicitNestingChildren(null, directChildrenOnly: false))
         {
             if (explicitNestingChild.Guid != Guid.Empty && m_databaseObjectsByGuid.ContainsKey(explicitNestingChild.Guid))
             {
                 throw new InvalidOperationException($"Database object {explicitNestingChild.Guid} is already present in the database.");
             }
         }
     }
     databaseObject.m_database = this;
     if (databaseObject.Guid != Guid.Empty)
     {
         m_databaseObjectsByGuid.Add(databaseObject.Guid, databaseObject);
     }
     foreach (DatabaseObject explicitNestingChild2 in databaseObject.GetExplicitNestingChildren(null, directChildrenOnly: true))
     {
         AddDatabaseObject(explicitNestingChild2, checkThatGuidsAreUnique: false);
     }
 }
Beispiel #2
0
 private static void publicSaveDatabaseObject(XElement node, DatabaseObject databaseObject, bool saveNestingParent)
 {
     XmlUtils.SetAttributeValue(node, "Name", databaseObject.Name);
     if (!string.IsNullOrEmpty(databaseObject.Description))
     {
         XmlUtils.SetAttributeValue(node, "Description", databaseObject.Description);
     }
     XmlUtils.SetAttributeValue(node, "Guid", databaseObject.Guid);
     if (databaseObject.Value != null)
     {
         XmlUtils.SetAttributeValue(node, "Value", databaseObject.Value);
         XmlUtils.SetAttributeValue(node, "Type", TypeCache.GetShortTypeName(databaseObject.Value.GetType().FullName));
     }
     if (databaseObject.ExplicitInheritanceParent != null)
     {
         XmlUtils.SetAttributeValue(node, "InheritanceParent", databaseObject.ExplicitInheritanceParent.Guid);
     }
     if (saveNestingParent && databaseObject.NestingParent != null)
     {
         XmlUtils.SetAttributeValue(node, "NestingParent", databaseObject.NestingParent.Guid);
     }
     publicSaveDatabaseObjectsList(node, from x in databaseObject.GetExplicitNestingChildren(null, directChildrenOnly: true)
                                   where !x.Type.SaveStandalone
                                   select x, saveNestingParents: false);
 }
Beispiel #3
0
 public void RemoveDatabaseObject(DatabaseObject databaseObject)
 {
     if (databaseObject.m_database != this)
     {
         throw new InvalidOperationException("public error: database object is not in the database.");
     }
     databaseObject.m_database = null;
     if (databaseObject.Guid != Guid.Empty && !m_databaseObjectsByGuid.Remove(databaseObject.Guid))
     {
         throw new InvalidOperationException("public error: database object not in dictionary.");
     }
     foreach (DatabaseObject explicitNestingChild in databaseObject.GetExplicitNestingChildren(null, directChildrenOnly: true))
     {
         RemoveDatabaseObject(explicitNestingChild);
     }
 }