public void TestGenerateGrammar() { ProjectSerializationManager projectSerializationManager = new ProjectSerializationManager(); Project sampleProject = projectSerializationManager.LoadProject(@"..\..\..\Projects\Figure8.eXo"); PSMSchema psmSchema = sampleProject.SingleVersion.PSMSchemas[0]; GrammarGenerator grammarGenerator = new GrammarGenerator(); Exolutio.Model.PSM.Grammar.Grammar g = grammarGenerator.GenerateGrammar(psmSchema); System.Diagnostics.Debug.WriteLine("Not normalized grammar: "); foreach (ProductionRule productionRule in g.ProductionRules) { System.Diagnostics.Debug.WriteLine(productionRule.ToString()); } System.Diagnostics.Debug.WriteLine(string.Empty); Normalizer normalizer = new Normalizer(); normalizer.Controller = new Controller.Controller(sampleProject); normalizer.NormalizeSchema(psmSchema); g = grammarGenerator.GenerateGrammar(psmSchema); System.Diagnostics.Debug.WriteLine("Normalized grammar: "); foreach (ProductionRule productionRule in g.ProductionRules) { System.Diagnostics.Debug.WriteLine(productionRule.ToString()); } System.Diagnostics.Debug.WriteLine(string.Empty); }
internal override void CommandOperation() { if (AttributeTypeGuid == Guid.Empty) { AttributeTypeGuid = Guid.NewGuid(); } AttributeType a = new AttributeType(Project, AttributeTypeGuid); ProjectVersion pv = Project.TranslateComponent <ProjectVersion>(ProjectVersionGuid); a.SetProjectVersion(pv); a.BaseType = BaseTypeGuid != Guid.Empty ? Project.TranslateComponent <AttributeType>(BaseTypeGuid) : null; a.Name = Name; a.IsSealed = IsSealed; a.XSDDefinition = XSDDefinition; if (PSMSchemaGuid != Guid.Empty) { PSMSchema psmSchema = Project.TranslateComponent <PSMSchema>(PSMSchemaGuid); a.Schema = psmSchema; psmSchema.PSMSchemaDefinedTypes.Add(a); } else { pv.PIMAttributeTypes.Add(a); } Report = new CommandReport("'{0}' created. "); }
private void bApply_Click(object sender, RoutedEventArgs e) { bApply.Focus(); error = false; controller.BeginMacro(); var addedPIMAttributes = Process(projectVersion.GetAvailablePIMTypes(), projectVersion, PSMSchema, controller, fakePIMAttributeTypes); List <FakeAttributeType> addedPSMAttributes; if (fakePSMAttributeTypes != null) { addedPSMAttributes = Process(PSMSchema.GetAvailablePSMTypes(), projectVersion, PSMSchema, controller, fakePSMAttributeTypes); } else { addedPSMAttributes = null; } if (error) { controller.CancelMacro(); } else { CommandBase tmp = (CommandBase)controller.CreatedMacro; controller.CommitMacro(); if (string.IsNullOrEmpty(tmp.ErrorDescription)) { { foreach (FakeAttributeType attribute in addedPIMAttributes) { attribute.SourceAttributeType = projectVersion.GetAvailablePIMTypes().Where (property => property.Name == attribute.Name).SingleOrDefault(); } addedPIMAttributes.RemoveAll(attribute => attribute.SourceAttributeType == null); } if (addedPSMAttributes != null) { foreach (FakeAttributeType attribute in addedPSMAttributes) { attribute.SourceAttributeType = PSMSchema.GetAvailablePSMTypes().Where (property => property.Name == attribute.Name).SingleOrDefault(); } addedPIMAttributes.RemoveAll(attribute => attribute.SourceAttributeType == null); } bApply.IsEnabled = false; dialogReady = true; error = false; } else { error = true; } } gridPIMAttributeTypes.Items.Refresh(); }
internal override void CommandOperation() { PSMAssociation a = Project.TranslateComponent <PSMAssociation>(associationGuid); PSMSchema s = Project.TranslateComponent <PSMSchema>(schemaGuid); if (a.Parent != null) { index = a.Parent.ChildPSMAssociations.IndexOf(a); a.Parent.ChildPSMAssociations.Remove(a); parentGuid = a.Parent; } //else throw new ExolutioCommandException("Deleted association " + a.ToString() + " had null Parent", this); isNonTreeAssociation = a.Child.ParentAssociation != a; if (a.Child != null) { childGuid = a.Child; if (!isNonTreeAssociation) { a.Child.ParentAssociation = null; s.Roots.Add(a.Child); } } //else throw new ExolutioCommandException("Deleted association " + a.ToString() + " had null Child", this); interpretation = a.Interpretation; s.PSMAssociations.Remove(a); Project.mappingDictionary.Remove(a); Report = new CommandReport(CommandReports.PSM_component_deleted, a); }
internal override void CommandOperation() { if (SchemaGuid == Guid.Empty) { SchemaGuid = Guid.NewGuid(); } if (SchemaClassGuid == Guid.Empty) { SchemaClassGuid = Guid.NewGuid(); } PSMSchema psmSchema; if (!Project.UsesVersioning) { psmSchema = new PSMSchema(Project, SchemaGuid, Project.SingleVersion); } else { psmSchema = new PSMSchema(Project, SchemaGuid, Project.TranslateComponent <ProjectVersion>(projectVersionGuid)); } new PSMSchemaClass(Project, SchemaClassGuid, psmSchema); Report = new CommandReport(CommandReports.PSM_component_added, psmSchema); }
public override bool VerifyConsistency(object superordinateObject, object candidate) { PSMSchema psmSchema = (PSMSchema)superordinateObject; PSMComponent psmComponent = (PSMComponent)candidate; return(psmSchema.SchemaComponents.Contains(psmComponent)); }
public void NormalizeSchema(PSMSchema schema) { modelVerifier = new ModelVerifier(); //Controller.BeginMacro(); FinalReport = new NestedCommandReport(); bool somethingFound = false; while (!modelVerifier.TestSchemaNormalized(schema)) { somethingFound = true; StackedCommand command = GetNormalizationCommand(schema); command.Execute(); if (command is MacroCommand) { NestedCommandReport commandReport = ((MacroCommand)command).GetReport(); ((NestedCommandReport)FinalReport).NestedReports.Add(commandReport); } } if (!somethingFound) { FinalReport = new CommandReport("Schema is already normalized. "); } //Controller.CommitMacro(); }
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 StackedCommand GetNormalizationCommand(PSMSchema schema) { // (d) Content model association normalization if (!modelVerifier.TestSchemaClassChildrenAreClasses(schema)) { PSMContentModel cm = (PSMContentModel)modelVerifier.LastViolatingComponent; cmdDeletePSMAssociation command = new cmdDeletePSMAssociation(Controller); command.Set(cm.ParentAssociation.ID); return(command); } // (c) Empty name association else if (!modelVerifier.TestSchemaClassChildrenNames(schema)) { PSMAssociation a = (PSMAssociation)modelVerifier.LastViolatingComponent; cmdDeletePSMAssociation command = new cmdDeletePSMAssociation(Controller); command.Set(a.ID); return(command); } // (e) Root content model normalization else if (!modelVerifier.TestRootsAreNotContentModels(schema)) { PSMContentModel cm = (PSMContentModel)modelVerifier.LastViolatingComponent; MacroCommand m = new MacroCommand(Controller); foreach (PSMAssociation childPsmAssociation in cm.ChildPSMAssociations) { cmdDeletePSMAssociation delA = new cmdDeletePSMAssociation(Controller); delA.Set(childPsmAssociation.ID); m.Commands.Add(delA); } cmdDeletePSMContentModel delCM = new cmdDeletePSMContentModel(Controller); delCM.Set(cm.ID); m.Commands.Add(delCM); return(m); } // (f) Root class normalization else if (!modelVerifier.TestRootsAreReferenced(schema)) { PSMClass c = (PSMClass)modelVerifier.LastViolatingComponent; cmdDeleteRootPSMClass command = new cmdDeleteRootPSMClass(Controller); command.Set(c.ID); return(command); } // (a) Cardinality normalization else if (!modelVerifier.TestSchemaClassChildrenCardinality(schema)) { PSMAssociation a = (PSMAssociation)modelVerifier.LastViolatingComponent; cmdUpdatePSMAssociationCardinality command = new cmdUpdatePSMAssociationCardinality(Controller); command.Set(a.ID, 1, 1); return(command); } // (b) Name normalization else if (!modelVerifier.TestContentModelsAssociationNames(schema)) { PSMAssociation a = (PSMAssociation)modelVerifier.LastViolatingComponent; cmdRenameComponent command = new cmdRenameComponent(Controller) { ComponentGuid = a.ID, NewName = String.Empty }; return(command); } else { throw new InvalidOperationException("Schema is already normalized. "); } }
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); } }
/// <summary> /// Returns true if a PSM schema is normalized /// </summary> public bool TestSchemaNormalized(PSMSchema psmSchema) { LogMessage m = new LogMessage() { Severity = ELogMessageSeverity.Error, MessageText = string.Format("PSM schema '{0}' is not normalized", psmSchema) }; messageDict[psmSchema] = m; bool c11 = TestSchemaClassChildrenCardinality(psmSchema); //(1) bool c12 = TestSchemaClassChildrenNames(psmSchema); //(1) bool c2 = TestSchemaClassChildrenAreClasses(psmSchema); //(2) bool c3 = TestContentModelsAssociationNames(psmSchema); //(3) bool c4 = TestRootsAreNotContentModels(psmSchema); //(4) bool c5 = TestRootsAreReferenced(psmSchema); //(5) bool result = c11 && c12 && c2 && c3 && c4 && c5; if (!result) { Log.AddLogMessage(m); } return(result); }
public PSMBridge(PSMSchema schema) { PSMAssociationMembers = new Dictionary <PSMAssociationMember, PSMBridgeClass>(); PSMAttributeType = new Dictionary <AttributeType, Classifier>(); this.Schema = schema; CreateTypesTable(); }
private void ClassifyNodes(DetectedChangeInstancesSet changeInstances, PSMSchema psmSchema) { FindRedNodes(changeInstances); #region blue and green nodes Queue <PSMAssociationMember> toDo = new Queue <PSMAssociationMember>(); foreach (PSMAssociationMember m in ModelIterator.GetLeaves(psmSchema)) { if (changeInstances.RedNodes.Contains(m)) { toDo.Enqueue(m); } } foreach (PSMAssociationMember redNode in changeInstances.RedNodes.OfType <PSMAssociationMember>()) { toDo.Enqueue(redNode); } foreach (PSMAttribute psmAttribute in changeInstances.RedNodes.OfType <PSMAttribute>()) { if (!changeInstances.RedNodes.Contains(psmAttribute.PSMClass)) { changeInstances.BlueNodes.AddIfNotContained(psmAttribute.PSMClass); toDo.Enqueue(psmAttribute.PSMClass); } } while (!toDo.IsEmpty()) { PSMAssociationMember m = toDo.Dequeue(); if (m.ParentAssociation != null) { if (!changeInstances.RedNodes.Contains(m.ParentAssociation.Parent) && !changeInstances.BlueNodes.Contains(m.ParentAssociation.Parent)) { changeInstances.BlueNodes.Add(m.ParentAssociation.Parent); if (!(m.ParentAssociation.Parent is PSMSchemaClass)) { toDo.Enqueue(m.ParentAssociation.Parent); } } } } changeInstances.GreenNodes.AddRange(psmSchema.SchemaComponents.Where(c => !(c is PSMAssociation) && !(c is PSMSchemaClass) && !changeInstances.RedNodes.Contains(c) && !changeInstances.BlueNodes.Contains(c)).Cast <PSMComponent>()); foreach (PSMComponent psmComponent in changeInstances.AllNodes) { if (!psmComponent.ExistsInVersion(changeInstances.OldVersion)) { changeInstances.AddedNodes.Add(psmComponent); } } #endregion }
public static string Transform(string document, string xslt, string tmpDir, PSMSchema psmSchema = null, bool schemaAware = false) { #if SAXON_XSLT return(TransformSAXON(document, xslt, tmpDir, psmSchema, schemaAware)); #else return(TransformNET(document, xslt, tmpDir)); #endif }
internal override OperationResult UndoOperation() { PSMSchema schema = Project.TranslateComponent <PSMSchema>(schemaGuid); PSMClass c = new PSMClass(Project, deletedClassGuid, schema, rootIndex); //schema.RegisterPSMRoot(c, rootIndex); //Already done in new PSMClass return(OperationResult.OK); }
internal override CommandBase.OperationResult UndoOperation() { PSMSchema s = Project.TranslateComponent <PSMSchema>(SchemaGuid); PSMDiagram psmDiagram = Project.TranslateComponent <PSMDiagram>(diagramGuid); s.ProjectVersion.PSMDiagrams.Remove(psmDiagram); Project.mappingDictionary.Remove(psmDiagram); return(OperationResult.OK); }
public void Initialize(PSMSchema psmSchema) { PSMSchema = psmSchema; nodeInfos.Clear(); Log = new Log(); NamingSupport = new NamingSupport { Log = Log }; }
/** * Inicializuje PushDownAutomat a jeho pomocne struktury. **/ public void inicialize(PSMSchema schema, String XMLFilePath) { XMLDocument = new XmlDocument(); XMLDocument.Load(XMLFilePath); readedNodesStackTrace = new Stack <String>(); schema.Project.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(removeFromCache); if (initializationCache.ContainsKey(schema)) { forestStatesTransitions = initializationCache[schema].ForestStatesTransitions; rightSideToLeftSide = initializationCache[schema].RightSideToLeftSide; startState = initializationCache[schema].StartState; finalState = initializationCache[schema].FinalState; wordToState = initializationCache[schema].WordToState; } else { treeStateCount = 0; forestStatesTransitions = new Dictionary <StateWordPair, HashSet <AutomatEdge> >(); rightSideToLeftSide = new Dictionary <string, HashSet <string> >(); startState = new HashSet <AutomatState>(); finalState = new HashSet <AutomatState>(); wordToState = new Dictionary <string, HashSet <AutomatState> >(); associationLeftSideName = new Dictionary <PSMAssociation, string>(); automatUtils = new FiniteAutomatUtils(); inicializedAssociations = new HashSet <PSMAssociation>(); AutomatState forestStartState = new AutomatState("ss1", true, null); AutomatState forestFinalState = new AutomatState("ss2", forestStartState); forestFinalState.exitState = true; startState.Add(forestStartState); finalState.Add(forestFinalState); forestStatesTransitions.Add(new StateWordPair(forestStartState, "T0"), new HashSet <AutomatEdge> { new AutomatEdge(forestFinalState) }); if (schema.PSMSchemaClass.ChildPSMAssociations.Count > 1) { throw new Exception("XML must have root element"); } treeStateCount++; associationLeftSideName.Add(schema.PSMSchemaClass.ChildPSMAssociations[0], leftSideName + (treeStateCount - 1)); inicialize(schema.PSMSchemaClass.ChildPSMAssociations[0], leftSideName + (treeStateCount - 1)); if (!initializationCache.ContainsKey(schema)) { initializationCache.Add(schema, new InitConfig(forestStatesTransitions, rightSideToLeftSide, startState, finalState, wordToState)); } } }
internal override CommandBase.OperationResult UndoOperation() { PSMSchema psmSchema = Project.TranslateComponent <PSMSchema>(SchemaGuid); PSMDiagram psmDiagram = new PSMDiagram(Project, DiagramGuid); psmDiagram.Schema = psmSchema; psmDiagram.LoadSchemaToDiagram(psmSchema); psmSchema.ProjectVersion.PSMDiagrams.Add(psmDiagram); return(OperationResult.OK); }
internal override CommandBase.OperationResult UndoOperation() { PSMSchema s = Project.TranslateComponent <PSMSchema>(schemaGuid); PSMContentModel cm = Project.TranslateComponent <PSMContentModel>(ContentModelGuid); Project.TranslateComponent <PSMSchema>(schemaGuid).Roots.Remove(cm); Project.TranslateComponent <PSMSchema>(schemaGuid).PSMContentModels.Remove(cm); Project.mappingDictionary.Remove(cm); return(OperationResult.OK); }
public void Initialize(PSMSchema psmSchema) { PSMSchema = psmSchema; nodeInfos.Clear(); Log = new Log(); NamingSupport = new NamingSupport { Log = Log }; RelaxNGXmlSyntaxWriter = new RelaxNGXmlSyntaxWriter(); }
internal override void CommandOperation() { PSMClass c = Project.TranslateComponent <PSMClass>(deletedClassGuid); PSMSchema schema = Project.TranslateComponent <PSMSchema>(schemaGuid); rootIndex = schema.Roots.Remove(c); schema.PSMClasses.Remove(c); Project.mappingDictionary.Remove(deletedClassGuid); Report = new CommandReport(CommandReports.PSM_component_deleted, c); }
public void TestSampleGenerator() { Project project = TestUtils.CreateSampleProject(); SampleDataGenerator generator = new SampleDataGenerator(); PSMSchema psmSchema = project.SingleVersion.PSMSchemas[0]; XDocument xmlDocument = generator.Translate(psmSchema); xmlDocument.Save("TestSampleGenerator.xml"); }
internal override CommandBase.OperationResult UndoOperation() { PSMSchema s = Project.TranslateComponent <PSMSchema>(schemaGuid); PSMContentModel cm = new PSMContentModel(Project, cmodelGuid, s, rootIndex); cm.Type = type; //s.RegisterPSMRoot(cm, rootIndex); //Already done in the constructor return(OperationResult.OK); }
internal override CommandBase.OperationResult UndoOperation() { PSMSchema schema = new PSMSchema(Project, schemaGuid); new PSMSchemaClass(Project, schemaClassGuid, schema) { Name = Name }; Project.LatestVersion.PSMSchemas.Insert(schema, index); return(OperationResult.OK); }
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); }
internal override CommandBase.OperationResult UndoOperation() { PSMGeneralization g = Project.TranslateComponent <PSMGeneralization>(GeneralizationGuid); PSMSchema s = Project.TranslateComponent <PSMSchema>(schemaGuid); g.General.GeneralizationsAsGeneral.Remove(g); g.Specific.GeneralizationAsSpecific = null; s.PSMGeneralizations.Remove(g); Project.mappingDictionary.Remove(g); return(OperationResult.OK); }
internal override CommandBase.OperationResult UndoOperation() { PSMSchema s = Project.TranslateComponent <PSMSchema>(SchemaGuid); s.UnRegisterPSMSchemaClass(s.PSMSchemaClass); ProjectVersion schemaVersion = s.ProjectVersion; schemaVersion.PSMSchemas.Remove(s); Project.mappingDictionary.Remove(SchemaClassGuid); Project.mappingDictionary.Remove(SchemaGuid); return(OperationResult.OK); }
public override void Execute(object parameter = null) { if (Current.ActiveDiagram != null && Current.ActiveDiagram is PSMDiagram) { ConstraintsSuggestor suggestor = new ConstraintsSuggestor(); PSMSchema psmSchema = (PSMSchema)Current.ActiveDiagram.Schema; IList <ClassifierConstraintBlock> constraints = suggestor.FindSuitableConstraints(Current.ProjectVersion.PIMSchema, psmSchema); SuggestConstraintsWindow w = new SuggestConstraintsWindow(); w.PSMSchema = psmSchema; w.Show(); w.DisplayConstraints(constraints); } }
internal override void CommandOperation() { PSMSchema s = Project.TranslateComponent <PSMSchema>(schemaGuid); PSMContentModel cm = Project.TranslateComponent <PSMContentModel>(cmodelGuid); type = cm.Type; rootIndex = s.Roots.Remove(cm); Project.TranslateComponent <PSMSchema>(schemaGuid).PSMContentModels.Remove(cm); Project.mappingDictionary.Remove(cm); Report = new CommandReport(CommandReports.PSM_component_deleted, cm); }