public void CanUseAreControlsValid()
        {
            //asign
            var controlManager = new ControlManager();
            var xForm = new XForm();

            xForm.Root = new XContainer { Name = "BaseContainer" };

            var xAttribute = new XAttribute<string>("StringAttribute") { Name = "StringAttribute", Value = "StringAttribute", Use = XAttributeUse.Required };
            var xContainer = new XContainer { Name = "ChildContainer", Value = "ChildContainerValue", ParentContainer = xForm.Root, MaxOccurs = 1234, MinOccurs = 0 };
            xContainer.Attributes.Add(xAttribute);
            var xElement = new XElement { Name = "Element", Value = "ElementValue" };
            xContainer.Elements.Add(xElement);

            xForm.Root.Attributes.Add(xAttribute);
            xForm.Root.Containers.Add(xContainer);
            xForm.Root.Elements.Add(xElement);
            xContainer.Value = "test";

            //action
            controlManager.GetGroupBoxGui(xForm.Root, xForm.Root);
            var areControlsValid = controlManager.AreControlsValid();

            //assert
            Assert.False(areControlsValid);
        }
        public void CanUseSave()
        {
            //asign
            var controlManager = new ControlManager();
            var xContainer = new XContainer();
            xContainer.Value = "test";

            //action
            controlManager.GetGroupBoxGui(xContainer, xContainer);
            controlManager.Save();

            //assert
        }
Esempio n. 3
0
        /// <summary>
        /// Get XForm from given Xsd file.
        /// </summary>
        /// <param name="fileName">Path to Xsd file.</param>
        /// <returns></returns>
        public XForm ParseXsdFile(string fileName)
        {
            _xFormRoot = null;
            _lastContainer = null;

            var xmlSchema = LoadXmlSchema(fileName);

            foreach (XmlSchemaElement element in xmlSchema.Elements.Values)
            {
                BuildXForm(element, null);
            }

            var xForm = new XForm();
            xForm.Root = _xFormRoot;

            return xForm;
        }
Esempio n. 4
0
        /// <summary>
        /// Fill up given XContainer with data from Xml file.
        /// </summary>
        /// <param name="sourceContainer">Given XContainer to be filled up.</param>
        /// <param name="xmlDoc">Xml document contains data.</param>
        /// <returns>True if filling was successfull, false if not.</returns>
        private bool Fill(XContainer sourceContainer, XmlDocument xmlDoc)
        {
            var xmlNodeList = xmlDoc.GetElementsByTagName(sourceContainer.Name);

            if (xmlNodeList.Count > 0)
            {
                _newRoot = sourceContainer.Clone();
                _newRoot.Containers.Clear();
                ResolveAttributes(_newRoot, ((XmlElement)xmlNodeList[0]));
                ResolveElements(_newRoot, ((XmlElement)xmlNodeList[0]));
                _newRoot.Value = xmlNodeList[0].Value;
                _newRoot.Name = xmlNodeList[0].Name;

                foreach (var element in xmlNodeList[0].ChildNodes)
                {
                    if (!(element is XmlComment))
                    {
                        if (element is XmlText)
                        {
                            _newRoot.Value = ((XmlText)element).Value;
                        }

                        foreach (var xContainer in sourceContainer.Containers)
                        {
                            var name = ((XmlElement)element).Name;
                            if (xContainer.Name == name)
                            {
                                FillChildNodes(_newRoot, xContainer, (XmlElement)element);
                            }
                        }
                    }
                }

                return true;
            }

            return false;
        }
        public void CanUseGenerateGui()
        {
            //asign
            var controlManager = new ControlManager();
            var xForm = new XForm();

            xForm.Root = new XContainer { Name = "BaseContainer" };

            var xAttribute = new XAttribute<string>(string.Empty) { Name = "StringAttribute", Value = "StringAttribute", Use = XAttributeUse.Required };
            var xContainer = new XContainer { Name = "ChildContainer", Value = "ChildContainerValue", ParentContainer = xForm.Root, MaxOccurs = 1234, MinOccurs = 0 };
            xContainer.Attributes.Add(xAttribute);
            var xElement = new XElement { Name = "Element", Value = "ElementValue" };
            xContainer.Elements.Add(xElement);

            xForm.Root.Attributes.Add(xAttribute);
            xForm.Root.Containers.Add(xContainer);
            xForm.Root.Elements.Add(xElement);

            //action
            var groupBoxGui = controlManager.GetGroupBoxGui(xForm.Root, xForm.Root);

            //assert
            Assert.NotNull(groupBoxGui);
        }
Esempio n. 6
0
        public void CanParseXFormFromXmlFileDocumentumArchivageSettingsXsd()
        {
            //asign
            var xmlWriter = new XmlWriter();
            var xForm = new XForm();

            xForm.Root = new XContainer { Name = "BaseContainer" };

            var xAttribute = new XAttribute<string>(string.Empty) { Name = "StringAttribute", Value = "StringAttribute" };
            var xContainer = new XContainer { Name = "ChildContainer", Value = "ChildContainerValue", ParentContainer = xForm.Root };
            xContainer.Attributes.Add(xAttribute);
            var xElement = new XElement { Name = "Element", Value = "ElementValue" };
            xContainer.Elements.Add(xElement);

            xForm.Root.Attributes.Add(xAttribute);
            xForm.Root.Containers.Add(xContainer);
            xForm.Root.Elements.Add(xElement);

            var fileStream = new FileStream(@"testXml.txt", FileMode.OpenOrCreate);

            //action
            xmlWriter.WriteXFormToXmlFile(fileStream, xForm);

            //assert
            var xml = File.ReadAllText(@"testXml.txt");

            var resultXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n" +
            "<BaseContainer xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" StringAttribute=\"StringAttribute\">" +
            "\r\n  <Element>ElementValue</Element>" +
            "\r\n  <ChildContainer StringAttribute=\"StringAttribute\">ChildContainerValue" +
            "<Element>ElementValue</Element>" +
            "</ChildContainer>" +
            "\r\n</BaseContainer>";

            Assert.AreEqual(xml, resultXml);
        }
Esempio n. 7
0
        /// <summary>
        /// Fill up child nodes of XContainer.
        /// </summary>
        /// <param name="destinationContainer">XContainer used to copy structure to source container.</param>
        /// <param name="sourceContainer">Source container contained data.</param>
        /// <param name="xmlElement">Xml Element contains data.</param>
        private void FillChildNodes(XContainer destinationContainer, XContainer sourceContainer, XmlElement xmlElement)
        {
            var newContainer = sourceContainer.Clone();
            newContainer.Containers.Clear();
            ResolveAttributes(newContainer, xmlElement);
            ResolveElements(newContainer, xmlElement);

            newContainer.Name = xmlElement.Name;

            if (xmlElement.ChildNodes.Count == 1)
            {
                if (xmlElement.ChildNodes[0] is XmlText)
                {
                    newContainer.Value = xmlElement.InnerText;
                }
            }

            newContainer.ParentContainer = destinationContainer;
            newContainer.Id = newContainer.ParentContainer.Containers.Count + 1;
            newContainer.ParentContainer.Containers.Add(newContainer);

            foreach (var element in xmlElement.ChildNodes)
            {
                if (!(element is XmlComment))
                {
                    foreach (var xContainer in sourceContainer.Containers)
                    {
                        var name = ((XmlElement)element).Name;
                        if (xContainer.Name == name)
                        {
                            FillChildNodes(newContainer, xContainer, (XmlElement)element);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
 /// <summary>
 /// Fill given XContainer attributes with data form Xml file.
 /// </summary>
 /// <param name="container">XContainer to be filled up.</param>
 /// <param name="element">XmlElement with data.</param>
 private void ResolveElements(XContainer container, XmlElement element)
 {
     foreach (var containerElement in container.Elements)
     {
         foreach (var childElement in element.ChildNodes)
         {
             if (!(childElement is XmlComment))
             {
                 var name = ((XmlElement)childElement).Name;
                 if (containerElement.Name == name)
                 {
                     containerElement.Value = ((XmlElement)childElement).InnerText;
                 }
             }
         }
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Fill given XContainer attributes with data form Xml file.
        /// </summary>
        /// <param name="container">XContainer to be filled up.</param>
        /// <param name="xmlElement">XmlElement with data.</param>
        private void ResolveAttributes(XContainer container, XmlElement xmlElement)
        {
            if (xmlElement != null)
            {
                foreach (IXAttribute attribute in container.Attributes)
                {
                    string value = xmlElement.GetAttribute(attribute.Name);

                    if (!string.IsNullOrEmpty(value))
                    {
                        if (attribute is XAttribute<string>)
                        {
                            ((XAttribute<string>)attribute).Value = value;
                        }
                        else if (attribute is XAttribute<int>)
                        {
                            ((XAttribute<int>)attribute).Value = int.Parse(value);
                        }
                        else if (attribute is XAttribute<bool>)
                        {
                            ((XAttribute<bool>)attribute).Value = bool.Parse(value);
                        }
                        else if (attribute is XAttribute<DateTime>)
                        {
                            ((XAttribute<DateTime>)attribute).Value = DateTime.Parse(value);
                        }
                        else if (attribute is XEnumerationAttribute<string>)
                        {
                            ((XEnumerationAttribute<string>)attribute).Value = value;
                        }
                    }
                }
            }
        }
Esempio n. 10
0
        public void CanUseUpdateBindingForChildren()
        {
            //asign
            var controlManager = new ControlManager();
            var xForm = new XForm();

            xForm.Root = new XContainer { Name = "BaseContainer" };

            var xAttribute1 = new XAttribute<string>(string.Empty) { Name = "StringAttribute1", Value = "StringAttribute", Use = XAttributeUse.Required };
            var xAttribute2 = new XAttribute<int>(1) { Name = "StringAttribute2", Use = XAttributeUse.Required };
            var xAttribute3 = new XAttribute<bool>(true) { Name = "StringAttribute3", Use = XAttributeUse.Required };
            var xAttribute4 = new XAttribute<DateTime>(DateTime.Now) { Name = "StringAttribute4", Use = XAttributeUse.Required };
            var xAttribute5 = new XEnumerationAttribute<string>(string.Empty) { Name = "StringAttribute5", Use = XAttributeUse.Required };
            var xContainer = new XContainer { Name = "ChildContainer", Value = "ChildContainerValue", ParentContainer = xForm.Root, MaxOccurs = 1234, MinOccurs = 0 };
            xContainer.Attributes.Add(xAttribute1);
            var xElement = new XElement { Name = "Element", Value = "ElementValue" };
            xContainer.Elements.Add(xElement);

            xForm.Root.Attributes.Add(xAttribute1);
            xForm.Root.Attributes.Add(xAttribute2);
            xForm.Root.Attributes.Add(xAttribute3);
            xForm.Root.Attributes.Add(xAttribute4);
            xForm.Root.Attributes.Add(xAttribute5);
            xForm.Root.Containers.Add(xContainer);
            xForm.Root.Elements.Add(xElement);

            //action
            controlManager.GetGroupBoxGui(xForm.Root, xForm.Root);
            controlManager.UpdateBindingForVisibleContainer(xForm.Root);

            //assert
        }
Esempio n. 11
0
 /// <summary>
 /// Creates Label control from given XContainer.
 /// </summary>
 /// <param name="container">Given XContainer.</param>
 /// <returns>Label control according to given XContainer.</returns>
 internal Label GetLabel(XContainer container)
 {
     var label = new Label();
     label.AutoSize = true;
     label.Name = container.Name + "Label";
     label.Size = new Size(35, 13);
     label.TabIndex = 0;
     label.Text = container.Name;
     return label;
 }
Esempio n. 12
0
        /// <summary>
        /// Build new XForm from XmlSchema.
        /// </summary>
        /// <param name="xmlSchemaElement">Current XmlSchemaElement.</param>
        /// <param name="parent">Parent XContainer to keep parent reference.</param>
        private void BuildXForm(XmlSchemaElement xmlSchemaElement, XContainer parent)
        {
            var container = new XContainer();
            container.MaxOccurs = xmlSchemaElement.MaxOccurs;
            container.MinOccurs = xmlSchemaElement.MinOccurs;

            if (xmlSchemaElement.Parent is XmlSchemaGroupBase)
            {
                var xmlSchemaGroupBase = ((XmlSchemaGroupBase)xmlSchemaElement.Parent);

                if (!string.IsNullOrEmpty(xmlSchemaGroupBase.MaxOccursString))
                {
                    container.MaxOccurs = ((XmlSchemaGroupBase)xmlSchemaElement.Parent).MaxOccurs;
                    container.MinOccurs = ((XmlSchemaGroupBase)xmlSchemaElement.Parent).MinOccurs;
                }
            }

            container.ParentContainer = parent;
            container.Name = xmlSchemaElement.Name;

            container.Id = 1;

            var complexType = xmlSchemaElement.ElementSchemaType as XmlSchemaComplexType;
            var simpleType = xmlSchemaElement.ElementSchemaType as XmlSchemaSimpleType;

            if (simpleType != null)
            {
                var element = new XElement();
                element.Name = xmlSchemaElement.Name;
                _lastContainer.Elements.Add(element);

                //TODO IMPLEMENT ANOTHER RESTRICTION FACETS LIKE enumeration, maxExclusive, pattern, etc.
            }

            if (complexType != null)
            {
                // If the complex type has any attributes, get an enumerator
                // and write each attribute name to the container.
                if (complexType.AttributeUses.Count > 0)
                {
                    IDictionaryEnumerator enumerator = complexType.AttributeUses.GetEnumerator();

                    while (enumerator.MoveNext())
                    {
                        var attribute = (XmlSchemaAttribute)enumerator.Value;
                        var xAttribute = GetXAttribute(attribute);

                        container.Attributes.Add(xAttribute);
                    }
                }

                if (_xFormRoot == null)
                {
                    _xFormRoot = container;
                }
                else
                {
                    _lastContainer.Containers.Add(container);
                }

                //xs:all, xs:choice, xs:sequence
                if (complexType.ContentTypeParticle is XmlSchemaGroupBase)
                {

                    var baseParticle = complexType.ContentTypeParticle as XmlSchemaGroupBase;
                    foreach (XmlSchemaElement subParticle in baseParticle.Items)
                    {
                        _lastContainer = container;
                        BuildXForm(subParticle, container);
                    }
                }
                else
                {
                    //TODO IMPLEMENT ANOTHER XmlSchemaContentType

                    if (complexType.ContentType == XmlSchemaContentType.TextOnly)
                    {
                        container.Value = string.Empty;
                    }
                }
            }

            _lastContainer = null;
        }
Esempio n. 13
0
        public void GetLabelForXContainer()
        {
            //asign
            var xElement = new XContainer();
            xElement.Name = "XContainer";
            var controlFactory = new ControlFactory();

            //action
            var control = controlFactory.GetLabel(xElement);

            //assert
            Assert.NotNull(control);
            Assert.AreEqual(control.Name, xElement.Name + "Label");
        }