private void ParseStoredDomainModel() { var context = UpgradeContext; var extensions = context.Metadata.Extensions.Where(e => e.Name == WellKnown.DomainModelExtensionName); try { var found = false; var types = new List <StoredTypeInfo>(); foreach (var extension in extensions) { found = true; var part = StoredDomainModel.Deserialize(extension.Value); types.AddRange(part.Types); } if (!found) { UpgradeLog.Info(Strings.LogDomainModelIsNotFoundInStorage); return; } var model = new StoredDomainModel { Types = types.ToArray() }; model.UpdateReferences(); context.ExtractedDomainModel = model; } catch (Exception e) { UpgradeLog.Warning(e, Strings.LogFailedToExtractDomainModelFromStorage); } }
public void UpgradeLogTest() { if (File.Exists(filePath)) { File.Delete(filePath); } UpgradeLog.Debug("Test message", null); UpgradeLog.Debug("Test message with parameter {0}", new object[] { 1 }); UpgradeLog.Debug(new Exception("Some exception"), "Test message with parameter {0}", new object[] { 1 }); UpgradeLog.Debug("Test message", new object[] { 1 }); UpgradeLog.Debug("Test message {0}", null); UpgradeLog.Debug(new Exception("Some exeption")); UpgradeLog.Debug(null, new object[] { 1 }); UpgradeLog.Info("Test message", null); UpgradeLog.Info("Test message with parameter {0}", new object[] { 1 }); UpgradeLog.Info(new Exception("Some exception"), "Test message with parameter {0}", new object[] { 1 }); UpgradeLog.Info("Test message", new object[] { 1 }); UpgradeLog.Info("Test message {0}", null); UpgradeLog.Info(new Exception("Some exeption")); UpgradeLog.Info(null, new object[] { 1 }); UpgradeLog.Warning("Test message", null); UpgradeLog.Warning("Test message with parameter {0}", new object[] { 1 }); UpgradeLog.Warning(new Exception("Some exception"), "Test message with parameter {0}", new object[] { 1 }); UpgradeLog.Warning("Test message", new object[] { 1 }); UpgradeLog.Warning("Test message {0}", null); UpgradeLog.Warning(new Exception("Some exeption")); UpgradeLog.Warning(null, new object[] { 1 }); UpgradeLog.Error("Test message", null); UpgradeLog.Error("Test message with parameter {0}", new object[] { 1 }); UpgradeLog.Error(new Exception("Some exception"), "Test message with parameter {0}", new object[] { 1 }); UpgradeLog.Error("Test message", new object[] { 1 }); UpgradeLog.Error("Test message {0}", null); UpgradeLog.Error(new Exception("Some exeption")); UpgradeLog.Error(null, new object[] { 1 }); UpgradeLog.FatalError("Test message", null); UpgradeLog.FatalError("Test message with parameter {0}", new object[] { 1 }); UpgradeLog.FatalError(new Exception("Some exception"), "Test message with parameter {0}", new object[] { 1 }); UpgradeLog.FatalError("Test message", new object[] { 1 }); UpgradeLog.FatalError("Test message {0}", null); UpgradeLog.FatalError(new Exception("Some exeption")); UpgradeLog.FatalError(null, new object[] { 1 }); Assert.IsTrue(File.Exists(filePath)); Assert.AreEqual(File.ReadAllLines(filePath).Count(), 35); }
private void SynchronizeSchema( Domain domain, SchemaUpgrader upgrader, SchemaExtractor extractor, SchemaUpgradeMode schemaUpgradeMode) { using (UpgradeLog.InfoRegion(Strings.LogSynchronizingSchemaInXMode, schemaUpgradeMode)) { StorageModel targetSchema = null; if (schemaUpgradeMode == SchemaUpgradeMode.Skip) { if (context.ParentDomain == null) { //If we build main domain we should log target model. //Log of Storage Node target model is not necessary //because storage target model exactly the same. targetSchema = GetTargetModel(domain); context.TargetStorageModel = targetSchema; if (UpgradeLog.IsLogged(LogLevel.Info)) { UpgradeLog.Info(Strings.LogTargetSchema); targetSchema.Dump(); } } var builder = ExtractedModelBuilderFactory.GetBuilder(context); context.ExtractedSqlModelCache = builder.Run(); OnSchemaReady(); return; // Skipping comparison completely } var extractedSchema = extractor.GetSchema(); // Hints var triplet = BuildTargetModelAndHints(extractedSchema); var hintProcessingResult = triplet.Third; targetSchema = triplet.First; context.TargetStorageModel = targetSchema; var hints = triplet.Second; if (UpgradeLog.IsLogged(LogLevel.Info)) { UpgradeLog.Info(Strings.LogExtractedSchema); extractedSchema.Dump(); UpgradeLog.Info(Strings.LogTargetSchema); targetSchema.Dump(); } OnSchemaReady(); var breifExceptionFormat = domain.Configuration.SchemaSyncExceptionFormat == SchemaSyncExceptionFormat.Brief; var result = SchemaComparer.Compare(extractedSchema, targetSchema, hints, context.Hints, schemaUpgradeMode, domain.Model, breifExceptionFormat, context.Stage); var shouldDumpSchema = !schemaUpgradeMode.In( SchemaUpgradeMode.Skip, SchemaUpgradeMode.ValidateCompatible, SchemaUpgradeMode.Recreate); if (shouldDumpSchema && UpgradeLog.IsLogged(LogLevel.Info)) { UpgradeLog.Info(result.ToString()); } if (UpgradeLog.IsLogged(LogLevel.Info)) { UpgradeLog.Info(Strings.LogComparisonResultX, result); } context.SchemaDifference = (NodeDifference)result.Difference; context.SchemaUpgradeActions = result.UpgradeActions; switch (schemaUpgradeMode) { case SchemaUpgradeMode.ValidateExact: if (result.SchemaComparisonStatus != SchemaComparisonStatus.Equal || result.HasColumnTypeChanges) { throw new SchemaSynchronizationException(result); } if (!hintProcessingResult.AreAllTypesMapped() && hintProcessingResult.SuspiciousTypes.Any()) { throw new SchemaSynchronizationException(Strings.ExExtractedAndTargetSchemasAreEqualButThereAreChangesInTypeIdentifiersSet); } break; case SchemaUpgradeMode.ValidateCompatible: if (result.SchemaComparisonStatus != SchemaComparisonStatus.Equal && result.SchemaComparisonStatus != SchemaComparisonStatus.TargetIsSubset) { throw new SchemaSynchronizationException(result); } break; case SchemaUpgradeMode.PerformSafely: if (result.HasUnsafeActions) { throw new SchemaSynchronizationException(result); } goto case SchemaUpgradeMode.Perform; case SchemaUpgradeMode.Recreate: case SchemaUpgradeMode.Perform: upgrader.UpgradeSchema(extractor.GetSqlSchema(), extractedSchema, targetSchema, result.UpgradeActions); if (result.UpgradeActions.Any()) { extractor.ClearCache(); } break; case SchemaUpgradeMode.ValidateLegacy: if (result.IsCompatibleInLegacyMode != true) { throw new SchemaSynchronizationException(result); } break; default: throw new ArgumentOutOfRangeException("schemaUpgradeMode"); } } }