/// <summary> /// Asynchronously saves all changes made in this context to the database. /// </summary> /// <param name="acceptAllChangesOnSuccess"> /// Indicates whether <see cref="ChangeTracking.ChangeTracker.AcceptAllChanges" /> is called after the changes have /// been sent successfully to the database. /// </param> /// <remarks> /// <para> /// This method will automatically call <see cref="ChangeTracking.ChangeTracker.DetectChanges" /> to discover any /// changes to entity instances before saving to the underlying database. This can be disabled via /// <see cref="ChangeTracking.ChangeTracker.AutoDetectChangesEnabled" />. /// </para> /// <para> /// Multiple active operations on the same context instance are not supported. Use 'await' to ensure /// that any asynchronous operations have completed before calling another method on this context. /// </para> /// </remarks> /// <param name="cancellationToken">A <see cref="CancellationToken" /> to observe while waiting for the task to complete.</param> /// <returns> /// A task that represents the asynchronous save operation. The task result contains the /// number of state entries written to the database. /// </returns> public virtual async Task <int> SaveChangesAsync(bool acceptAllChangesOnSuccess, CancellationToken cancellationToken = default(CancellationToken)) { var stateManager = StateManager; if (ChangeTracker.AutoDetectChangesEnabled) { ChangeDetector.DetectChanges(stateManager); } try { return(await stateManager.SaveChangesAsync(acceptAllChangesOnSuccess, cancellationToken)); } catch (Exception exception) { _logger.LogError( CoreLoggingEventId.DatabaseError, () => new DatabaseErrorLogState(GetType()), exception, e => CoreStrings.LogExceptionDuringSaveChanges(Environment.NewLine, e)); throw; } }
public static void FindAndDisplayChanges(PSMSchema schemaVersion1, PSMSchema schemaVersion2) { ChangeDetector changeDetector = new ChangeDetector(); DetectedChangeInstancesSet detectedChangeInstancesSet = changeDetector.DetectChanges(schemaVersion1, schemaVersion2); EvolutionChangesWindow.Show(detectedChangeInstancesSet, Current.MainWindow, schemaVersion1.PSMDiagram, schemaVersion2.PSMDiagram); }
private void TryDetectChanges(IStateManager stateManager) { if (ChangeTracker.AutoDetectChangesEnabled) { ChangeDetector.DetectChanges(stateManager); } }
public static void Adapt(PSMSchema schemaVersion1, PSMSchema schemaVersion2) { ChangeDetector changeDetector = new ChangeDetector(); DetectedChangeInstancesSet detectedChangeInstancesSet = changeDetector.DetectChanges(schemaVersion1, schemaVersion2); XsltAdaptationScriptGenerator g = new XsltAdaptationScriptGenerator(); g.Initialize(schemaVersion1, schemaVersion2, detectedChangeInstancesSet); g.GenerateTransformationStructure(); XDocument revalidationStylesheet = g.GetAdaptationTransformation(); revalidationStylesheet.Elements().First().AddFirst(new XComment(string.Format(" Template generated by eXolutio on {0} {1} \r\n from {2}. ", System.DateTime.Now.ToShortDateString(), System.DateTime.Now.ToShortTimeString(), Current.Project.ProjectFile))); if (Environment.MachineName.Contains("TRUPIK")) { revalidationStylesheet.Save(XsltTestWindow.SAVE_STYLESHEET); if (schemaVersion1.Project.ProjectFile != null) { string ls = string.Format("{0}\\{1}", schemaVersion1.Project.ProjectFile.Directory.FullName, "LastStylesheet.xslt"); revalidationStylesheet.Save(ls); } } //else { XsltTestWindow.ShowDialog(detectedChangeInstancesSet, schemaVersion1, schemaVersion2); } }
public void AdbisExample() { ProjectSerializationManager s = new ProjectSerializationManager(); DirectoryInfo pd = new DirectoryInfo(Environment.CurrentDirectory); while (!pd.GetDirectories().Any(d => d.FullName.EndsWith(@"Projects"))) { pd = pd.Parent; } Project p = s.LoadProject(Path.Combine(pd.FullName, "Projects", "adbis-branched.eXo")); ChangeDetector detector = new ChangeDetector(); DetectedChangeInstancesSet detectedChangeInstancesSet = detector.DetectChanges(p.ProjectVersions[0].PSMSchemas[0], p.ProjectVersions[1].PSMSchemas[0]); }
public void TestOCLAdaptation(object directory) { DirectoryInfo testDir = new DirectoryInfo(directory.ToString()); try { FileInfo[] inputFiles = testDir.GetFiles("*in.xml"); FileInfo projectFile = testDir.GetFiles("*.eXo").FirstOrDefault(); if (projectFile == null) { Assert.Fail("No project file found for test {0}", testDir.Name); } FileInfo[] stylesheetFiles = testDir.GetFiles("*.xslt"); FileInfo referenceStylesheetFileInfo = null; foreach (FileInfo stylesheetFile in stylesheetFiles) { if (stylesheetFile.Name.Contains("DesiredStylesheet") || stylesheetFile.Name.Contains("LastStylesheet") || stylesheetFile.Name.Contains("generated") || stylesheetFile.Name.Contains("last-working")) { continue; } referenceStylesheetFileInfo = stylesheetFile; } Project project = serializationManager.LoadProject(projectFile); XsltAdaptationScriptGenerator generator = new XsltAdaptationScriptGenerator(); ChangeDetector detector = new ChangeDetector(); PSMSchema psmSchemaOldVersion = project.ProjectVersions[0].PSMSchemas.First(); PSMSchema psmSchemaNewVersion = project.ProjectVersions[1].PSMSchemas.First(); DetectedChangeInstancesSet detectedChangeInstancesSet = detector.DetectChanges(psmSchemaOldVersion, psmSchemaNewVersion); generator.Initialize(psmSchemaOldVersion, psmSchemaNewVersion, detectedChangeInstancesSet); generator.SchemaAware = true; generator.GenerateTransformationStructure(); XDocument testGeneratedStylesheet = generator.GetAdaptationTransformation(); string testGeneratedStylesheetFileName = testDir.FullName + "/" + testDir.Name + "-generated.xslt"; testGeneratedStylesheet.SaveInUtf8(testGeneratedStylesheetFileName); Console.WriteLine("Revalidation stylesheet generated."); Console.WriteLine(); string generatedStylesheetText = File.ReadAllText(testGeneratedStylesheetFileName); StringBuilder failMessage = new StringBuilder(); int failCounts = 0; StringBuilder inconclusiveMessage = new StringBuilder(); if (referenceStylesheetFileInfo != null) { //XDocument xdRefStylesheet = XDocument.Load(referenceStylesheet.FullName); //xdRefStylesheet.RemoveComments(); //string referenceStylesheetText = xdRefStylesheet.ToString(); //XDocument xdGenStylesheet = XDocument.Load(testGeneratedStylesheetFile); //xdGenStylesheet.RemoveComments(); //generatedStylesheetText = xdGenStylesheet.ToString(); string diff; if (XmlDocumentHelper.DocumentCompare(testGeneratedStylesheetFileName, referenceStylesheetFileInfo.FullName, out diff, XmlDiffOptions.IgnoreComments | XmlDiffOptions.IgnoreWhitespace)) { string message = string.Format("Generated stylesheet for {1} is identical to reference stylesheet {0}.", referenceStylesheetFileInfo.Name, testDir.Name); Console.WriteLine(message); } else { string message = string.Format("Generated stylesheet for {1} differs from reference stylesheet {0}.", referenceStylesheetFileInfo.Name, testDir.Name); Console.WriteLine(message); inconclusiveMessage.AppendLine(message); } } else { string message = string.Format("No reference stylesheet available. "); Console.WriteLine(message); } Console.WriteLine(); string tmpDir = Path.GetTempPath(); foreach (FileInfo inputFile in inputFiles) { Console.WriteLine("Testing revalidation of file {0}.", inputFile.Name); string input = File.ReadAllText(inputFile.FullName); string output = XsltProcessing.TransformSAXON(inputFile.FullName, testGeneratedStylesheetFileName, true); string genOutputFile = inputFile.FullName.Replace("in.xml", "out-generated.xml"); File.WriteAllText(genOutputFile, output); Console.WriteLine("XSLT transformation succeeded, results written to {0}. ", genOutputFile); string refOutputFile = inputFile.FullName.Replace("in.xml", "out.xml"); if (File.Exists(refOutputFile)) { bool bIdentical = XmlDocumentHelper.DocumentCompare(refOutputFile, genOutputFile, XmlDiffOptions.IgnoreXmlDecl | XmlDiffOptions.IgnoreComments); if (bIdentical) { string message = string.Format("Output for file {0} is identical to the reference output. ", inputFile.Name); Console.WriteLine(message); } else { string message = string.Format("Result differs from reference output for file {0}", inputFile.Name); Console.WriteLine(message); failMessage.AppendLine(message); failCounts++; } } else { string message = string.Format("Reference output not found for file {0}", inputFile.Name); Console.WriteLine(message); inconclusiveMessage.AppendLine(message); } } if (inputFiles.Length == 0) { string message = string.Format("No input files for test {0}", testDir.Name); Console.WriteLine(message); inconclusiveMessage.AppendLine(message); } if (failCounts > 0) { string finalMessage = string.Format("Failed for {0}/{1} test inputs. \r\n", failCounts, inputFiles.Length); Console.WriteLine(finalMessage); failMessage.Insert(0, finalMessage); Assert.Fail(failMessage.ToString()); } if (inconclusiveMessage.Length > 0) { Assert.Inconclusive(inconclusiveMessage.ToString()); } if (failCounts == 0) { string lastWorkingStylesheetFile = testDir.FullName + "/" + testDir.Name + "-last-working.xslt"; testGeneratedStylesheet.SaveInUtf8(lastWorkingStylesheetFile); } Console.WriteLine("Test succeeded. "); } catch (Exception exception) { } }
/// <summary> /// Scans the tracked entity instances to detect any changes made to the instance data. <see cref="DetectChanges()" /> /// is usually called automatically by the context when up-to-date information is required (before /// <see cref="DbContext.SaveChanges()" /> and when returning change tracking information). You typically only need to /// call this method if you have disabled <see cref="AutoDetectChangesEnabled" />. /// </summary> public virtual void DetectChanges() => ChangeDetector.DetectChanges(StateManager);
public void Detector() { var date = DateTime.Now; var user1 = new User { Id = 1, Password = null, Posts = new List <Post>() { new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔ1", Id = 1, IsTransient = false, Author = new Author() { Title = null } }, new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔ", Id = 2, IsTransient = false, Author = new Author() { Title = "author" } }, new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔ", Id = 3, IsTransient = false, Author = new Author() { Title = "author" } }, new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔ2", Id = 4, IsTransient = false, Author = new Author() { Title = "author" } }, new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔb", Id = 5, IsTransient = false, Author = new Author() { Title = "author" } }, new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔ", Id = 6, IsTransient = false, Author = new Author() { Title = "author" } }, } }; var user2 = new User { Id = 1, Password = "******", Posts = new List <Post>() { new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔ", Id = 1, IsTransient = false, Author = new Author() { Title = "author" } }, new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔ", Id = 2, IsTransient = false, Author = new Author() { Title = "author" } }, new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔ", Id = 3, IsTransient = false, Author = new Author() { Title = "author" } }, new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔ", Id = 4, IsTransient = false, Author = new Author() { Title = "author" } }, new Post() { CreatedDate = date, Description = date.Ticks.ToString(), Title = "²âÊÔ", Author = new Author() { Title = "author2" } } } }; IChangeManager manager = new ChangeManager(); IChangeManagerFactory managerFactory = new ChangeManagerFactory(manager); IChangeDetector detector = new ChangeDetector(managerFactory); manager = detector.DetectChanges(user2, user1); }