Esempio n. 1
0
 private static void WriteDeleteContentListType(SchemaWriter writer, ContentListType contentListType, SchemaEditor origSchema, List <PropertySet> modifiedPropertySets)
 {
     writer.DeleteContentListType(contentListType);
     if (!modifiedPropertySets.Contains(contentListType))
     {
         modifiedPropertySets.Add(contentListType);
     }
 }
Esempio n. 2
0
        public void Register()
        {
            SchemaEditor origSchema = new SchemaEditor();

            origSchema.Load();
            DataProvider.Current.AssertSchemaTimestampAndWriteModificationDate(this.SchemaTimestamp);
            SchemaWriter schemaWriter = DataProvider.Current.CreateSchemaWriter();

            RegisterSchema(origSchema, this, schemaWriter);
        }
Esempio n. 3
0
        private static void WriteDeleteNodeType(SchemaWriter writer, NodeType nodeType, SchemaEditor origSchema, List <PropertySet> modifiedPropertySets)
        {
            //-- recursive
            foreach (NodeType childType in nodeType.Children)
            {
                WriteDeleteNodeType(writer, childType, origSchema, modifiedPropertySets);
            }

            writer.DeleteNodeType(nodeType);
            if (!modifiedPropertySets.Contains(nodeType))
            {
                modifiedPropertySets.Add(nodeType);
            }
        }
Esempio n. 4
0
        private static void WriteSchemaModifications(SchemaEditor origSchema, SchemaEditor newSchema, SchemaWriter writer, List <PropertySet> modifiedPropertySets)
        {
            //---- #1: Delete types

            foreach (NodeType type in GetNodeTypeRootsToDelete(origSchema.NodeTypes, newSchema.NodeTypes))
            {
                WriteDeleteNodeType(writer, type, origSchema, modifiedPropertySets);
            }
            foreach (var type in GetTypesToDelete <ContentListType>(origSchema.ContentListTypes, newSchema.ContentListTypes))
            {
                WriteDeleteContentListType(writer, type, origSchema, modifiedPropertySets);
            }
            //foreach (PropertyType type in GetTypesToDelete<PropertyType>(origSchema.PropertyTypes, newSchema.PropertyTypes))
            //    WriteDeletePropertyType(writer, type);
            foreach (PermissionType type in GetTypesToDelete <PermissionType>(origSchema.PermissionTypes, newSchema.PermissionTypes))
            {
                WriteDeletePermissionType(writer, type);
            }

            //---- #2: Create or modify types

            WriteCreateOrModifyPropertyTypes(origSchema, newSchema, writer);
            WriteCreateOrModifyNodeTypes(origSchema, newSchema, modifiedPropertySets, writer);
            WriteCreateOrModifyContentListTypes(origSchema, newSchema, modifiedPropertySets, writer);
            WriteCreateOrModifyPermissionTypes(origSchema, newSchema, writer);

            //---- #3: Delete PropertyTypes
            foreach (PropertyType type in GetTypesToDelete <PropertyType>(origSchema.PropertyTypes, newSchema.PropertyTypes))
            {
                WriteDeletePropertyType(writer, type);
            }
        }
Esempio n. 5
0
        private static void WriteAddOrRemovePropertyTypes(ContentListType origSet, ContentListType newSet, List <PropertySet> modifiedPropertySets, SchemaWriter writer)
        {
            bool origSetChanged = false;

            if (origSet == null)
            {
                //-- New NodeType: add all property
                foreach (PropertyType propType in newSet.PropertyTypes)
                {
                    writer.AddPropertyTypeToPropertySet(propType, newSet, true);
                }
                return;
            }
            //-- Delete PropertyType if needed
            foreach (PropertyType propType in GetTypesToDelete <PropertyType>(origSet.PropertyTypes, newSet.PropertyTypes))
            {
                writer.RemovePropertyTypeFromPropertySet(propType, newSet);
                origSetChanged = true;
            }

            //-- Create or modify PropertyTypes
            foreach (PropertyType propType in newSet.PropertyTypes)
            {
                if (NeedToCreate <PropertyType>(origSet.PropertyTypes, propType))
                {
                    writer.AddPropertyTypeToPropertySet(propType, newSet, true);
                    origSetChanged = true;
                }
            }

            if (origSetChanged && !modifiedPropertySets.Contains(origSet))
            {
                modifiedPropertySets.Add(origSet);
            }
        }
Esempio n. 6
0
 private static void RegisterSchema(SchemaEditor origSchema, SchemaEditor newSchema, SchemaWriter schemaWriter)
 {
     using (var traceOperation = Logger.TraceOperation("Write storage schema modifications."))
     {
         // Ensure transaction encapsulation
         bool isLocalTransaction = !TransactionScope.IsActive;
         if (isLocalTransaction)
         {
             TransactionScope.Begin();
         }
         try
         {
             List <PropertySet> modifiedPropertySets = new List <PropertySet>();
             schemaWriter.Open();
             WriteSchemaModifications(origSchema, newSchema, schemaWriter, modifiedPropertySets);
             foreach (PropertySet modifiedPropertySet in modifiedPropertySets)
             {
                 NodeTypeDependency.FireChanged(modifiedPropertySet.Id);
             }
             schemaWriter.Close();
             if (isLocalTransaction)
             {
                 TransactionScope.Commit();
             }
             ActiveSchema.Reset();
             traceOperation.IsSuccessful = true;
         }
         finally
         {
             IDisposable unmanagedWriter = schemaWriter as IDisposable;
             if (unmanagedWriter != null)
             {
                 unmanagedWriter.Dispose();
             }
             if (isLocalTransaction && TransactionScope.IsActive)
             {
                 TransactionScope.Rollback();
             }
         }
     }
 }
Esempio n. 7
0
        private static void WriteAddOrRemovePropertyTypes(NodeType origSet, NodeType newSet, List <PropertySet> modifiedPropertySets, SchemaWriter writer)
        {
            if (origSet == null)
            {
                //-- New NodeType: add all property
                foreach (PropertyType propType in newSet.PropertyTypes)
                {
                    writer.AddPropertyTypeToPropertySet(propType, newSet, newSet.DeclaredPropertyTypes.Contains(propType));
                }
                return;
            }
            bool origSetChanged = false;

            //-- Delete PropertyType if needed
            foreach (PropertyType propType in GetTypesToDelete <PropertyType>(origSet.PropertyTypes, newSet.PropertyTypes))
            {
                writer.RemovePropertyTypeFromPropertySet(propType, newSet);
                origSetChanged = true;
            }

            //-- Create or modify PropertyTypes
            foreach (PropertyType propType in newSet.PropertyTypes)
            {
                if (NeedToCreate <PropertyType>(origSet.PropertyTypes, propType))
                {
                    bool isDeclared = newSet.DeclaredPropertyTypes.Contains(propType);
                    writer.AddPropertyTypeToPropertySet(propType, newSet, isDeclared);
                    origSetChanged = true;
                }
                else
                {
                    //-- Modify Property declaration if needed (by the modifications in DeclaredPropertyTypes)
                    bool newIsDeclared  = newSet.DeclaredPropertyTypes.Contains(propType);
                    bool origIsDeclared = origSet.DeclaredPropertyTypes[propType.Name] != null;
                    if (newIsDeclared != origIsDeclared)
                    {
                        writer.UpdatePropertyTypeDeclarationState(propType, newSet, newIsDeclared);
                    }
                }
            }

            if (origSetChanged && !modifiedPropertySets.Contains(origSet))
            {
                modifiedPropertySets.Add(origSet);
            }
        }
Esempio n. 8
0
 private static void WriteCreateOrModifyPermissionTypes(SchemaEditor origSchema, SchemaEditor newSchema, SchemaWriter writer)
 {
     //-- new
     foreach (PermissionType newType in newSchema.PermissionTypes)
     {
         if (NeedToCreate <PermissionType>(origSchema.PermissionTypes, newType))
         {
             writer.CreatePermissionType(newType.Name);
         }
     }
 }
Esempio n. 9
0
 private static void WriteCreateOrModifyContentListTypes(SchemaEditor origSchema, SchemaEditor newSchema, List <PropertySet> modifiedPropertySets, SchemaWriter writer)
 {
     foreach (var newType in newSchema.ContentListTypes)
     {
         if (NeedToCreate <ContentListType>(origSchema.ContentListTypes, newType))
         {
             writer.CreateContentListType(newType.Name);
         }
         WriteAddOrRemovePropertyTypes(origSchema.ContentListTypes[newType.Name], newType, modifiedPropertySets, writer);
     }
 }
Esempio n. 10
0
        private static void WriteCreateOrModifyNodeTypes(SchemaEditor origSchema, SchemaEditor newSchema, List <PropertySet> modifiedPropertySets, SchemaWriter writer)
        {
            List <NodeType> _nodeTypesToEnumerate = new List <NodeType>();

            //-- collect only roots
            foreach (NodeType rootNodeType in newSchema.NodeTypes)
            {
                if (rootNodeType.Parent == null)
                {
                    _nodeTypesToEnumerate.Add(rootNodeType);
                }
            }

            int index = 0;

            while (index < _nodeTypesToEnumerate.Count)
            {
                NodeType currentType = _nodeTypesToEnumerate[index++];
                NodeType origType    = null;

                if (NeedToCreate <NodeType>(origSchema.NodeTypes, currentType))
                {
                    writer.CreateNodeType(currentType.Parent, currentType.Name, currentType.ClassName);
                }
                else
                {
                    origType = origSchema.NodeTypes[currentType.Name];
                    string origParentName = origType.Parent == null ? null : origType.Parent.Name;
                    string newParentName  = currentType.Parent == null ? null : currentType.Parent.Name;
                    bool   parentChanged  = origParentName != newParentName;
                    if (parentChanged || origType.ClassName != currentType.ClassName)
                    {
                        writer.ModifyNodeType(origType, currentType.Parent, currentType.ClassName);
                        if (!modifiedPropertySets.Contains(origType))
                        {
                            modifiedPropertySets.Add(origType);
                        }
                    }
                }

                //-- Property list (origType can be null)
                WriteAddOrRemovePropertyTypes(origType, currentType, modifiedPropertySets, writer);

                //-- Add children to enumerator
                _nodeTypesToEnumerate.AddRange(currentType.GetChildren());
            }
        }
Esempio n. 11
0
        //-------------------------------------------------------------- CreateOrRemove commands

        private static void WriteCreateOrModifyPropertyTypes(SchemaEditor origSchema, SchemaEditor newSchema, SchemaWriter writer)
        {
            //-- new
            foreach (PropertyType newType in newSchema.PropertyTypes)
            {
                if (NeedToCreate <PropertyType>(origSchema.PropertyTypes, newType))
                {
                    writer.CreatePropertyType(newType.Name, newType.DataType, newType.Mapping, newType.IsContentListProperty);
                }
            }
        }
Esempio n. 12
0
 private static void WriteDeletePermissionType(SchemaWriter writer, PermissionType permType)
 {
     writer.DeletePermissionType(permType);
 }
Esempio n. 13
0
        //-------------------------------------------------------------- Remove commands

        private static void WriteDeletePropertyType(SchemaWriter writer, PropertyType propType)
        {
            writer.DeletePropertyType(propType);
        }