コード例 #1
0
        public void SubmitForm(XmppData.Data submit)
        {
            ElementList fields = submit.SelectElements(typeof(XmppData.Field));

            foreach (var field in fields)
            {
                if (field is XmppData.Field)
                {
                    XmppData.Field fld = (XmppData.Field)field;
                    //Set conf back
                    switch (fld.Var)
                    {
                    case "muc#roomconfig_usernamesonly":
                        UserNamesOnly = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_roomtitle":
                        Title = fld.GetValue();
                        break;

                    case "muc#roomconfig_enablelogging":
                        Logging = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_changesubject":
                        CanChangeSubject = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_allowinvites":
                        CanInvite = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_publicroom":
                        Visible = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_persistentroom":
                        Persistent = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_membersonly":
                        MembersOnly = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_passwordprotectedroom":
                        PasswordProtected = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_moderated":
                        Moderated = fld.GetValueBool();
                        break;

                    case "muc#roomconfig_roomsecret":
                        Password = fld.GetValue();
                        break;
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        ///   Gets a list of all form fields
        /// </summary>
        /// <returns> </returns>
        public Field[] GetFields()
        {
            ElementList nl = SelectElements(typeof (Field));
            var fields = new Field[nl.Count];
            int i = 0;
            foreach (Element e in nl)
            {
                fields[i] = (Field) e;
                i++;
            }

            return fields;
        }
コード例 #3
0
 /// <summary>
 /// </summary>
 /// <param name="field"> </param>
 public Field AddField(Field field)
 {
     AddChild(field);
     return field;
 }
コード例 #4
0
 /// <summary>
 /// </summary>
 /// <returns> </returns>
 public Field AddField()
 {
     var f = new Field();
     AddChild(f);
     return f;
 }
コード例 #5
0
		public static Data GetDataForm(object dataForm, string prefix)
		{
			Data data = new Data(XDataFormType.form);

			//Go through public vars
			PropertyInfo[] props = dataForm.GetType().GetProperties(BindingFlags.Instance | BindingFlags.SetProperty |
											 BindingFlags.Public);
			foreach (PropertyInfo prop in props)
			{
				if (prop.CanRead)
				{
					Field field = new Field(FieldType.Unknown);

					field.Var = string.Format("{0}#{1}", prefix, prop.Name);
					object propValue = prop.GetValue(dataForm, null);

					foreach (var attribute in prop.GetCustomAttributes(false))
					{
						if (attribute is XDataDescriptionAttribute)
						{
							field.Label = (attribute as XDataDescriptionAttribute).Description;
						}
						else if (attribute is XDataOneOfAttribute)
						{
							field.Type = FieldType.List_Single;
							field.FieldValue = (string)propValue;
							foreach (var vars in (attribute as XDataOneOfAttribute).Variants)
							{
								field.AddOption(vars, vars);
							}
						}
						else if (attribute is XDataAnyOfAttribute)
						{
							field.Type = FieldType.List_Multi;
							field.AddValues((string[])propValue);
							foreach (var vars in (attribute as XDataAnyOfAttribute).Variants)
							{
								field.AddOption(vars, vars);
							}
						}
						else if (attribute is XDataMultiline)
						{
							field.Type = FieldType.Text_Multi;
							field.FieldValue = (string)propValue;
						}
						else if (attribute is XDataPassword)
						{
							field.Type = FieldType.Text_Private;
							field.FieldValue = (string)propValue;
						}
						else if (attribute is XDataFixed)
						{
							field.Type = FieldType.Fixed;
							field.FieldValue = (string)propValue;
						}
					}
					if (field.Type == FieldType.Unknown)
					{
						if (prop.PropertyType == typeof(bool))
						{
							field.Type = FieldType.Boolean;
							field.FieldValue = (bool)propValue ? "1" : "0";
						}
						else if (prop.PropertyType == typeof(string))
						{
							field.Type = FieldType.Text_Single;
							field.FieldValue = (string)propValue;
						}
					}
					if (field.Label == null)
					{
						field.Label = prop.Name;
					}
					data.AddField(field);
				}
			}

			return data;
		}
コード例 #6
0
        public static XmppData.Data GetDataForm(object dataForm, string prefix)
        {
            XmppData.Data data = new XmppData.Data(XmppData.XDataFormType.form);

            //Go through public vars
            PropertyInfo[] props = dataForm.GetType().GetProperties(BindingFlags.Instance | BindingFlags.SetProperty |
                                                                    BindingFlags.Public);
            foreach (PropertyInfo prop in props)
            {
                if (prop.CanRead)
                {
                    XmppData.Field field = new XmppData.Field(XmppData.FieldType.Unknown);

                    field.Var = string.Format("{0}#{1}", prefix, prop.Name);
                    object propValue = prop.GetValue(dataForm, null);

                    foreach (var attribute in prop.GetCustomAttributes(false))
                    {
                        if (attribute is XDataDescriptionAttribute)
                        {
                            field.Label = (attribute as XDataDescriptionAttribute).Description;
                        }
                        else if (attribute is XDataOneOfAttribute)
                        {
                            field.Type       = XmppData.FieldType.List_Single;
                            field.FieldValue = (string)propValue;
                            foreach (var vars in (attribute as XDataOneOfAttribute).Variants)
                            {
                                field.AddOption(vars, vars);
                            }
                        }
                        else if (attribute is XDataAnyOfAttribute)
                        {
                            field.Type = XmppData.FieldType.List_Multi;
                            field.AddValues((string[])propValue);
                            foreach (var vars in (attribute as XDataAnyOfAttribute).Variants)
                            {
                                field.AddOption(vars, vars);
                            }
                        }
                        else if (attribute is XDataMultiline)
                        {
                            field.Type       = XmppData.FieldType.Text_Multi;
                            field.FieldValue = (string)propValue;
                        }
                        else if (attribute is XDataPassword)
                        {
                            field.Type       = XmppData.FieldType.Text_Private;
                            field.FieldValue = (string)propValue;
                        }
                        else if (attribute is XDataFixed)
                        {
                            field.Type       = XmppData.FieldType.Fixed;
                            field.FieldValue = (string)propValue;
                        }
                    }
                    if (field.Type == XmppData.FieldType.Unknown)
                    {
                        if (prop.PropertyType == typeof(bool))
                        {
                            field.Type       = XmppData.FieldType.Boolean;
                            field.FieldValue = (bool)propValue ? "1" : "0";
                        }
                        else if (prop.PropertyType == typeof(string))
                        {
                            field.Type       = XmppData.FieldType.Text_Single;
                            field.FieldValue = (string)propValue;
                        }
                    }
                    if (field.Label == null)
                    {
                        field.Label = prop.Name;
                    }
                    data.AddField(field);
                }
            }

            return(data);
        }