Exemplo 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);
     }
 }
Exemplo 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);
        }
Exemplo 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);
            }
        }
Exemplo n.º 4
0
        public void Register()
        {
            var origSchema = Retrier.Retry(3, 100, typeof(InvalidSchemaException), () =>
            {
                var sche = new SchemaEditor();
                sche.Load();
                return(sche);
            });

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

            RegisterSchema(origSchema, this, schemaWriter);
        }
Exemplo n.º 5
0
        private static void RegisterSchema(SchemaEditor origSchema, SchemaEditor newSchema, SchemaWriter schemaWriter)
        {
            if (schemaWriter.CanWriteDifferences)
            {
                using (var op = SnTrace.Database.StartOperation("Write storage schema modifications."))
                {
                    try
                    {
                        var modifiedPropertySets = new List <PropertySet>();

                        schemaWriter.Open();
                        WriteSchemaModifications(origSchema, newSchema, schemaWriter, modifiedPropertySets);

                        foreach (var modifiedPropertySet in modifiedPropertySets)
                        {
                            NodeTypeDependency.FireChanged(modifiedPropertySet.Id);
                        }

                        schemaWriter.Close();
                        ActiveSchema.Reset();

                        op.Successful = true;
                    }
                    catch (Exception ex)
                    {
                        SnLog.WriteException(ex, null, EventId.RepositoryRuntime);
                        throw new SchemaEditorCommandException("Error during schema registration.", ex);
                    }
                    finally
                    {
                        if (schemaWriter is IDisposable unmanagedWriter)
                        {
                            unmanagedWriter.Dispose();
                        }
                    }
                }
            }
            else
            {
                using (var op = SnTrace.Database.StartOperation("Update storage schema."))
                {
                    var modifiedPropertySetIds = GetModifiedPropertySetIds(origSchema, newSchema);

                    schemaWriter.WriteSchemaAsync(newSchema.ToRepositorySchemaData()).GetAwaiter().GetResult();
                    ActiveSchema.Reset();
                    foreach (var id in modifiedPropertySetIds)
                    {
                        NodeTypeDependency.FireChanged(id);
                    }

                    op.Successful = true;
                }
            }
        }
Exemplo n.º 6
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);
            }
        }
Exemplo 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);
            }
        }
Exemplo n.º 8
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);
     }
 }
Exemplo n.º 9
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());
            }
        }
Exemplo n.º 10
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);
                }
            }
        }
Exemplo n.º 11
0
        // -------------------------------------------------------------- Remove commands

        private static void WriteDeletePropertyType(SchemaWriter writer, PropertyType propType)
        {
            writer.DeletePropertyType(propType);
        }
Exemplo n.º 12
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);
            }

            // #2: Create or modify types

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

            // #3: Delete PropertyTypes
            foreach (PropertyType type in GetTypesToDelete <PropertyType>(origSchema.PropertyTypes, newSchema.PropertyTypes))
            {
                WriteDeletePropertyType(writer, type);
            }
        }
Exemplo n.º 13
0
        private static void RegisterSchema(SchemaEditor origSchema, SchemaEditor newSchema, SchemaWriter schemaWriter)
        {
            using (var op = SnTrace.Database.StartOperation("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();
                    op.Successful = true;
                }
                catch (Exception ex)
                {
                    SnLog.WriteException(ex, null, EventId.RepositoryRuntime);
                    throw new SchemaEditorCommandException("Error during schema registration.", ex);
                }
                finally
                {
                    IDisposable unmanagedWriter = schemaWriter as IDisposable;
                    if (unmanagedWriter != null)
                    {
                        unmanagedWriter.Dispose();
                    }
                    try
                    {
                        if (isLocalTransaction && TransactionScope.IsActive)
                        {
                            TransactionScope.Rollback();
                        }
                    }
                    catch (Exception ex2)
                    {
                        // This catch block will handle any errors that may have occurred
                        // on the server that would cause the rollback to fail, such as
                        // a closed connection (MSDN).
                        const string msg = "Error during schema transaction rollback.";
                        SnLog.WriteException(ex2, msg, EventId.RepositoryRuntime);

                        throw new SchemaEditorCommandException(msg, ex2);
                    }
                }
            }
        }
Exemplo n.º 14
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();
             }
         }
     }
 }
Exemplo n.º 15
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);
         }
     }
 }
Exemplo n.º 16
0
 private static void WriteDeletePermissionType(SchemaWriter writer, PermissionType permType)
 {
     writer.DeletePermissionType(permType);
 }