/// <summary>
        ///     Copies the element to another content class by creating a new element and copying the attribute values to it.
        ///     Make sure to set the language variant in the target project into which the element should be copied, first.
        /// </summary>
        /// <param name="contentClass"> target content class, into which the element should be copied </param>
        /// <returns> the created copy </returns>
        /// <remarks>
        ///     <list type="bullet">
        ///         <item>
        ///             <description>Override this method, if you need to set other values than the direct attributes of the element (e.g. setting text values of TextHtml elements)</description>
        ///         </item>
        ///         <item>
        ///             <description>
        ///                 The target content class is only modified on the server, thus the content class object does not contain the newly created element.
        ///                 If you need an updated version of the content class, you have to retrieve it again with
        ///                 <code>new ContentClass(Project, Guid);</code>
        ///             </description>
        ///         </item>
        ///     </list>
        /// </remarks>
        public IContentClassElement CopyToContentClass(IContentClass contentClass)
        {
            var newContentClassElement = CreateElement(contentClass, Type);
            var assign = new AttributeAssignment();

            assign.AssignAllRedDotAttributesForLanguage(this, newContentClassElement,
                                                        Project.LanguageVariants.Current.Abbreviation);

            var node = (XmlElement)newContentClassElement.XmlElement.Clone();

            node.Attributes.RemoveNamedItem("guid");
            string creationString = GetSaveString(node);

            // <summary>
            // RQL for creating an element from a content class.
            // Two parameters:
            // 1. Content class guid
            // 2. Element to create, make sure it contains an attribute "action" with the value "save"!
            // </summary>
            const string CREATE_ELEMENT = @"<TEMPLATE guid=""{0}"">{1}</TEMPLATE>";

            XmlDocument rqlResult =
                contentClass.Project.ExecuteRQL(string.Format(CREATE_ELEMENT, contentClass.Guid.ToRQLString(),
                                                              creationString));
            var resultElementNode = (XmlElement)rqlResult.GetElementsByTagName("ELEMENT")[0];

            if (resultElementNode == null)
            {
                throw new SmartAPIException(Session.ServerLogin,
                                            string.Format("Error during creation of element {0}", this));
            }
            newContentClassElement.Guid = resultElementNode.GetGuid();

            return(newContentClassElement);
        }
Пример #2
0
        public void listBoxSelectedIndexChangedNew(object sender, EventArgs e)
        {
            if (listboxEntries.SelectedIndex != -1)
            {
                Object assignmentOrConstraint = this.assignmentsAndConstraints[listboxEntries.SelectedIndex];

                if (assignmentOrConstraint is AttributeAssignment)
                {
                    AttributeAssignment attAss = assignmentOrConstraint as AttributeAssignment;
                    String leftAttributeName   = attAss.AttributeName;
                    String expressionName      = attAss.ValueExpression.GetType().Name;
                    cmbAttributes.Text = leftAttributeName;
                    radioSet.Checked   = true;
                }
                else if (assignmentOrConstraint is EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint)
                {
                    EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint constraint = assignmentOrConstraint as EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint;
                    String leftAttributeName = ((constraint.ConstraintExpression as ComparisonExpression).LeftExpression as AttributeValueExpression).AttributeName;
                    String expressionName    = (constraint.ConstraintExpression as ComparisonExpression).RightExpression.GetType().Name;
                    cmbAttributes.Text = leftAttributeName;

                    ComparisonExpression compExp = constraint.ConstraintExpression as ComparisonExpression;
                    if (compExp.Operator == ComparingOperator.EQUAL)
                    {
                        radioEqual.Checked = true;
                    }
                    else if (compExp.Operator == ComparingOperator.GREATER)
                    {
                        radioGreater.Checked = true;
                    }
                    else if (compExp.Operator == ComparingOperator.GREATER_OR_EQUAL)
                    {
                        radioGreaterEqual.Checked = true;
                    }
                    else if (compExp.Operator == ComparingOperator.LESS)
                    {
                        radioLess.Checked = true;
                    }
                    else if (compExp.Operator == ComparingOperator.LESS_OR_EQUAL)
                    {
                        radioLessEqual.Checked = true;
                    }
                    else if (compExp.Operator == ComparingOperator.UNEQUAL)
                    {
                        radioNotEqual.Checked = true;
                    }
                }

                this.ConstraintExpressionProvider = new AttributeConstraintExpressionProvider(assignmentOrConstraint, objectVariable, repository, this.OvExpressionProvider);
                expressionControl.setVisualOutput(this.ConstraintExpressionProvider, ConstraintExpressionProvider.getProviderExpression());
            }
        }
Пример #3
0
        public static void constraintsToAssignments(ObjectVariable ov, SQLRepository repository)
        {
            foreach (Constraint constraint in ov.Constraints)
            {
                AttributeAssignment assignment = new AttributeAssignment(repository);
                assignment.ValueExpression = (constraint.ConstraintExpression as ComparisonExpression).RightExpression;

                AttributeValueExpression left = (constraint.ConstraintExpression as ComparisonExpression).LeftExpression as AttributeValueExpression;

                assignment.AttributeGUID = left.AttributeGUID;
                assignment.AttributeName = left.AttributeName;

                ov.AttributeAssignments.Add(assignment);
            }
            ov.Constraints.Clear();
        }
Пример #4
0
        public static Boolean checkAttributeAssignment(SQLElement ovElement, AttributeAssignment attrAssignment, SQLRepository repository)
        {
            SQLAttribute attribute = repository.GetAttributeByGuid(attrAssignment.AttributeGUID);

            //attribute not existing
            if (attribute == null)
            {
                return(false);
            }


            Boolean attributeParentValid = checkIfClassifierContainsAttribute(repository.GetElementByGuid(attrAssignment.OvGuid), repository, attribute);

            if (!attributeParentValid)
            {
                return(attributeParentValid);
            }

            return(checkExpression(ovElement, attrAssignment.ValueExpression, repository));
        }
Пример #5
0
        private void CopyAttributesToCC(IContentClass targetCC)
        {
            var assignment = new AttributeAssignment();

            assignment.AssignAllLanguageIndependentRedDotAttributes(EditableAreaSettings, targetCC.EditableAreaSettings);

            targetCC.EditableAreaSettings.Commit();
            targetCC.Refresh();
            try
            {
                assignment.AssignAllLanguageIndependentRedDotAttributes(this, targetCC);
            } catch (AttributeChangeException e)
            {
                throw new SmartAPIException(Session.ServerLogin,
                                            string.Format(
                                                "Unable to assign attribute {0} in content class {1} of project {2} to content class {3} of project {4}",
                                                e.AttributeName, Name, Project.Name, targetCC.Name,
                                                targetCC.Project.Name), e);
            }
            targetCC.Commit();
        }
Пример #6
0
        /// <summary>
        ///     Copy selected elements from this content class to another target content class.
        /// </summary>
        /// <param name="targetCC"> Target content class to copy the elements to </param>
        /// <param name="elementNames"> Names of the elements to copy </param>
        public void CopyElementsToContentClass(IContentClass targetCC, params string[] elementNames)
        {
            if (elementNames == null || elementNames.Length == 0)
            {
                return;
            }

            var createdElements = new Dictionary <string, IContentClassElement>();

            using (new LanguageContext(Project))
            {
                var assign = new AttributeAssignment();
                foreach (var languageVariant in Project.LanguageVariants)
                {
                    ILanguageVariant targetLanguageVariant =
                        targetCC.Project.LanguageVariants[languageVariant.Abbreviation];
                    foreach (var curElementName in elementNames)
                    {
                        IContentClassElement curTargetContentClassElement;
                        languageVariant.Select();
                        var curSourceContentClassElement = Elements[curElementName];
                        if (createdElements.TryGetValue(curElementName, out curTargetContentClassElement))
                        {
                            targetLanguageVariant.Select();
                            assign.AssignAllRedDotAttributesForLanguage(curSourceContentClassElement,
                                                                        curTargetContentClassElement,
                                                                        targetLanguageVariant.Abbreviation);
                            curTargetContentClassElement.CommitInCurrentLanguage();
                        }
                        else
                        {
                            targetLanguageVariant.Select();
                            curTargetContentClassElement = curSourceContentClassElement.CopyToContentClass(targetCC);
                            createdElements.Add(curElementName, curTargetContentClassElement);
                        }
                    }
                }
            }
        }
Пример #7
0
        private void CopyAttributesToCC(IContentClass targetCC)
        {
            var assignment = new AttributeAssignment();
            assignment.AssignAllLanguageIndependentRedDotAttributes(EditableAreaSettings, targetCC.EditableAreaSettings);

            targetCC.EditableAreaSettings.Commit();
            targetCC.Refresh();
            try
            {
                assignment.AssignAllLanguageIndependentRedDotAttributes(this, targetCC);
            } catch (AttributeChangeException e)
            {
                throw new SmartAPIException(Session.ServerLogin,
                                            string.Format(
                                                "Unable to assign attribute {0} in content class {1} of project {2} to content class {3} of project {4}",
                                                e.AttributeName, Name, Project.Name, targetCC.Name,
                                                targetCC.Project.Name), e);
            }
            targetCC.Commit();
        }
Пример #8
0
        /// <summary>
        ///     Copy selected elements from this content class to another target content class.
        /// </summary>
        /// <param name="targetCC"> Target content class to copy the elements to </param>
        /// <param name="elementNames"> Names of the elements to copy </param>
        public void CopyElementsToContentClass(IContentClass targetCC, params string[] elementNames)
        {
            if (elementNames == null || elementNames.Length == 0)
            {
                return;
            }

            var createdElements = new Dictionary<string, IContentClassElement>();
            using (new LanguageContext(Project))
            {
                var assign = new AttributeAssignment();
                foreach (var languageVariant in Project.LanguageVariants)
                {
                    ILanguageVariant targetLanguageVariant =
                        targetCC.Project.LanguageVariants[languageVariant.Abbreviation];
                    foreach (var curElementName in elementNames)
                    {
                        IContentClassElement curTargetContentClassElement;
                        languageVariant.Select();
                        var curSourceContentClassElement = Elements[curElementName];
                        if (createdElements.TryGetValue(curElementName, out curTargetContentClassElement))
                        {
                            targetLanguageVariant.Select();
                            assign.AssignAllRedDotAttributesForLanguage(curSourceContentClassElement,
                                                                        curTargetContentClassElement,
                                                                        targetLanguageVariant.Abbreviation);
                            curTargetContentClassElement.CommitInCurrentLanguage();
                        }
                        else
                        {
                            targetLanguageVariant.Select();
                            curTargetContentClassElement = curSourceContentClassElement.CopyToContentClass(targetCC);
                            createdElements.Add(curElementName, curTargetContentClassElement);
                        }
                    }
                }
            }
        }
Пример #9
0
        /// <summary>
        ///     Copies the element to another content class by creating a new element and copying the attribute values to it.
        ///     Make sure to set the language variant in the target project into which the element should be copied, first.
        /// </summary>
        /// <param name="contentClass"> target content class, into which the element should be copied </param>
        /// <returns> the created copy </returns>
        /// <remarks>
        ///     <list type="bullet">
        ///         <item>
        ///             <description>Override this method, if you need to set other values than the direct attributes of the element (e.g. setting text values of TextHtml elements)</description>
        ///         </item>
        ///         <item>
        ///             <description>
        ///                 The target content class is only modified on the server, thus the content class object does not contain the newly created element.
        ///                 If you need an updated version of the content class, you have to retrieve it again with
        ///                 <code>new ContentClass(Project, Guid);</code>
        ///             </description>
        ///         </item>
        ///     </list>
        /// </remarks>
        public IContentClassElement CopyToContentClass(IContentClass contentClass)
        {
            var newContentClassElement = CreateElement(contentClass, Type);
            var assign = new AttributeAssignment();
            assign.AssignAllRedDotAttributesForLanguage(this, newContentClassElement,
                                                        Project.LanguageVariants.Current.Abbreviation);

            var node = (XmlElement) newContentClassElement.XmlElement.Clone();
            node.Attributes.RemoveNamedItem("guid");
            string creationString = GetSaveString(node);

            // <summary>
            // RQL for creating an element from a content class.
            // Two parameters:
            // 1. Content class guid
            // 2. Element to create, make sure it contains an attribute "action" with the value "save"!
            // </summary>
            const string CREATE_ELEMENT = @"<TEMPLATE guid=""{0}"">{1}</TEMPLATE>";

            XmlDocument rqlResult =
                contentClass.Project.ExecuteRQL(string.Format(CREATE_ELEMENT, contentClass.Guid.ToRQLString(),
                                                              creationString));
            var resultElementNode = (XmlElement) rqlResult.GetElementsByTagName("ELEMENT")[0];
            if (resultElementNode == null)
            {
                throw new SmartAPIException(Session.ServerLogin,
                                            string.Format("Error during creation of element {0}", this));
            }
            newContentClassElement.Guid = resultElementNode.GetGuid();

            return newContentClassElement;
        }
Пример #10
0
        public void bttEdit_Click(object sender, EventArgs e)
        {
            int    selectedIndex = listboxEntries.SelectedIndex;
            String assignmentConstraintString = "";

            if (selectedIndex != -1)
            {
                //attributeAssignment
                if (radioSet.Checked && cmbAttributes.Text != "")
                {
                    SQLAttribute        leftAttribute   = this.leftAttributes[cmbAttributes.SelectedIndex] as SQLAttribute;
                    AttributeAssignment attAssignment   = new AttributeAssignment(repository, objectVariable, leftAttribute);
                    Expression          rightExpression = ConstraintExpressionProvider.getExpression();
                    if (rightExpression != null)
                    {
                        attAssignment.ValueExpression = rightExpression;
                        this.assignmentsAndConstraints.RemoveAt(selectedIndex);
                        this.assignmentsAndConstraints.Insert(selectedIndex, attAssignment);
                        assignmentConstraintString = attAssignment.ToString();
                    }
                }


                //constraint
                else if (!radioSet.Checked && cmbAttributes.Text != "")
                {
                    SQLAttribute leftAttribute = this.leftAttributes[cmbAttributes.SelectedIndex];
                    EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint constraint = new EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint(repository);

                    ComparisonExpression compExp           = new ComparisonExpression(repository);
                    ComparingOperator    comparingOperator = ComparingOperator.EQUAL;
                    if (radioEqual.Checked)
                    {
                        comparingOperator = ComparingOperator.EQUAL;
                    }
                    else if (radioGreater.Checked)
                    {
                        comparingOperator = ComparingOperator.GREATER;
                    }
                    else if (radioLess.Checked)
                    {
                        comparingOperator = ComparingOperator.LESS;
                    }
                    else if (radioLessEqual.Checked)
                    {
                        comparingOperator = ComparingOperator.LESS_OR_EQUAL;
                    }
                    else if (radioNotEqual.Checked)
                    {
                        comparingOperator = ComparingOperator.UNEQUAL;
                    }
                    else if (radioGreaterEqual.Checked)
                    {
                        comparingOperator = ComparingOperator.GREATER_OR_EQUAL;
                    }
                    compExp.Operator       = comparingOperator;
                    compExp.LeftExpression = new AttributeValueExpression(repository, leftAttribute, objectVariable.sqlElement);
                    Expression rightExpression = ConstraintExpressionProvider.getExpression();
                    if (rightExpression != null)
                    {
                        compExp.RightExpression         = rightExpression;
                        constraint.ConstraintExpression = compExp;
                        this.assignmentsAndConstraints.RemoveAt(selectedIndex);
                        this.assignmentsAndConstraints.Insert(selectedIndex, constraint);
                        assignmentConstraintString = constraint.ToString();
                    }
                }
                internalAssignmentConstraintListToOVLists();
                addAssignmentsAndConstraintsToListboxNew();

                listboxEntries.SelectedItem = assignmentConstraintString;
            }
            this.expressionControl.setInformationLossPossible(false);
        }
Пример #11
0
        private void bttAdd_Click(object sender, EventArgs e)
        {
            String assignmentConstraintString = "";

            //attributeAssignment
            if (radioSet.Checked && cmbAttributes.Text != "")
            {
                SQLAttribute        leftAttribute   = this.leftAttributes[cmbAttributes.SelectedIndex] as SQLAttribute;
                AttributeAssignment attAssignment   = new AttributeAssignment(repository, this.objectVariable, leftAttribute);
                Expression          rightExpression = ConstraintExpressionProvider.getExpression();
                if (rightExpression != null)
                {
                    attAssignment.ValueExpression = rightExpression;
                    this.objectVariable.AttributeAssignments.Add(attAssignment);
                    String assignmentString = attAssignment.ToString();
                    listboxEntries.Items.Add(assignmentString);

                    assignmentConstraintString = assignmentString;
                }
            }

            //constraint
            else if (!radioSet.Checked && cmbAttributes.Text != "")
            {
                SQLAttribute leftAttribute = this.leftAttributes[cmbAttributes.SelectedIndex];
                EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint constraint = new EAEcoreAddin.Modeling.SDMModeling.SDMExportWrapper.patterns.Constraint(repository);

                ComparisonExpression compExp           = new ComparisonExpression(repository);
                ComparingOperator    comparingOperator = ComparingOperator.EQUAL;
                if (radioEqual.Checked)
                {
                    comparingOperator = ComparingOperator.EQUAL;
                }
                else if (radioGreater.Checked)
                {
                    comparingOperator = ComparingOperator.GREATER;
                }
                else if (radioLess.Checked)
                {
                    comparingOperator = ComparingOperator.LESS;
                }
                else if (radioLessEqual.Checked)
                {
                    comparingOperator = ComparingOperator.LESS_OR_EQUAL;
                }
                else if (radioNotEqual.Checked)
                {
                    comparingOperator = ComparingOperator.UNEQUAL;
                }
                else if (radioGreaterEqual.Checked)
                {
                    comparingOperator = ComparingOperator.GREATER_OR_EQUAL;
                }
                compExp.Operator = comparingOperator;

                compExp.LeftExpression = new AttributeValueExpression(repository, leftAttribute, objectVariable.sqlElement);
                Expression rightExpression = ConstraintExpressionProvider.getExpression();
                if (rightExpression != null)
                {
                    compExp.RightExpression         = rightExpression;
                    constraint.ConstraintExpression = compExp;
                    this.objectVariable.Constraints.Add(constraint);
                    String constraintString = constraint.ToString();
                    listboxEntries.Items.Add(constraintString);

                    assignmentConstraintString = constraintString;
                }
            }
            addAssignmentsAndConstraintsToListboxNew();

            if (assignmentConstraintString != "")
            {
                listboxEntries.SelectedItem = assignmentConstraintString;
                //listBoxSelectedIndexChangedNew(null, null);
            }
            this.expressionControl.setInformationLossPossible(false);
        }