예제 #1
0
        public string GetValue(Control ctrl, XmlNode renderingDocument)
        {
            /*WARNING: This procedure assumes that GetWebControl uses 2 controls foreach schema element inside the sequence*/
            StringBuilder sb = new StringBuilder();

            Panel pn = (Panel)ctrl;
            int   schemaChildCount  = 0;
            int   childControlCount = 0;

            foreach (XmlNode n in renderingDocument.ChildNodes)
            {
                if (n.Name.StartsWith("xs_"))
                {
                    sb.Append(FieldsManager.GetInstance(n, namedSequence.Items[schemaChildCount], completeSchemas).GetValue(pn.Controls[childControlCount], n));
                    schemaChildCount++;
                    /*look at the assumption*/
                    childControlCount += 2;
                }
                else
                {
                    childControlCount++;
                }
            }
            return(sb.ToString());
        }
예제 #2
0
        public string GetValue(Control src, XmlNode renderingDocument)
        {
            UpdatePanel up = ((UpdatePanel)src);
            ChoicePanel cp = ((ChoicePanel)up.ContentTemplateContainer.Controls[0]);

            int schemaChildCount = 0;
            int controlCount     = 0;

            foreach (XmlNode n in renderingDocument.ChildNodes)
            {
                if (n.Name.StartsWith("xs_"))
                {
                    if (((RadioButton)cp.Controls[controlCount]).Checked)
                    {
                        return(FieldsManager.GetInstance(n, namedChoice.Items[schemaChildCount], schemas).GetValue(cp.Controls[controlCount + 1], n));
                    }
                    schemaChildCount++;
                    controlCount += 3;
                }
                else
                {
                    controlCount++;
                }
            }
            return("");
        }
예제 #3
0
        public string GetValue(Control ctrl, XmlNode renderingDocument)
        {
            /*if, once here, the getWebControl created a RepeaterPanel*/
            if (referredElement.MaxOccurs > 1)
            {
                string rs = "";

                RepeaterPanel    rp     = ((ctrl as UpdatePanel).ContentTemplateContainer.Controls[1] as RepeaterPanel);
                XmlSchemaElement newElm = new XmlSchemaElement();
                newElm.Name           = referredElement.Name;
                newElm.SchemaType     = referredElement.SchemaType;
                newElm.SchemaTypeName = referredElement.SchemaTypeName;
                newElm.IsNillable     = referredElement.IsNillable;

                foreach (Control ct in rp.RepeatedItems())
                {
                    rs += FieldsManager.GetInstance(renderingDocument, newElm, schemas).GetValue(ct, renderingDocument);
                }
                return(rs);
            }
            /*else there was just a standard complexType inside the <element> */
            else
            {
                Panel pn = ctrl as Panel;
                /*i create a node with the element name with inside the value of my child (complexType)*/
                return("<" + referredElement.Name + ">"
                       + FieldsManager.GetInstance(renderingDocument.FirstChild, referredElement.SchemaType, schemas).GetValue(pn.Controls[0], renderingDocument.FirstChild) +
                       "</" + referredElement.Name + ">");
            }
        }
예제 #4
0
        public Control GetWebControl(HttpServerUtility server, XmlNode renderingDocument)
        {
            var field = FieldsManager.GetInstance(renderingDocument.FirstChild, complexType.Particle, schemas);

            if (this.value != null)
            {
                ((IField)field).SetValue(this.value);
            }
            return(field.GetWebControl(server, renderingDocument.FirstChild));
        }
예제 #5
0
        public Control GetWebControl(HttpServerUtility server, System.Xml.XmlNode renderingDocument)
        {
            /* if it is a repeatable element, of any type, complexType or our base types*/
            if (referredElement.MaxOccurs > 1)
            {
                XmlSchemaElement newElm = new XmlSchemaElement();

                /*I copy the schema element omitting min e max Occurs*/
                newElm.Name           = referredElement.Name;
                newElm.SchemaType     = referredElement.SchemaType;
                newElm.SchemaTypeName = referredElement.SchemaTypeName;

                /*and i create a repeater panel that manages the repetition of that single element (without the max e min occurs)*/
                RepeaterPanel rp = new RepeaterPanel(schemas, renderingDocument, newElm, value, (int)referredElement.MinOccurs, (int)referredElement.MaxOccurs);
                rp.ID = referredElement.Name + "_Repeating";
                UpdatePanel up = new UpdatePanel();
                up.ContentTemplateContainer.Controls.Add(new LiteralControl("<BR>"));
                up.ContentTemplateContainer.Controls.Add(rp);

                return(up);
            }
            else             /*if it is just an element with an inline complex type*/
            {
                NamingPanel pn = new NamingPanel();

                string name;
                if (renderingDocument.Attributes["renderedLabel"] != null)
                {
                    name = renderingDocument.Attributes["renderedLabel"].Value.FromXmlValue2Render(server);
                }
                else
                {
                    name = referredElement.Name.FromXmlName2Render(server);
                }

                pn.GroupingText = name;
                pn.ID           = referredElement.Name;
                /*This field should be a ComplexType*/
                var field = FieldsManager.GetInstance(renderingDocument.FirstChild, referredElement.SchemaType, schemas);
                /*I set the value to the ComplexType inside the element*/
                if (value != null)
                {
                    ((IField)field).SetValue(value[0].ChildNodes.ToList());
                }
                pn.Controls.Add(field.GetWebControl(server, renderingDocument.FirstChild));

                return(pn);
            }
        }
예제 #6
0
        public Control GetWebControl(HttpServerUtility server, XmlNode renderingDocument)
        {
            /*WARNING: This MUST be the same procedure of the one in GetValue, otherwise nothing works*/

            Panel pn = new Panel();

            int schemaChildCount = 0;

            foreach (XmlNode n in renderingDocument.ChildNodes)
            {
                if (n.Name.StartsWith("xs_"))                /*this is a schema element!*/
                {
                    XmlSchemaObject rndObj = namedSequence.Items[schemaChildCount];
                    var             field  = FieldsManager.GetInstance(n, rndObj, this.completeSchemas);


                    /*If someone sets the value on this class i must set it to my child.*/
                    if (value != null)
                    {
                        List <XmlNode> d = new List <XmlNode>();

                        /*This foreach is needed for repeating elements
                         * The schema specify just <element name=".." maxOccurs="..">
                         * but here we can have many nodes with the same name matching that element*/
                        foreach (XmlNode nvalue in value)
                        {
                            if (nvalue.SchemaInfo.SchemaElement.Name == ((XmlSchemaElement)rndObj).Name)
                            {
                                d.Add(nvalue);
                            }
                        }
                        ((IField)field).SetValue(d);
                    }

                    var wctrl = field.GetWebControl(server, n);

                    pn.Controls.Add(wctrl);
                    pn.Controls.Add(new LiteralControl("<BR>"));
                    schemaChildCount++;
                }
                else                 /*this is a rendering only element*/
                {
                    pn.Controls.Add(FieldsManager.GetInstance(n, null, null).GetWebControl(server, n));
                }
            }
            return(pn);
        }
예제 #7
0
        private Control addItem(int i)
        {
            var field = FieldsManager.GetInstance(renderingToRepeat, itemToRepeat, schemas);

            /* Assigning the i-esimo node to the i-esimo field, if presents */
            if (values != null && i < values.Count && (values[i].SchemaInfo.SchemaElement.Name == itemToRepeat.Name))
            {
                var tmp = new List <XmlNode>();
                tmp.Add(values[i]);
                ((IField)field).SetValue(tmp);
            }

            var ctr = field.GetWebControl(Page.Server, this.renderingToRepeat);

            ctr.ID = ctr.ID + i.ToString();
            /* This part adds the new controls in the end, BUT before the two controls added OnInit*/
            this.Controls.AddAt(this.Controls.Count - 3, ctr);
            this.Controls.AddAt(this.Controls.Count - 3, new LiteralControl("<br />"));

            return(ctr);
        }
예제 #8
0
        public string GetValue(Control ctrl, XmlNode renderingDocument)
        {
            var field = FieldsManager.GetInstance(renderingDocument.FirstChild, complexType.Particle, schemas);

            return(field.GetValue(ctrl, renderingDocument.FirstChild));
        }
예제 #9
0
        public void AddItems()
        {
            int schemaChildCount = 0;

            foreach (XmlNode n in renderingDocument.ChildNodes)
            {
                if (n.Name.StartsWith("xs_"))
                {
                    bool itemChecked = false;

                    XmlSchemaObject rndObj = obj.Items[schemaChildCount];
                    var             field  = FieldsManager.GetInstance(n, rndObj, schemas);

                    if (value != null)
                    {
                        List <XmlNode> d = null;
                        foreach (XmlNode nvalue in value)
                        {
                            if (nvalue.SchemaInfo.SchemaElement.Name == ((XmlSchemaElement)rndObj).Name)
                            {
                                d = new List <XmlNode>();
                                d.Add(nvalue);
                                itemChecked = true;
                            }
                        }
                        if (itemChecked)
                        {
                            ((IField)field).SetValue(d);
                        }
                    }

                    var wctrl = field.GetWebControl(Page.Server, n);

                    RadioButton rb = new RadioButton();
                    rb.AutoPostBack    = true;
                    rb.CheckedChanged += new EventHandler(rb_CheckedChanged);

                    rb.GroupName = this.ID + "choice";

                    if (rndObj is XmlSchemaElement)
                    {
                        var rndElem = (XmlSchemaElement)rndObj;
                        if (n.Attributes["label"] != null)
                        {
                            rb.Text = n.Attributes["label"].Value.FromXmlValue2Render(Page.Server);
                        }
                        else
                        {
                            rb.Text = rndElem.Name.FromXmlName2Render(Page.Server);
                        }
                    }
                    else
                    {
                        rb.Text = ("UNNAMED CHOICE");
                    }

                    rb.Text += "<BR>";

                    if (!itemChecked)
                    {
                        wctrl.Visible = false;
                    }

                    if (itemChecked)
                    {
                        rb.Checked = true;
                    }

                    this.Controls.Add(rb);
                    this.Controls.Add(wctrl);
                    this.Controls.Add(new LiteralControl("<BR>"));

                    schemaChildCount++;
                }
                else
                {
                    var wctrl = FieldsManager.GetInstance(n, null, null).GetWebControl(Page.Server, n);
                    this.Controls.Add(wctrl);
                    this.Controls.Add(new LiteralControl("<BR>"));
                }
            }
        }
예제 #10
0
        public void FieldsManagerTest()
        {
            fieldList = new List <IField>();

            #region Reflection Test

            /*
             * Reflection test
             */
            FieldsManager.LoadTypes();
            List <Type> lt = FieldsManager.FieldTypes;
            Assert.IsTrue(lt.Count > 0);



            List <MethodInfo> lm1 = FieldsManager.GetConstraints(lt[0]);
            List <MethodInfo> lm2 = FieldsManager.GetConstraints(lt[1]);
            Assert.IsNotNull(lm1);
            Assert.IsNotNull(lm2);

            Console.WriteLine("--Report1 (reflection test)--");
            Console.WriteLine("Types found:");
            foreach (Type t in lt)
            {
                Console.WriteLine(t.Name);
            }
            Console.WriteLine("Constraints for Field: " + lt[0].Name);
            foreach (MethodInfo m in lm1)
            {
                Console.WriteLine(m.Name);
            }
            Console.WriteLine("Constraints for Field: " + lt[1].Name);
            foreach (MethodInfo m in lm2)
            {
                Console.WriteLine(m.Name);
            }

            #endregion

            #region Instance Creation Test 1

            fieldList.Add(FieldsManager.GetInstance(lt[0]));
            fieldList.Add(FieldsManager.GetInstance(lt[0]));
            fieldList.Add(FieldsManager.GetInstance(lt[0]));
            fieldList.Add(FieldsManager.GetInstance(lt[0]));

            fieldList.Add(FieldsManager.GetInstance(lt[1]));
            fieldList.Add(FieldsManager.GetInstance(lt[1]));
            fieldList.Add(FieldsManager.GetInstance(lt[1]));
            fieldList.Add(FieldsManager.GetInstance(lt[1]));

            foreach (IField f in fieldList)
            {
                Assert.IsNotNull(f);
            }
            for (int i = 0; i < fieldList.Count; i++)
            {
                fieldList[i].TypeName = "type" + i;
            }

            Console.WriteLine("Fields schema");
            XmlSchema         xsch = new XmlSchema();
            XmlWriterSettings xset = new XmlWriterSettings();
            xset.ConformanceLevel = ConformanceLevel.Auto;
            XmlWriter xwr = XmlWriter.Create(Console.Out, xset);
            foreach (IField f in fieldList)
            {
                xsch.Items.Add(f.TypeSchema);
            }

            xsch.Write(xwr);



            #endregion

            #region Instance Manipulation


            //Add Constraint to IntBox

            /* if (f1 is IntBox)
             * {
             *   Assert.IsTrue(((IntBox)f1).AddGreaterThanConstraint(1));
             * }
             * Console.WriteLine("IntBox with Constraint");
             * XmlSchemaComplexType xsd3 = f1.TypeSchema;
             * xsch = new XmlSchema();
             * xsch.Items.Add(xsd3);
             * //prints new schema to output
             * xsch.Write(xwr);
             */
            XmlSchemaSet xsdset = new XmlSchemaSet();
            XmlSchema    xsd4   = XmlSchema.Read(new StringReader(TestResources.BaseTypes), ValidationEventHandler);
            xsdset.Add(xsd4);
            int count1 = 0, count2 = 0;
            foreach (IField f in fieldList)
            {
                xsch = new XmlSchema();
                if (f is IntBox)
                {
                    switch (count1)
                    {
                    case 0:
                    {
                        Assert.IsTrue(((IntBox)f).AddGreaterThanConstraint(1));
                    } break;

                    case 1:
                    {
                        Assert.IsTrue(((IntBox)f).AddIntervalConstraint(3, 100));
                    } break;

                    case 2:
                    {
                        Assert.IsTrue(((IntBox)f).AddLowerThanConstraint(9000));
                    } break;

                    case 3:
                    {
                        Assert.IsTrue(((IntBox)f).AddLowerThanConstraint(0));
                        Assert.IsTrue(((IntBox)f).AddGreaterThanConstraint(-1000));
//                                Assert.IsFalse(((IntBox)f).AddLowerThanConstraint(0));
//                                Assert.IsFalse(((IntBox)f).AddLowerThanConstraint(0));
//                                Assert.IsFalse(((IntBox)f).AddGreaterThanConstraint(-1000));
                    } break;
                    }
                    count1++;
                }
                if (f is StringBox)
                {
                    switch (count2)
                    {
                    case 0:
                    {
                        Assert.IsTrue(((StringBox)f).AddMinLengthConstraint(2));
                        Assert.IsTrue(((StringBox)f).AddMaxLengthConstraint(10));
                    } break;

                    case 1:
                    {
                        Assert.IsTrue(((StringBox)f).AddPatternConstraint("[0-9]"));
                        Assert.IsTrue(((StringBox)f).AddMaxLengthConstraint(1));
                    } break;

                    case 2:
                    {
                        Assert.IsTrue(((StringBox)f).AddMaxLengthConstraint(2));
                        //                               Assert.IsFalse(((StringBox)f).AddMaxLengthConstraint(2));
                        //                               Assert.IsFalse(((StringBox)f).AddMinLengthConstraint(-2));
                        Assert.IsTrue(((StringBox)f).AddMinLengthConstraint(1));
                    } break;

                    case 3: { } break;
                    }
                    count2++;
                }
                XmlSchemaComplexType xsd3 = f.TypeSchema;
                xsch.Items.Add(xsd3);
                xsdset.Add(xsch);
            }
            XmlSchema compiledSchema = null;
            xsdset.Compile();

            foreach (XmlSchema sch in xsdset.Schemas())
            {
                compiledSchema = sch;
                compiledSchema.Write(Console.Out);
                Console.Out.WriteLine();
            }

            #endregion

            #region Instance Retrieving

            XmlSchema xsd5           = XmlSchema.Read(new StringReader(TestResources.BaseTypes), ValidationEventHandler);
            XmlSchema xsd6           = XmlSchema.Read(new StringReader(TestResources.Field1), ValidationEventHandler);
            XmlSchema xsd7           = XmlSchema.Read(new StringReader(TestResources.Field2), ValidationEventHandler);
            XmlSchema xsd8           = XmlSchema.Read(new StringReader(TestResources.Elem1), ValidationEventHandler);


            XmlSchemaSet xset2 = new XmlSchemaSet();
            xset2.Add(xsd5);
            xset2.Add(xsd6);
            xset2.Add(xsd7);
            xset2.Add(xsd8);

            xset2.Compile();

            List <IField> lf = new List <IField>();
            foreach (XmlSchemaElement elem in ((XmlSchemaSequence)((XmlSchemaComplexType)xsd8.Items[0]).ContentTypeParticle).Items)
            {
                Assert.IsNotNull(elem);
                IField felem = FieldsManager.GetInstance(xset2, elem);
                Assert.IsNotNull(felem);
                lf.Add(felem);
            }

            Assert.IsTrue(lf.Count > 0);

            //XmlSchemaElement elem1 =((XmlSchemaElement)((XmlSchemaSequence)compl1.ContentTypeParticle).Items[0]);
            //XmlSchemaElement elem2 = ((XmlSchemaElement)((XmlSchemaSequence)compl2.ContentTypeParticle).Items[0]);

            Console.Out.WriteLine("------Fields Retrieved-------");

            List <WebControl> wl = new List <WebControl>();
            foreach (IField l in lf)
            {
                Assert.IsNotNull(l.Name);
                Console.Out.WriteLine("Field name: " + l.Name);
                WebControl w = l.GetWebControl();
                Assert.IsNotNull(w);
                List <BaseValidator> vl = l.GetValidators();
                Assert.IsNotNull(vl);
                Assert.IsTrue(vl.Count > 0);
                XmlSchema xs = new XmlSchema();
                xs.Items.Add(l.TypeSchema);
                xs.Write(Console.Out);
                foreach (BaseValidator v in vl)
                {
                    Console.Out.WriteLine("Validator:" + v.GetType().Name);
                }
            }


            //WebControl w=l.GetWebControl();
            //    Assert.IsNotNull(w);
            //    w.



            #endregion
        }