private void importTGGCSP(SQLElement ruleElement, MocaNode cspInstanceNode)
        {
            EA.Element  cspElement = MainImport.getInstance().EcoreImport.getOrCreateElement(ruleElement, cspInstanceNode, "Class");
            CSPInstance cspIstance = new CSPInstance(sqlRep, sqlRep.GetElementByID(cspElement.ElementID));

            cspIstance.deserializeFromMocaTree(cspInstanceNode);


            MainImport.getInstance().MocaTaggableElements.Add(cspIstance);
            MainImport.getInstance().ElementGuidToElement.Add(cspElement.ElementGUID, cspElement);
        }
        public CSPInstanceDialog(SQLRepository repository, SQLElement constraintElement, CSPController controller)
        {
            InitializeComponent();
            this.controller            = controller;
            this.labelInformation.Text = "";
            this.CSPConstraintDataGridView1.initializeComponent(repository, controller);
            this.StartPosition     = FormStartPosition.CenterScreen;
            this.constraintElement = constraintElement;
            this.repository        = repository;

            this.constraintInstance = new CSPInstance(repository, constraintElement);
            this.constraintInstance.loadTreeFromTaggedValue();

            this.setAppearance();
            if (comboBoxConstraints.SelectedIndex == -1)
            {
                this.comboBoxConstraints.SelectedIndex = 0;
            }

            if (listBoxConstraints.Items.Count > 0)
            {
                listBoxConstraints.SelectedIndex = 0;
            }
        }
        public override List <string> doRule(SQLElement eaElement, SQLWrapperClasses.SQLRepository repository)
        {
            List <String> results = new List <string>();

            if (eaElement.Stereotype == TGGModelingMain.CSPConstraintStereotype || eaElement.Stereotype == "TGGCsp")
            {
                SQLElement parentElement = repository.GetElementByID(eaElement.ParentID);
                if (parentElement.Stereotype != SDMModelingMain.StoryNodeStereotype)
                {
                    CSPInstance csp = new CSPInstance(repository, eaElement);
                    if (csp.loadTreeFromTaggedValue())
                    {
                        foreach (CSPInstanceEntry instance in csp.createdEntries)
                        {
                            foreach (Expression exp in instance.typedInExpressions)
                            {
                                if (!ConsistencyUtil.checkExpression(eaElement, exp, repository))
                                {
                                    results.Add("Tgg CSP expression is invalid: " + exp);
                                }
                            }
                        }
                    }
                    else
                    {
                        results.Add("Tgg CSP is outdated and maybe erroneous - updating it manually is recommended");
                    }
                }
            }
            else if (eaElement.Type == "Constraint")
            {
                results.Add("Tgg CSP is outdated and cant be modified - quickfix is recommended");
            }

            return(results);
        }
        private void addElementCopyToRule(EA.Element elementToBeCopied, EA.DiagramObject diagramObjectToBeCopied)
        {
            EA.Element newElement = newRuleElement.Elements.AddNew(elementToBeCopied.Name.Substring(0, 1).ToLower() + elementToBeCopied.Name.Substring(1, elementToBeCopied.Name.Length - 1), elementToBeCopied.Type) as EA.Element;
            newElement.Stereotype   = elementToBeCopied.Stereotype;
            newElement.ClassifierID = elementToBeCopied.ClassifierID;
            newElement.Notes        = elementToBeCopied.Notes;
            newElement.Update();

            newElementIdToNewElement.Add(newElement.ElementID, newElement);
            oldElementIdToNewElementId.Add(elementToBeCopied.ElementID, newElement.ElementID);

            foreach (EA.TaggedValue tags in elementToBeCopied.TaggedValues)
            {
                EA.TaggedValue newTag = newElement.TaggedValues.AddNew(tags.Name, "") as EA.TaggedValue;
                if (!checkBoxExactCopy.Checked)
                {
                    newTag.Value = tags.Value.Replace(elementToBeCopied.ElementGUID, newElement.ElementGUID).Replace("create", "check_only");
                    newTag.Notes = tags.Notes.Replace(elementToBeCopied.ElementGUID, newElement.ElementGUID).Replace("\"bindingOperator\" value=\"create", "\"bindingOperator\" value=\"check_only");
                }
                else
                {
                    newTag.Value = tags.Value;
                    newTag.Notes = tags.Notes;
                }
                newTag.Update();
            }

            EA.DiagramObject newDiagramObject = newRuleDiagram.DiagramObjects.AddNew("", newElement.Type) as EA.DiagramObject;
            newDiagramObject.ElementID = newElement.ElementID;
            newDiagramObject.left      = diagramObjectToBeCopied.left;
            newDiagramObject.right     = diagramObjectToBeCopied.right;
            newDiagramObject.top       = diagramObjectToBeCopied.top;
            newDiagramObject.bottom    = diagramObjectToBeCopied.bottom;
            newDiagramObject.Update();


            if (newElement.Stereotype == TGGModelingMain.TggObjectVariableStereotype)
            {
                TGGObjectVariable tggOv = new TGGObjectVariable(repository.GetElementByID(newElement.ElementID), repository);
                tggOv.loadTreeFromTaggedValue();
                if (!checkBoxExactCopy.Checked)
                {
                    tggOv.BindingOperator = SDMModeling.SDMExportWrapper.patterns.BindingOperator.CHECK_ONLY;
                    TGGModelingUtil.assignmentsToConstraints(tggOv, repository);
                }
                tggOv.saveTreeToEATaggedValue(true);
            }
            else if (newElement.Stereotype == TGGModelingMain.TggCorrespondenceStereotype)
            {
                TGGCorrespondence tggCorr = new TGGCorrespondence(repository.GetElementByID(newElement.ElementID), repository);
                tggCorr.loadTreeFromTaggedValue();
                if (!checkBoxExactCopy.Checked)
                {
                    tggCorr.BindingOperator = SDMModeling.SDMExportWrapper.patterns.BindingOperator.CHECK_ONLY;
                    TGGModelingUtil.assignmentsToConstraints(tggCorr, repository);
                }
                tggCorr.saveTreeToEATaggedValue(true);
            }
            else if (newElement.Stereotype == TGGModelingMain.CSPConstraintStereotype)
            {
                CSPInstance instance = new CSPInstance(repository, repository.GetElementByID(newElement.ElementID));
                instance.loadTreeFromTaggedValue();
                instance.saveTreeToEATaggedValue(true);
            }
        }
        private void importRule(SQLPackage modelPackage, MocaNode ruleNode)
        {
            EA.Element ruleElement = MainImport.getInstance().EcoreImport.getOrCreateElement(modelPackage, ruleNode, Main.EAClassType);

            if (ruleElement.Diagrams.Count == 0)
            {
                EA.Diagram ruleDiagram = ruleElement.Diagrams.AddNew(ruleElement.Name, TGGModelingMain.TggRuleDiagramMetatype[0]) as EA.Diagram;
                ruleDiagram.Update();
                MainImport.getInstance().DiagramsToBeFilled.Add(ruleDiagram);
            }

            EA.Method mainMethod = MainImport.getInstance().EcoreImport.getOrCreateMethod(sqlRep.GetElementByID(ruleElement.ElementID), ruleNode.getAttributeOrCreate("mainMethodGuid").Value, ruleElement.Name, "");

            MocaNode parametersNode = ruleNode.getChildNodeWithName(EOperation.ParametersChildNodeName);

            if (parametersNode != null)
            {
                foreach (MocaNode paramNode in parametersNode.Children)
                {
                    EA.Parameter parameter = MainImport.getInstance().EcoreImport.getOrCreateParameter(mainMethod, paramNode);

                    MainImport.getInstance().OldGuidToNewGuid.Add(paramNode.getAttributeOrCreate(Main.GuidStringName).Value, parameter.ParameterGUID);
                }
            }

            EClass eClass = MainImport.getInstance().EcoreImport.importEClassFeatures(ruleNode, sqlRep.GetElementByID(ruleElement.ElementID));

            MainImport.getInstance().MocaTaggableElements.Remove(eClass);
            TGGRule rule = new TGGRule(sqlRep, sqlRep.GetElementByID(ruleElement.ElementID));

            rule.deserializeFromMocaTree(ruleNode);

            MainImport.getInstance().MocaTaggableElements.Add(rule);

            foreach (MocaNode ovNode in ruleNode.getChildNodeWithName(StoryPattern.ObjectVariablesChildNodeName).Children)
            {
                if (ovNode.Name == TGGModelingMain.TggObjectVariableStereotype)
                {
                    ObjectVariable ov = MainImport.getInstance().SdmImport.importObjectVariable(sqlRep.GetElementByID(ruleElement.ElementID), ovNode);
                    MainImport.getInstance().MocaTaggableElements.Remove(ov);
                    ov = new TGGObjectVariable(ov.sqlElement, sqlRep);
                    ov.deserializeFromMocaTree(ovNode);
                    MainImport.getInstance().MocaTaggableElements.Add(ov);
                }
                else if (ovNode.Name == TGGCorrespondence.CorrespondenceNodeName)
                {
                    ObjectVariable ov = MainImport.getInstance().SdmImport.importObjectVariable(sqlRep.GetElementByID(ruleElement.ElementID), ovNode);
                    MainImport.getInstance().MocaTaggableElements.Remove(ov);
                    ov = new TGGCorrespondence(ov.sqlElement, sqlRep);
                    ov.deserializeFromMocaTree(ovNode);
                    MainImport.getInstance().MocaTaggableElements.Add(ov);
                }
            }

            MocaNode cspsNode = ruleNode.getChildNodeWithName(TGGRule.CspsChildNodeName);

            if (cspsNode != null)
            {
                foreach (MocaNode cspInstanceNode in cspsNode.Children)
                {
                    importTGGCSP(sqlRep.GetElementByID(ruleElement.ElementID), cspInstanceNode);
                }
            }
            else
            {
                if (ruleNode.getAttributeOrCreate(TGGRule.CspSpecAttributeName).Value != "")
                {
                    EA.Element constraintElement = ruleElement.Elements.AddNew("", Main.EAClassType) as EA.Element;
                    constraintElement.Stereotype = TGGModelingMain.CSPConstraintStereotype;
                    constraintElement.Notes      = ruleNode.getAttributeOrCreate(TGGRule.CspSpecAttributeName).Value;
                    constraintElement.Update();

                    CSPInstance cspInstance = new CSPInstance(sqlRep, sqlRep.GetElementByID(constraintElement.ElementID));
                    cspInstance.CspStringValueFromImport = ruleNode.getAttributeOrCreate(TGGRule.CspSpecAttributeName).Value;
                    MainImport.getInstance().MocaTaggableElements.Add(cspInstance);
                }
            }
        }