示例#1
0
        private ContentListType ManageContentListType(Dictionary <string, FieldDescriptor> fieldInfoList, Dictionary <string, List <string> > oldBindings, bool modify, out List <FieldSetting> fieldSettings)
        {
            var attempts = 0;

            while (true)
            {
                try
                {
                    return(ManageContentListTypeOneAttempt(fieldInfoList, oldBindings, modify, out fieldSettings));
                }
                catch (Exception e)
                {
                    if (!e.Message.Contains("Storage schema is out of date") || attempts++ >= 42)
                    {
                        throw;
                    }
                }
                var timer = Stopwatch.StartNew();
                ActiveSchema.Reload();
                ContentTypeManager.Reload();
                timer.Stop();
                var d          = timer.Elapsed;
                var timeString = $"{d.Minutes}:{d.Seconds}.{d.Milliseconds}";
                SnLog.WriteInformation(
                    $"Type system is reloaded because it was out of date during managing a list type. Attempt: {attempts}, reloading time: {timeString}",
                    EventId.RepositoryRuntime);
            }
        }
示例#2
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);
                    }
                }
            }
        }
示例#3
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;
                }
            }
        }
示例#4
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();
             }
         }
     }
 }