Ejemplo n.º 1
0
        public static DataFormType parseDataFormType(string s)
        {
            DataFormType type = DataFormType.FROM;

            Enum.TryParse(s?.ToUpper(), out type);
            return(type);
        }
Ejemplo n.º 2
0
        public void loadRoomConfig(XmlNode node)
        {
            type = parseDataFormType(node.Attributes["type"]?.Value);

            foreach (XmlNode n in node.ChildNodes)
            {
                switch (n.Name)
                {
                case "field":
                    FIELDS.Add(new Field(n));
                    break;

                case "title":
                    titel = n.InnerText;
                    break;

                case "instructions":
                    instructions = n.InnerText;
                    break;

                default:
                    Logging.Logger.Warn("Unknown data form config element '" + n.Name + "' received!");
                    break;
                }
            }
        }
Ejemplo n.º 3
0
 protected void AssertType(DataFormType expected)
 {
     if (this.Type != expected)
     {
         throw new ArgumentException("The specified XML element is not a data-form of type '" + expected.ToString() + "'.");
     }
 }
Ejemplo n.º 4
0
 public DataForm(DataFormType type, List <Field> fields)
 {
     this.FIELDS       = fields;
     this.type         = type;
     this.titel        = null;
     this.instructions = null;
 }
Ejemplo n.º 5
0
        public bool AddDataFormType(DataFormType dataFormType)
        {
            bool result = false;

            using (var context = new DataFormDataContext())
            {
                context.DataFormTypes.Add(dataFormType);
                int save = context.SaveChanges();
                if (save > 0)
                {
                    result = true;
                }
            }
            return(result);
        }
Ejemplo n.º 6
0
        public bool RemoveDataFormType(DataFormType dataFormType)
        {
            bool result = false;

            using (var context = new DataFormDataContext())
            {
                var dtf = context.DataFormTypes.Where(x => x.DataFormTypeId == dataFormType.DataFormTypeId).FirstOrDefault();
                if (dtf != null)
                {
                    context.DataFormTypes.Remove(dtf);
                    int save = context.SaveChanges();
                    if (save > 0)
                    {
                        result = true;
                    }
                }
            }
            return(result);
        }
Ejemplo n.º 7
0
        public static DataForm Create(XmlElement element)
        {
            DataForm form;

            element.ThrowIfNull <XmlElement>("element");
            if ((element.Name != "x") || (element.NamespaceURI != "jabber:x:data"))
            {
                throw new ArgumentException("Invalid root element: " + element.Name);
            }
            string attribute = element.GetAttribute("type");

            if (string.IsNullOrEmpty(attribute))
            {
                throw new ArgumentException("Missing 'type' attribute.");
            }
            try
            {
                DataFormType type = Util.ParseEnum <DataFormType>(attribute, true);
                switch (type)
                {
                case DataFormType.Form:
                    return(new RequestForm(element));

                case DataFormType.Submit:
                    return(new SubmitForm(element));

                case DataFormType.Cancel:
                    return(new CancelForm(element));

                case DataFormType.Result:
                    return(new ResultForm(element));
                }
                throw new ArgumentException("Invalid form type: " + type);
            }
            catch (Exception exception)
            {
                throw new XmlException("Invalid data-form element.", exception);
            }
            return(form);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a data-form instance of the proper type from the specified
        /// XML element.
        /// </summary>
        /// <param name="element">The XML element to create the data-form instance
        /// from.</param>
        /// <returns>An initialized instance of a data-form class of the respectiv
        /// type which derives from the DataForm base class.</returns>
        /// <exception cref="ArgumentNullException">The element parameter is
        /// null.</exception>
        /// <exception cref="ArgumentException">The specified XML element is not a
        /// valid data-form element.</exception>
        public static DataForm Create(XmlElement element)
        {
            element.ThrowIfNull("element");
            if (element.Name != "x" || element.NamespaceURI != "jabber:x:data")
            {
                throw new ArgumentException("Invalid root element: " + element.Name);
            }
            string s = element.GetAttribute("type");

            if (String.IsNullOrEmpty(s))
            {
                throw new ArgumentException("Missing 'type' attribute.");
            }
            try
            {
                DataFormType type = Util.ParseEnum <DataFormType>(s);
                switch (type)
                {
                case DataFormType.Form:
                    return(new RequestForm(element));

                case DataFormType.Submit:
                    return(new SubmitForm(element));

                case DataFormType.Cancel:
                    return(new CancelForm(element));

                case DataFormType.Result:
                    return(new ResultForm(element));

                default:
                    throw new ArgumentException("Invalid form type: " + type);
                }
            }
            catch (Exception e)
            {
                throw new XmlException("Invalid data-form element.", e);
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 ///		Convierte el tipo
 /// </summary>
 private JabberForm.FormType ConvertType(DataFormType intType)
 {
     switch (intType)
         {	case DataFormType.Cancel:
                 return JabberForm.FormType.Cancel;
             case DataFormType.Result:
                 return JabberForm.FormType.Result;
             case DataFormType.Submit:
                 return JabberForm.FormType.Submit;
             default:
                 return JabberForm.FormType.Form;
         }
 }
Ejemplo n.º 10
0
		/// <summary>
		/// Asserts the data-form is of the specified type.
		/// </summary>
		/// <param name="expected">The type to assert.</param>
		/// <exception cref="ArgumentException">The data-form is not of the
		/// expected type.</exception>
		protected void AssertType(DataFormType expected) {
			if (Type != expected) {
				throw new ArgumentException("The specified XML element is not a " +
					"data-form of type '" + expected.ToString() + "'.");
			}
		}
Ejemplo n.º 11
0
 public DataForm(DataFormType type) : this(type, new List <Field>())
 {
 }