Example #1
0
        /// <summary>
        /// Sets the common <see cref="AttributeValue"/>
        /// </summary>
        /// <param name="elementWithAttributes">The <see cref="SpecElementWithAttributes"/> to modify</param>
        /// <param name="thing">The associated <see cref="ICategorizableThing"/></param>
        private void SetCommonAttributeValues(SpecElementWithAttributes elementWithAttributes, ICategorizableThing thing)
        {
            var shortNameType = (AttributeDefinitionString)elementWithAttributes.SpecType.SpecAttributes.Single(x => x.DatatypeDefinition == this.TextDatatypeDefinition && x.LongName == ShortNameAttributeDefName);
            var nameType      = (AttributeDefinitionString)elementWithAttributes.SpecType.SpecAttributes.Single(x => x.DatatypeDefinition == this.TextDatatypeDefinition && x.LongName == NameAttributeDefName);
            var categoryType  = (AttributeDefinitionString)elementWithAttributes.SpecType.SpecAttributes.Single(x => x.DatatypeDefinition == this.TextDatatypeDefinition && x.LongName == CategoryAttributeDefName);

            var castthing = (Thing)thing;

            // Add shortname
            var shortname = new AttributeValueString
            {
                TheValue   = castthing.UserFriendlyShortName ?? string.Empty,
                Definition = shortNameType
            };

            elementWithAttributes.Values.Add(shortname);

            // Add name
            var name = new AttributeValueString
            {
                TheValue   = castthing.UserFriendlyName ?? string.Empty,
                Definition = nameType
            };

            elementWithAttributes.Values.Add(name);

            // Add Category
            var category = new AttributeValueString
            {
                TheValue   = thing.Category.Any() ? string.Join(", ", thing.Category.Select(x => x.ShortName)) : emptyContent,
                Definition = categoryType
            };

            elementWithAttributes.Values.Add(category);
        }
Example #2
0
        public void Verify_That_Exception_Is_Raised_When_Invalid_AttributeDefinition_Is_Set()
        {
            var attributeDefinitionString = new AttributeDefinitionReal();
            var attributeValueString      = new AttributeValueString();
            var attributeValue            = (AttributeValue)attributeValueString;

            Assert.Throws <ArgumentException>(() => attributeValue.AttributeDefinition = attributeDefinitionString);
        }
Example #3
0
        public void VerifytThatExceptionIsRaisedWhenInvalidAttributeDefinitionIsSet()
        {
            var attributeDefinitionString = new AttributeDefinitionReal();
            var attributeValueString      = new AttributeValueString();
            var attributeValue            = (AttributeValue)attributeValueString;

            Assert.Throws <ArgumentException>(() => attributeValue.AttributeDefinition = attributeDefinitionString);
        }
Example #4
0
        protected Node(Graph parent)
        {
            Parent = parent;
            Parent.AddNode(this);

            _description = new AttributeValueString(this, "Description");
            _name        = new AttributeValueString(this, "Name");
            _name.SetReadOnly();
        }
Example #5
0
        public void Verify_That_WriteXml_Without_Definition_Set_Throws_SerializationException()
        {
            using var memoryStream = new MemoryStream();
            using var writer       = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true });
            var attributeValueString = new AttributeValueString();

            Assert.That(() => attributeValueString.WriteXml(writer),
                        Throws.Exception.TypeOf <SerializationException>());
        }
Example #6
0
        public void VerifyConvenienceValueProperty()
        {
            var attributeValue = new AttributeValueString();

            var val = "test";

            attributeValue.ObjectValue = val;

            Assert.AreEqual(attributeValue.TheValue, val);
        }
Example #7
0
        public Graph()
        {
            OsClock = new PerformanceCounter();
            _proc   = new GraphProcessor(this);

            _attrWorkingDirMask          = new AttributeValueString(this, "WorkingDirMask");
            _attrWorkingDirMask.Changed += (o, e) => _ctx.WorkingDirectoryMask = _attrWorkingDirMask.TypedGet();

            _attrFileMask          = new AttributeValueString(this, "FileMask");
            _attrFileMask.Changed += (o, e) => _ctx.FileMask = _attrFileMask.TypedGet();
        }
Example #8
0
 public void VerifyThatWriteXmlWithoutDefinitionSetThrowsSerializationException()
 {
     using (var fs = new FileStream("test.xml", FileMode.Create))
     {
         using (var writer = XmlWriter.Create(fs, new XmlWriterSettings {
             Indent = true
         }))
         {
             var attributeValueString = new AttributeValueString();
             Assert.Throws <SerializationException>(() => attributeValueString.WriteXml(writer));
         }
     }
 }
        private void AddAttributeButton_Click(object sender, RoutedEventArgs e)
        {
            var dataGridRowIndex = ((sender as Button).BindingGroup.Owner as DataGridRow).GetIndex();
            AttributeDefinition selectedAttribute = _attributes[dataGridRowIndex].AttributeDefinition;
            AttributeValue      attributeValue    = null;

            if (selectedAttribute.GetType() == typeof(AttributeDefinitionBoolean))
            {
                attributeValue             = new AttributeValueBoolean();
                attributeValue.ObjectValue = false;
            }
            else if (selectedAttribute.GetType() == typeof(AttributeDefinitionDate))
            {
                attributeValue             = new AttributeValueDate();
                attributeValue.ObjectValue = DateTime.Now;
            }
            else if (selectedAttribute.GetType() == typeof(AttributeDefinitionEnumeration))
            {
                attributeValue = new AttributeValueEnumeration();
                List <EnumValue> enumValues = new List <EnumValue>();
                enumValues.Add(((DatatypeDefinitionEnumeration)selectedAttribute.DatatypeDefinition).SpecifiedValues.First());
                attributeValue.ObjectValue = enumValues;
            }
            else if (selectedAttribute.GetType() == typeof(AttributeDefinitionInteger))
            {
                attributeValue             = new AttributeValueInteger();
                attributeValue.ObjectValue = "";
            }
            else if (selectedAttribute.GetType() == typeof(AttributeDefinitionReal))
            {
                attributeValue             = new AttributeValueReal();
                attributeValue.ObjectValue = "";
            }
            else if (selectedAttribute.GetType() == typeof(AttributeDefinitionString))
            {
                attributeValue             = new AttributeValueString();
                attributeValue.ObjectValue = "";
            }
            else if (selectedAttribute.GetType() == typeof(AttributeDefinitionXHTML))
            {
                attributeValue             = new AttributeValueXHTML();
                attributeValue.ObjectValue = "<div></div>";
            }
            attributeValue.AttributeDefinition           = selectedAttribute;
            attributeValue.SpecElAt                      = (Application.Current.MainWindow as MainWindow).content.SpecObjects.SingleOrDefault(x => x.Identifier == _specObject.Identifier);
            _attributes[dataGridRowIndex].AttributeValue = attributeValue;
            _attributes[dataGridRowIndex].added          = true;
        }
Example #10
0
        public void VerifyThatTheAttributeDefinitionCanBeSetOrGet()
        {
            var attributeDefinitionString = new AttributeDefinitionString();

            var attributeValueString = new AttributeValueString();

            attributeValueString.Definition = attributeDefinitionString;

            var attributeValue = (AttributeValue)attributeValueString;

            Assert.AreEqual(attributeDefinitionString, attributeValue.AttributeDefinition);

            attributeValue.AttributeDefinition = attributeDefinitionString;

            Assert.AreEqual(attributeDefinitionString, attributeValue.AttributeDefinition);
        }
Example #11
0
        public void Verify_That_The_AttributeDefinition_Can_Be_Set_Or_Get()
        {
            var attributeDefinitionString = new AttributeDefinitionString();

            var attributeValueString = new AttributeValueString();

            attributeValueString.Definition = attributeDefinitionString;

            var attributeValue = (AttributeValue)attributeValueString;

            Assert.AreEqual(attributeDefinitionString, attributeValue.AttributeDefinition);

            attributeValue.AttributeDefinition = attributeDefinitionString;

            Assert.AreEqual(attributeDefinitionString, attributeValue.AttributeDefinition);
        }
Example #12
0
        /// <summary>
        /// Returns the <see cref="SpecObject"/> representation of a <see cref="Requirement"/>
        /// </summary>
        /// <param name="requirement">The <see cref="Requirement"/></param>
        /// <param name="specObjectType">The associated <see cref="SpecObjectType"/></param>
        /// <returns>The associated <see cref="SpecObject"/></returns>
        public SpecObject ToReqIfSpecObject(Requirement requirement, SpecObjectType specObjectType)
        {
            if (requirement == null)
            {
                throw new ArgumentNullException("requirement");
            }

            var specObject = new SpecObject();

            this.SetIdentifiableProperties(specObject, requirement);
            specObject.Type = specObjectType;

            this.SetCommonAttributeValues(specObject, requirement);

            foreach (var parameterValue in requirement.ParameterValue)
            {
                var attributeDef = specObjectType.SpecAttributes.Single(x => x.DatatypeDefinition.Identifier == parameterValue.ParameterType.Iid.ToString());
                var value        = this.ToReqIfAttributeValue(parameterValue.ParameterType, attributeDef, parameterValue.Value, parameterValue.Scale);
                specObject.Values.Add(value);
            }

            // Add extra AttributeValue corresponding to the requirement text
            if (requirement.Definition.Any())
            {
                var definition          = requirement.Definition.First();
                var attributeDefinition = (AttributeDefinitionString)specObjectType.SpecAttributes.Single(def => def.DatatypeDefinition == this.TextDatatypeDefinition && def.LongName == RequirementTextAttributeDefName);
                var requirementValue    = new AttributeValueString
                {
                    TheValue   = definition.Content,
                    Definition = attributeDefinition
                };

                specObject.Values.Add(requirementValue);
            }

            // Add extra AttributeValue corresponding to the isDeprecated property
            var isDeprecatedType = (AttributeDefinitionBoolean)specObjectType.SpecAttributes.Single(def => def.DatatypeDefinition == this.BooleanDatatypeDefinition && def.LongName == IsDeprecatedAttributeDefName);
            var isDeprecated     = new AttributeValueBoolean
            {
                TheValue   = requirement.IsDeprecated,
                Definition = isDeprecatedType
            };

            specObject.Values.Add(isDeprecated);

            return(specObject);
        }
        /// <summary>
        /// Create <see cref="AttributeValue"/> For <see cref="SpecElementWithAttributes"/>
        /// </summary>
        /// <param name="specElementWithAttributes">
        /// The <see cref="SpecElementWithAttributes"/> to which <see cref="AttributeValue"/>s need to be added.
        /// </param>
        /// <param name="specType">
        /// The <see cref="SpecType"/> of the <see cref="specElementWithAttributes"/>
        /// </param>
        private void CreateValuesForSpecElementWithAttributes(SpecElementWithAttributes specElementWithAttributes, SpecType specType)
        {
            var attributeValueBoolean = new AttributeValueBoolean();

            attributeValueBoolean.Definition = (AttributeDefinitionBoolean)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionBoolean));
            attributeValueBoolean.TheValue   = true;
            specElementWithAttributes.Values.Add(attributeValueBoolean);

            var attributeValueDate = new AttributeValueDate();

            attributeValueDate.Definition = (AttributeDefinitionDate)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionDate));
            attributeValueDate.TheValue   = XmlConvert.ToDateTime("2015-12-01", XmlDateTimeSerializationMode.Utc);
            specElementWithAttributes.Values.Add(attributeValueDate);

            var attributeValueEnumeration = new AttributeValueEnumeration();

            attributeValueEnumeration.Definition = (AttributeDefinitionEnumeration)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionEnumeration));
            var enumValue = attributeValueEnumeration.Definition.Type.SpecifiedValues.FirstOrDefault();

            attributeValueEnumeration.Values.Add(enumValue);
            specElementWithAttributes.Values.Add(attributeValueEnumeration);

            var attributeValueInteger = new AttributeValueInteger();

            attributeValueInteger.Definition = (AttributeDefinitionInteger)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionInteger));
            attributeValueInteger.TheValue   = 1;
            specElementWithAttributes.Values.Add(attributeValueInteger);

            var attributeValueReal = new AttributeValueReal();

            attributeValueReal.Definition = (AttributeDefinitionReal)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionReal));
            attributeValueReal.TheValue   = 100;
            specElementWithAttributes.Values.Add(attributeValueReal);

            var attributeValueString = new AttributeValueString();

            attributeValueString.Definition = (AttributeDefinitionString)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionString));
            attributeValueString.TheValue   = "a string value";
            specElementWithAttributes.Values.Add(attributeValueString);

            var attributeValueXhtml = new AttributeValueXHTML();

            attributeValueXhtml.Definition = (AttributeDefinitionXHTML)specType.SpecAttributes.SingleOrDefault(x => x.GetType() == typeof(AttributeDefinitionXHTML));
            attributeValueXhtml.TheValue   = this.xhtmlcontent;
            specElementWithAttributes.Values.Add(attributeValueXhtml);
        }
Example #14
0
        public void Verify_That_WriteXmlAsync_Throws_Exception_when_cancelled()
        {
            using var memoryStream = new MemoryStream();
            using var writer       = XmlWriter.Create(memoryStream, new XmlWriterSettings { Indent = true });

            var attributeValueString = new AttributeValueString
            {
                Definition = new AttributeDefinitionString()
            };

            var cts = new CancellationTokenSource();

            cts.Cancel();

            Assert.That(
                async() => await attributeValueString.WriteXmlAsync(writer, cts.Token),
                Throws.Exception.TypeOf <OperationCanceledException>());
        }
        private void SetupReqIf()
        {
            this.reqIf             = new ReqIF();
            this.reqIf.Lang        = "en";
            this.corecontent       = new ReqIFContent();
            this.reqIf.CoreContent = this.corecontent;
            this.stringDatadef     = new DatatypeDefinitionString();
            this.specificationtype = new SpecificationType();
            this.specobjecttype    = new SpecObjectType();
            this.specrelationtype  = new SpecRelationType();
            this.relationgrouptype = new RelationGroupType();

            this.specAttribute = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };

            this.reqAttribute = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };
            this.specRelationAttribute = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };
            this.relationgroupAttribute = new AttributeDefinitionString()
            {
                DatatypeDefinition = this.stringDatadef
            };

            this.specificationtype.SpecAttributes.Add(this.specAttribute);
            this.specobjecttype.SpecAttributes.Add(this.reqAttribute);
            this.specrelationtype.SpecAttributes.Add(this.specRelationAttribute);
            this.relationgrouptype.SpecAttributes.Add(this.relationgroupAttribute);

            this.specification1 = new Specification()
            {
                Type = this.specificationtype
            };
            this.specification2 = new Specification()
            {
                Type = this.specificationtype
            };

            this.specobject1 = new SpecObject()
            {
                Type = this.specobjecttype
            };
            this.specobject2 = new SpecObject()
            {
                Type = this.specobjecttype
            };

            this.specrelation = new SpecRelation()
            {
                Type = this.specrelationtype, Source = this.specobject1, Target = this.specobject2
            };
            this.relationgroup = new RelationGroup()
            {
                Type = this.relationgrouptype, SourceSpecification = this.specification1, TargetSpecification = this.specification2
            };

            this.specValue1 = new AttributeValueString()
            {
                AttributeDefinition = this.specAttribute, TheValue = "spec1"
            };
            this.specValue2 = new AttributeValueString()
            {
                AttributeDefinition = this.specAttribute, TheValue = "spec2"
            };
            this.objectValue1 = new AttributeValueString()
            {
                AttributeDefinition = this.reqAttribute, TheValue = "req1"
            };
            this.objectValue2 = new AttributeValueString()
            {
                AttributeDefinition = this.reqAttribute, TheValue = "req2"
            };
            this.relationgroupValue = new AttributeValueString()
            {
                AttributeDefinition = this.relationgroupAttribute, TheValue = "group"
            };
            this.specrelationValue = new AttributeValueString()
            {
                AttributeDefinition = this.specRelationAttribute, TheValue = "specrelation"
            };

            this.specification1.Values.Add(this.specValue1);
            this.specification2.Values.Add(this.specValue2);
            this.specobject1.Values.Add(this.objectValue1);
            this.specobject2.Values.Add(this.objectValue2);
            this.specrelation.Values.Add(this.specrelationValue);
            this.relationgroup.Values.Add(this.relationgroupValue);

            this.corecontent.DataTypes.Add(this.stringDatadef);
            this.corecontent.SpecTypes.AddRange(new SpecType[] { this.specobjecttype, this.specificationtype, this.specrelationtype, this.relationgrouptype });
            this.corecontent.SpecObjects.AddRange(new SpecObject[] { this.specobject1, this.specobject2 });
            this.corecontent.Specifications.AddRange(new Specification[] { this.specification1, this.specification2 });
            this.corecontent.SpecRelations.Add(this.specrelation);
            this.corecontent.SpecRelationGroups.Add(this.relationgroup);

            this.specification1.Children.Add(new SpecHierarchy()
            {
                Object = this.specobject1
            });
            this.specification2.Children.Add(new SpecHierarchy()
            {
                Object = this.specobject2
            });
        }
        /// <summary>
        /// Change ReqIF value of the specObject and the attribute value. The Attribute must be part of the ReqIF file.
        /// </summary>
        /// <param name="specObject"></param>
        /// <param name="name"></param>
        /// <param name="eaValue"></param>
        /// <param name="caseSensitive"></param>
        /// <returns></returns>
        private bool RoundtripChangeValueReqIf(SpecObject specObject, string name, string eaValue, bool caseSensitive = false)
        {
            try
            {
                AttributeValue attrValueObject = caseSensitive
                    ? specObject.Values.SingleOrDefault(x => x.AttributeDefinition.LongName == name)
                    : specObject.Values.SingleOrDefault(x =>
                                                        x.AttributeDefinition.LongName.ToLower() == name.ToLower());
                // Attribute not part of ReqIF, skip
                if (attrValueObject == null)
                {
                    // Create AttributValue and assign them to values.
                    AttributeDefinition attributeType =
                        _moduleAttributeDefinitions.SingleOrDefault(x => x.LongName.ToLower() == name.ToLower());
                    switch (attributeType)
                    {
                    case AttributeDefinitionString _:
                        attrValueObject = new AttributeValueString
                        {
                            AttributeDefinition = attributeType
                        };
                        break;

                    case AttributeDefinitionXHTML _:
                        attrValueObject = new AttributeValueXHTML
                        {
                            AttributeDefinition = attributeType
                        };
                        break;

                    case AttributeDefinitionEnumeration moduleAttributDefinitionEnumeration:
                        attrValueObject = new AttributeValueEnumeration
                        {
                            AttributeDefinition = attributeType
                        };
                        break;
                    }

                    if (attrValueObject == null)
                    {
                        return(true);                         // not supported datatype
                    }
                    specObject.Values.Add(attrValueObject);
                }

                var attrType = attrValueObject.AttributeDefinition; //specObj.Values[0].AttributeDefinition.LongName;
                switch (attrType)
                {
                case AttributeDefinitionXHTML _:
                    // make xhtml and handle new line
                    var xhtmlcontent = MakeXhtmlFromString(eaValue);
                    attrValueObject.ObjectValue = xhtmlcontent;
                    break;

                case AttributeDefinitionString _:
                    attrValueObject.ObjectValue = eaValue;
                    break;

                case AttributeDefinitionEnumeration _:

                    try
                    {
                        // take all the valid enums
                        if (!SetReqIfEnumValue((AttributeValueEnumeration)attrValueObject, eaValue))
                        {
                            return(false);
                        }
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show($@"Name: '{name}'

Value: '{eaValue}'

{e}", $@"Error enumeration value TV '{name}'.");
                    }

                    break;
                }

                return(true);
            }
            catch (Exception e)
            {
                MessageBox.Show($@"Name: '{name}'

Value: '{eaValue}'

{e}", $@"Error value TV '{name}'.");
                return(false);
            }
        }
Example #17
0
 public MatlabNode(Graph g) : base("Matlab", g)
 {
     _attrFuncName          = new AttributeValueString(this, "Scriptname");
     _attrFuncName.Changed += _attrFuncName_Changed;
     _attrFuncName.SetRuntimeReadonly();
 }
 public PropertyRowNodeAttrString(AttributeValueString attr)
 {
     _attr          = attr;
     _attr.Changed += (s, e) => Changed?.Invoke(this, new PropertyGridRowChangedEventArgs());
 }