Esempio n. 1
0
        /// <summary>
        /// Builds
        /// </summary>
        /// <param name="objForm"></param>
        /// <returns></returns>
        public string BuildAskingForm(object objForm)
        {
            XNamespace xn  = "jabber:x:data";
            XDocument  doc = new XDocument();

            XElement elemMessage = new XElement(xn + "x");

            elemMessage.Add(new XAttribute("type", Type));

            doc.Add(elemMessage);

            if (Title != null)
            {
                elemMessage.Add(new XElement(xn + "title", Title));
            }
            if (Instructions != null)
            {
                elemMessage.Add(new XElement(xn + "instructions", Instructions));
            }



            /// Now build all our Properties
            ///
            Type formtype = objForm.GetType();

            PropertyInfo [] props = formtype.GetProperties();
            if ((props != null) && (props.Length > 0))
            {
                foreach (PropertyInfo prop in props)
                {
                    object objPropValue = prop.GetValue(objForm, null);

                    /// See what attributes we have
                    ///
                    object [] attr = prop.GetCustomAttributes(typeof(FormFieldAttribute), true);
                    if ((attr == null) || (attr.Length <= 0))
                    {
                        continue;
                    }

                    FormFieldAttribute ffa = attr[0] as FormFieldAttribute;
                    ffa.AddXML(elemMessage, objPropValue);
                }
            }

            return(doc.ToString(SaveOptions.None));
        }
Esempio n. 2
0
        public void SetPropertyFromFormValue(XElement elemfield, string strVarValue)
        {
            List <string> Values = new List <string>();
            var           values = elemfield.Descendants("{jabber:x:data}value");

            foreach (XElement nextvalue in values)
            {
                Values.Add(nextvalue.Value);
            }

            if (Values.Count > 0)
            {
                PropertyInfo [] props = GetType().GetProperties();
                foreach (PropertyInfo prop in props)
                {
                    /// See what attributes we have
                    ///
                    object[] attr = prop.GetCustomAttributes(typeof(FormFieldAttribute), true);
                    if ((attr == null) || (attr.Length <= 0))
                    {
                        continue;
                    }

                    FormFieldAttribute ffa = attr[0] as FormFieldAttribute;
                    if (ffa.Var == strVarValue)
                    {
                        if (ffa.IsStringList == true)
                        {
                            prop.SetValue(this, Values, null);
                        }
                        else
                        {
                            prop.SetValue(this, Values[0], null);
                        }
                        break;
                    }
                }
            }
        }