Exemplo n.º 1
0
        public static bool?Show(DetectedChangeInstancesSet changeInstances, IMainWindow MainWindow, PSMDiagram diagramOldVersion, PSMDiagram diagramNewVersion)
        {
            EvolutionChangesWindow evolutionChangesWindow = new EvolutionChangesWindow();

            evolutionChangesWindow.ChangeInstances = changeInstances;
            evolutionChangesWindow.MainWindow      = MainWindow;

            List <ChangeInstance> changesList = new List <ChangeInstance>();

            foreach (KeyValuePair <Type, List <ChangeInstance> > keyValuePair in changeInstances)
            {
                changesList.AddRange(keyValuePair.Value);
            }

            evolutionChangesWindow.gridChanges.ItemsSource = changesList;
            evolutionChangesWindow.DiagramOldVersion       = diagramOldVersion;
            evolutionChangesWindow.DiagramNewVersion       = diagramNewVersion;
            evolutionChangesWindow.DiagramView             = MainWindow.DiagramTabManager.GetOpenedDiagramView(diagramNewVersion);
            evolutionChangesWindow.DiagramViewOldVersion   = MainWindow.DiagramTabManager.GetOpenedDiagramView(diagramOldVersion);
            evolutionChangesWindow.Topmost = true;

            evolutionChangesWindow.lRed.Text   = changeInstances.RedNodes.ConcatWithSeparator(", ");
            evolutionChangesWindow.lBlue.Text  = changeInstances.BlueNodes.ConcatWithSeparator(", ");
            evolutionChangesWindow.lGreen.Text = changeInstances.GreenNodes.ConcatWithSeparator(", ");

            evolutionChangesWindow.Show();
            return(true);
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 4
0
        public static bool?ShowDialog(DetectedChangeInstancesSet changeInstances, PSMSchema activeDiagramOldVersion, PSMSchema activeDiagramNewVersion)
        {
            XsltTestWindow xsltTestWindow = new XsltTestWindow(changeInstances);

            xsltTestWindow.SchemaVersion1 = activeDiagramOldVersion;
            xsltTestWindow.SchemaVersion2 = activeDiagramNewVersion;

            //return xsltTestWindow.ShowDialog();
            xsltTestWindow.Show();
            return(true);
        }
Exemplo n.º 5
0
        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]);
        }
Exemplo n.º 6
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)
            {
            }
        }
Exemplo n.º 7
0
 private XsltTestWindow(DetectedChangeInstancesSet changeInstances)
     : this()
 {
     ChangeInstances = changeInstances;
 }