public LoadDataForm(DataForm data, DataItem item) { // // Required for Windows Form Designer support // InitializeComponent(); this.item = item; this.data = data; }
/// <summary> /// Sends a <see cref="RoomConfigMessage"/> and saves the given room configuration. /// </summary> /// <param name="roomJid">The bare JID if the room you would like to save the room configuration for. e.g. '*****@*****.**'</param> /// <param name="roomConfiguration">The new room configuration.</param> /// <returns>The <see cref="RoomConfigMessage"/> result</returns> public Task <MessageResponseHelperResult <IQMessage> > saveRoomConfigurationAsync(string roomJid, DataForm roomConfiguration) { Predicate <IQMessage> predicate = (x) => { return(true); }; AsyncMessageResponseHelper <IQMessage> helper = new AsyncMessageResponseHelper <IQMessage>(CONNECTION, predicate); RoomConfigMessage msg = new RoomConfigMessage(CONNECTION.account.getFullJid(), roomJid, roomConfiguration, MUCAffiliation.OWNER); return(helper.startAsync(msg)); }
internal Page(DataForm Form, XmlElement E) : base(Form, E) { }
/// <summary> /// Class managing a page in a data form layout. /// </summary> /// <param name="Form">Data Form.</param> /// <param name="Label">Label</param> /// <param name="ChildElements">Child elements.</param> public Page(DataForm Form, string Label, params LayoutElement[] ChildElements) : base(Form, Label, ChildElements) { }
public JsonResult ObtenerFacturaMN(SG_FACTURAS_MN facturas) { DataForm<SG_FACTURAS_MN> result = new DataForm<SG_FACTURAS_MN>(); var datos = _serFac.ObtenerFacturaPorCriterio(x => x.FECHA == facturas.FECHA && x.ID_COMBUSTIBLE == facturas.ID_COMBUSTIBLE); if (datos != null) { var format = new { ID_COMBUSTIBLE = datos.ID_COMBUSTIBLE, ID_FACTURA = datos.ID_FACTURA, FECHA33 = String.Format("{0: dd/MM/yyyy}", datos.FECHA), IMPORTE = datos.IMPORTE, LITROS = datos.LITROS, PRECIO = datos.PRECIO }; return Json(new { success = true, data = format }); } else { var combustible = _serCom.ObtenerCombustible(x => x.ID_COMBUSTIBLE == facturas.ID_COMBUSTIBLE); var format = new { ID_COMBUSTIBLE = combustible.ID_COMBUSTIBLE, ID_FACTURA =0, IMPORTE = 0, LITROS = 0, PRECIO = combustible.PRECIO_VENTA }; return Json(new { success = true, data = format }); } }
/// <summary> /// Creates an offer or result from the specified data-form. /// </summary> /// <param name="form">The data-form to include in the feature negotiation /// offer or result.</param> /// <returns>An XML element representing the feature negotiation /// offer or result.</returns> /// <exception cref="ArgumentNullException">The form parameter is /// null.</exception> public static XmlElement Create(DataForm form) { form.ThrowIfNull("form"); return(Xml.Element("feature", "http://jabber.org/protocol/feature-neg").Child(form.ToXmlElement())); }
internal LayoutElement(DataForm Form) { this.form = Form; }
private void EditClick(object sender, System.EventArgs e) { if (((EditMenuItem)sender).item is FunctionItem) { SourceForm sourceForm = new SourceForm(graph, (FunctionItem)((EditMenuItem)sender).item, this); sourceForm.Reset(); sourceForm.Show(); } else if (((EditMenuItem)sender).item is DataItem) { DataForm dataForm = new DataForm(graph, (DataItem)((EditMenuItem)sender).item, this); dataForm.Reset(); dataForm.Show(); } }
private void Layout(Panel Container, ReportedReference ReportedReference, DataForm Form) { if (Form.Records.Length == 0 || Form.Header.Length == 0) { return; } Dictionary <string, int> VarIndex = new Dictionary <string, int>(); ColumnDefinition ColumnDefinition; RowDefinition RowDefinition; TextBlock TextBlock; int i, j; Brush BorderBrush = new SolidColorBrush(Colors.Gray); Brush Bg1 = new SolidColorBrush(Color.FromArgb(0x20, 0x40, 0x40, 0x40)); Brush Bg2 = new SolidColorBrush(Color.FromArgb(0x10, 0x80, 0x80, 0x80)); Border Border; Grid Grid = new Grid(); Container.Children.Add(Grid); i = 0; foreach (Field Field in Form.Header) { ColumnDefinition = new ColumnDefinition() { Width = GridLength.Auto }; Grid.ColumnDefinitions.Add(ColumnDefinition); VarIndex[Field.Var] = i++; } RowDefinition = new System.Windows.Controls.RowDefinition() { Height = GridLength.Auto }; Grid.RowDefinitions.Add(RowDefinition); foreach (Field[] Row in Form.Records) { RowDefinition = new RowDefinition() { Height = GridLength.Auto }; Grid.RowDefinitions.Add(RowDefinition); } foreach (Field Field in Form.Header) { if (!VarIndex.TryGetValue(Field.Var, out i)) { continue; } Border = new Border(); Grid.Children.Add(Border); Grid.SetColumn(Border, i); Grid.SetRow(Border, 0); Border.BorderBrush = BorderBrush; Border.BorderThickness = new Thickness(1); Border.Padding = new Thickness(5, 1, 5, 1); Border.Background = Bg1; TextBlock = new TextBlock() { FontWeight = FontWeights.Bold, Text = Field.Label }; Border.Child = TextBlock; } j = 0; foreach (Field[] Row in Form.Records) { j++; foreach (Field Field in Row) { if (!VarIndex.TryGetValue(Field.Var, out i)) { continue; } Border = new Border(); Grid.Children.Add(Border); Grid.SetColumn(Border, i); Grid.SetRow(Border, j); Border.BorderBrush = BorderBrush; Border.BorderThickness = new Thickness(1); Border.Padding = new Thickness(5, 1, 5, 1); if ((j & 1) == 1) { Border.Background = Bg2; } else { Border.Background = Bg1; } TextBlock = new TextBlock() { Text = Field.ValueString }; Border.Child = TextBlock; } } }
private void MedlemDetails_EditEnding(object sender, DataFormEditEndingEventArgs e) { DataForm objMedlemDetails = sender as DataForm; int x = 1; }
internal TextElement(DataForm Form, XmlElement E) : base(Form) { this.text = E.InnerText; }
/// <summary> /// Class managing a text element. /// </summary> /// <param name="Form">Data Form.</param> /// <param name="Text">Text.</param> public TextElement(DataForm Form, string Text) : base(Form) { this.text = Text; }
internal NodeQueryResponseEventArgs(NodeQuery Query, DataForm Parameters, IqResultEventArgs e) : base(Parameters, e) { this.query = Query; }
static void WriteTargetData(Int32 in_com) { ColorManagementMISDK sdk = ColorManagementMISDK.GetInstance(); // Connect ReturnMessage ret = sdk.Connect(in_com); if (!ErrorDefine.IsNormalCode(ret.errorCode)) { Console.WriteLine("Error:{0:d} Connect", ret.errorCode); return; } // Get instrumentInfo InstrumentInfoEx instInfoEx; ret = sdk.GetInstrumentInfo(out instInfoEx, in_com); if (!ErrorDefine.IsNormalCode(ret.errorCode)) { Console.WriteLine("Error:{0:d} GetInstrumentInfo Ex", ret.errorCode); sdk.DisConnect(in_com); return; } if (instInfoEx.Name != "CM-25cG") { Console.WriteLine("Unsppoted instrument"); sdk.DisConnect(in_com); return; } Console.WriteLine("Please input the target number to be written. 1-2500"); int targetNum = Convert.ToInt32(Console.ReadLine()); // Set target data TargetDataPack targetDataPack = new TargetDataPack(); // Set time targetDataPack.date = DateTime.Now; // Set group list targetDataPack.group_list = new List <int> { 0, 0, 0, 0, 0 }; // Set name (MAX 30 characters) string name = "target:" + targetNum.ToString(); if (name.Length > 30) { name.Remove(30); } targetDataPack.name = name; // Set meas mode targetDataPack.meas_mode = MeasCondMode.MeasModeColorAndGloss; // Set meas area targetDataPack.meas_area = MeasArea.AREA_MAV; // Set meas type targetDataPack.meas_type = MeasType.MEASTYPE_NONE; // Set meas angel targetDataPack.meas_angle = MeasAngle.MEAS_ANGLE_NONE; // Set light direction targetDataPack.l_direction = LightDirection.LDIRECTION_NONE; // Set meas specular component targetDataPack.meas_scie = MeasCondScie.SC_NONE; // Set meas UV targetDataPack.meas_uv = MeasCondUv.UV_NONE; // Set warning level targetDataPack.warning_level = 80; // Set warning targetDataPack.warning = 0; // Set diagnosis targetDataPack.diagnosis = 0; // Set data attribute int specOrColor = 0; Console.WriteLine("Please set 1 for spectral and 2 for colorimetric."); specOrColor = Convert.ToInt32(Console.ReadLine()); if (specOrColor == 1) { // spectral data targetDataPack.data_attr = DataAttr.DATAATTR_SPEC; } else { // colorimetric data targetDataPack.data_attr = DataAttr.DATAATTR_LAB; } // Set target data if (specOrColor == 1) { // spectral data List <double> gloss = new List <double>(); gloss.Add(10.00); List <double> data = new List <double>(); for (Int32 i = instInfoEx.WaveLengthStart; i <= instInfoEx.WaveLengthEnd; i += instInfoEx.WaveLengthPitch) { data.Add(100.00); } targetDataPack.data = new Dictionary <DataId, List <double> >(); targetDataPack.data.Add(DataId.DATAID_GLOSS, gloss); targetDataPack.data.Add(DataId.DATAID_SPEC, data); // Set target ret = sdk.SetTargetData(targetNum, targetDataPack, in_com); if (!ErrorDefine.IsNormalCode(ret.errorCode)) { Console.WriteLine("Error:{0:d} SetTargetData", ret.errorCode); sdk.DisConnect(in_com); return; } } else if (specOrColor == 2) { targetDataPack.data_color = new ColorData(); targetDataPack.data_color.obs1 = Observer.Deg10; targetDataPack.data_color.ill1 = Illuminant.ILL_D65; targetDataPack.data_color.obs2 = Observer.Deg10; targetDataPack.data_color.ill2 = Illuminant.ILL_C; targetDataPack.data_color.data1 = new Dictionary <DataId, List <double> >(); List <double> data1 = new List <double>() { 100.00, 100.00, 100.00 }; targetDataPack.data_color.data1.Add(DataId.DATAID_SPEC, data1); targetDataPack.data_color.data2 = new Dictionary <DataId, List <double> >(); List <double> data2 = new List <double>() { 99.00, 1.10, 1.20 }; targetDataPack.data_color.data2.Add(DataId.DATAID_SPEC, data2); List <double> gloss = new List <double>() { 10.00 }; targetDataPack.data_color.data1.Add(DataId.DATAID_GLOSS, gloss); targetDataPack.data_color.data2.Add(DataId.DATAID_GLOSS, gloss); // Set target ret = sdk.SetTargetData(targetNum, targetDataPack, in_com); if (!ErrorDefine.IsNormalCode(ret.errorCode)) { Console.WriteLine("Error:{0:d} SetTargetData", ret.errorCode); sdk.DisConnect(in_com); return; } } else { // specOrColor Console.WriteLine("Unsupported"); sdk.DisConnect(in_com); return; } // Set tolerance for light source primary DataForm dataForm = new DataForm(); dataForm.IrradiationDirection = IrradiationDirection.NO_PARAM; dataForm.DataType = DataType.NO_PARAM; ToleranceData tolerancePrimaryData = new ToleranceData(); ToleranceParam tolerancePrimaryParam = new ToleranceParam(); tolerancePrimaryParam.Upper_enable = 1; tolerancePrimaryParam.Upper_value = 1.1; tolerancePrimaryParam.Lower_enable = 1; tolerancePrimaryParam.Lower_value = -1.2; tolerancePrimaryData.Tolerance = new Dictionary <int, ToleranceParam>(); tolerancePrimaryData.Tolerance.Add((int)ToleranceId.TOLERANCE_ID_L, tolerancePrimaryParam); //L* tolerancePrimaryData.Tolerance.Add((int)ToleranceId.TOLERANCE_ID_A, tolerancePrimaryParam); //a* tolerancePrimaryData.Tolerance.Add((int)ToleranceId.TOLERANCE_ID_B, tolerancePrimaryParam); //b* ret = sdk.SetToleranceForTarget(targetNum, 0, dataForm, tolerancePrimaryData, in_com); if (!ErrorDefine.IsNormalCode(ret.errorCode)) { Console.WriteLine("Error:{0:d} SetToleranceForTarget primary", ret.errorCode); sdk.DisConnect(in_com); return; } // Set tolerance for light source secondary ToleranceData toleranceSecondaryData = new ToleranceData(); ToleranceParam toleranceSecondaryParam = new ToleranceParam(); toleranceSecondaryParam.Upper_enable = 0; toleranceSecondaryParam.Upper_value = 2.1; toleranceSecondaryParam.Lower_enable = 0; toleranceSecondaryParam.Lower_value = -2.2; toleranceSecondaryData.Tolerance = new Dictionary <int, ToleranceParam>(); toleranceSecondaryData.Tolerance.Add((int)ToleranceId.TOLERANCE_ID_L, toleranceSecondaryParam); //L* toleranceSecondaryData.Tolerance.Add((int)ToleranceId.TOLERANCE_ID_A, toleranceSecondaryParam); //a* toleranceSecondaryData.Tolerance.Add((int)ToleranceId.TOLERANCE_ID_B, toleranceSecondaryParam); //b* ret = sdk.SetToleranceForTarget(targetNum, 1, dataForm, toleranceSecondaryData, in_com); if (!ErrorDefine.IsNormalCode(ret.errorCode)) { Console.WriteLine("Error:{0:d} SetToleranceForTarget secondary", ret.errorCode); sdk.DisConnect(in_com); return; } // Set parametric for tolerance ParametricCoef parametricData = new ParametricCoef(); parametricData.CMC = new List <double>(); parametricData.CMC.Add(1.1); parametricData.CMC.Add(1.2); parametricData.DeltaE94 = new List <double>(); parametricData.DeltaE94.Add(2.1); parametricData.DeltaE94.Add(2.2); parametricData.DeltaE94.Add(2.3); parametricData.DeltaE00 = new List <double>(); parametricData.DeltaE00.Add(3.1); parametricData.DeltaE00.Add(3.2); parametricData.DeltaE00.Add(3.3); ret = sdk.SetParametricForTarget(targetNum, dataForm, parametricData, in_com); if (!ErrorDefine.IsNormalCode(ret.errorCode)) { Console.WriteLine("Error:{0:d} SetParametricForTarget", ret.errorCode); sdk.DisConnect(in_com); return; } // Disconnect sdk.DisConnect(in_com); return; }
public void EnsureBeginEditThenEndEditDoesNotRaiseException() { DataForm df = new DataForm(); df.CurrentItem = new DataClass(); df.BeginEdit(); bool success = false; try { df.CommitEdit(true /* exitEditingMode */); success = true; } catch (NullReferenceException) { } Assert.IsTrue(success); }
/// <summary> /// Verify the given dependency property. /// </summary> /// <param name="name">The name of the property.</param> /// <param name="propertyType">The type of the property.</param> /// <param name="expectGet">Whether its CLR property has a getter.</param> /// <param name="expectSet">Whether its CLR property has a setter.</param> /// <param name="hasCallback">Whether the property has a callback.</param> /// <param name="dataFormInstance">The <see cref="DataForm"/>.</param> /// <param name="valuesToSet">The values to test the setter with.</param> private static void VerifyDependencyPropertyWithName(string name, Type propertyType, bool expectGet, bool expectSet, bool hasCallback, DataForm dataFormInstance, params object[] valuesToSet) { // Ensure that the DependencyProperty itself exists. FieldInfo fieldInfo = typeof(DataForm).GetField(name + "Property", BindingFlags.Static | BindingFlags.Public); Assert.IsNotNull(fieldInfo); Assert.AreEqual(typeof(DependencyProperty), fieldInfo.FieldType); DependencyProperty property = fieldInfo.GetValue(null) as DependencyProperty; Assert.IsNotNull(property); // // Ensure that its corresponding CLR property exists. PropertyInfo propertyInfo = typeof(DataForm).GetProperty(name, BindingFlags.Instance | BindingFlags.Public); Assert.IsNotNull(propertyInfo); Assert.AreEqual(propertyType, propertyInfo.PropertyType); // Ensure that it can be got and set as expected. Assert.AreEqual(expectGet, propertyInfo.CanRead); Assert.AreEqual(expectSet, propertyInfo.CanWrite); if (expectSet) { // Make sure that what we set is what we get. foreach (object value in valuesToSet) { propertyInfo.SetValue(dataFormInstance, value, null); Assert.AreEqual(value, propertyInfo.GetValue(dataFormInstance, null)); } } // Check to make sure that the callback is present or not present as expected. MethodInfo methodInfo = typeof(DataForm).GetMethod("On" + name + "PropertyChanged", BindingFlags.Static | BindingFlags.NonPublic); if (hasCallback) { Assert.IsNotNull(methodInfo); } else { Assert.IsNull(methodInfo); } }
private void Layout(Panel Container, Networking.XMPP.DataForms.Layout.Section Section, DataForm Form) { GroupBox GroupBox = new GroupBox(); Container.Children.Add(GroupBox); GroupBox.Header = Section.Label; GroupBox.Margin = new Thickness(5, 5, 5, 5); StackPanel StackPanel = new StackPanel(); GroupBox.Content = StackPanel; StackPanel.Margin = new Thickness(5, 5, 5, 5); foreach (LayoutElement Element in Section.Elements) { this.Layout(StackPanel, Element, Form); } }
private async void SetHandler(object Sender, IqEventArgs e) { try { string ServiceToken = XML.Attribute(e.Query, "st"); string DeviceToken = XML.Attribute(e.Query, "dt"); string UserToken = XML.Attribute(e.Query, "ut"); LinkedList <ThingReference> Nodes = null; SortedDictionary <string, bool> ParameterNames = this.provisioningClient == null ? null : new SortedDictionary <string, bool>(); LinkedList <ControlOperation> Operations = new LinkedList <ControlOperation>(); ControlParameter Parameter; DataForm Form = null; XmlElement E; string Name; foreach (XmlNode N in e.Query.ChildNodes) { E = N as XmlElement; if (E == null) { continue; } switch (E.LocalName) { case "nd": if (Nodes == null) { Nodes = new LinkedList <ThingReference>(); } Nodes.AddLast(new ThingReference( XML.Attribute(E, "id"), XML.Attribute(E, "src"), XML.Attribute(E, "pt"))); break; case "b": case "cl": case "d": case "dt": case "db": case "dr": case "i": case "l": case "s": case "t": if (ParameterNames != null) { ParameterNames[XML.Attribute(E, "n")] = true; } break; case "x": Form = new DataForm(this.client, E, null, null, e.From, e.To); if (Form.Type != FormType.Submit) { ParameterBadRequest(e); return; } if (ParameterNames != null) { foreach (Field Field in Form.Fields) { ParameterNames[Field.Var] = true; } } break; default: ParameterBadRequest(e); return; } } foreach (XmlNode N in e.Query.ChildNodes) { E = N as XmlElement; if (E == null) { continue; } switch (E.LocalName) { case "b": Name = XML.Attribute(E, "n"); foreach (ThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter == null) { return; } BooleanControlParameter BooleanControlParameter = Parameter as BooleanControlParameter; if (BooleanControlParameter == null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new BooleanControlOperation(Node, BooleanControlParameter, XML.Attribute(E, "v", false), e)); } break; case "cl": Name = XML.Attribute(E, "n"); foreach (ThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter == null) { return; } ColorControlParameter ColorControlParameter = Parameter as ColorControlParameter; if (ColorControlParameter == null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new ColorControlOperation(Node, ColorControlParameter, XML.Attribute(E, "v"), e)); } break; case "d": Name = XML.Attribute(E, "n"); foreach (ThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter == null) { return; } DateControlParameter DateControlParameter = Parameter as DateControlParameter; if (DateControlParameter == null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new DateControlOperation(Node, DateControlParameter, XML.Attribute(E, "v", DateTime.MinValue), e)); } break; case "dt": Name = XML.Attribute(E, "n"); foreach (ThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter == null) { return; } DateTimeControlParameter DateTimeControlParameter = Parameter as DateTimeControlParameter; if (DateTimeControlParameter == null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new DateTimeControlOperation(Node, DateTimeControlParameter, XML.Attribute(E, "v", DateTime.MinValue), e)); } break; case "db": Name = XML.Attribute(E, "n"); foreach (ThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter == null) { return; } DoubleControlParameter DoubleControlParameter = Parameter as DoubleControlParameter; if (DoubleControlParameter == null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new DoubleControlOperation(Node, DoubleControlParameter, XML.Attribute(E, "v", 0.0), e)); } break; case "dr": Name = XML.Attribute(E, "n"); foreach (ThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter == null) { return; } DurationControlParameter DurationControlParameter = Parameter as DurationControlParameter; if (DurationControlParameter == null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new DurationControlOperation(Node, DurationControlParameter, XML.Attribute(E, "v", Duration.Zero), e)); } break; case "i": Name = XML.Attribute(E, "n"); foreach (ThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter == null) { return; } Int32ControlParameter Int32ControlParameter = Parameter as Int32ControlParameter; if (Int32ControlParameter == null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new Int32ControlOperation(Node, Int32ControlParameter, XML.Attribute(E, "v", 0), e)); } break; case "l": Name = XML.Attribute(E, "n"); foreach (ThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter == null) { return; } Int64ControlParameter Int64ControlParameter = Parameter as Int64ControlParameter; if (Int64ControlParameter == null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new Int64ControlOperation(Node, Int64ControlParameter, XML.Attribute(E, "v", 0L), e)); } break; case "s": Name = XML.Attribute(E, "n"); foreach (ThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter == null) { return; } StringControlParameter StringControlParameter = Parameter as StringControlParameter; if (StringControlParameter == null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new StringControlOperation(Node, StringControlParameter, XML.Attribute(E, "v"), e)); } break; case "t": Name = XML.Attribute(E, "n"); foreach (ThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter == null) { return; } TimeControlParameter TimeControlParameter = Parameter as TimeControlParameter; if (TimeControlParameter == null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new TimeControlOperation(Node, TimeControlParameter, XML.Attribute(E, "v", TimeSpan.Zero), e)); } break; case "x": Dictionary <string, ControlParameter> Parameters; foreach (ThingReference Node in Nodes ?? NoNodes) { Parameters = await this.GetControlParametersByName(Node); if (Parameters == null) { NotFound(e); return; } foreach (Field Field in Form.Fields) { if (!Parameters.TryGetValue(Field.Var, out Parameter)) { ParameterNotFound(Field.Var, e); return; } Operations.AddLast(new FormControlOperation(Node, Parameter, Field.ValueString, e)); } } break; } } if (this.provisioningClient != null) { string[] ParameterNames2 = new string[ParameterNames.Count]; ParameterNames.Keys.CopyTo(ParameterNames2, 0); this.provisioningClient.CanControl(e.FromBareJid, Nodes, ParameterNames2, ServiceToken.Split(space, StringSplitOptions.RemoveEmptyEntries), DeviceToken.Split(space, StringSplitOptions.RemoveEmptyEntries), UserToken.Split(space, StringSplitOptions.RemoveEmptyEntries), (sender2, e2) => { if (e2.Ok && e2.CanControl) { LinkedList <ControlOperation> Operations2 = null; bool Restricted; if (e2.Nodes != null || e2.ParameterNames != null) { Dictionary <ThingReference, bool> AllowedNodes = null; Dictionary <string, bool> AllowedParameterNames = null; Operations2 = new LinkedList <ControlOperation>(); Restricted = false; if (e2.Nodes != null) { AllowedNodes = new Dictionary <ThingReference, bool>(); foreach (ThingReference Node in e2.Nodes) { AllowedNodes[Node] = true; } } if (e2.ParameterNames != null) { AllowedParameterNames = new Dictionary <string, bool>(); foreach (string ParameterName in e2.ParameterNames) { AllowedParameterNames[ParameterName] = true; } } foreach (ControlOperation Operation in Operations) { if (AllowedNodes != null && !AllowedNodes.ContainsKey(Operation.Node)) { Restricted = true; continue; } if (AllowedParameterNames != null && !AllowedParameterNames.ContainsKey(Operation.ParameterName)) { Restricted = true; continue; } Operations2.AddLast(Operation); } } else { Restricted = false; } if (Restricted) { this.PerformOperations(Operations2, e, e2.Nodes, e2.ParameterNames); } else { this.PerformOperations(Operations, e, null, null); } } else { e.IqError("<error type='cancel'><forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' xml:lang='en'>Access denied.</text></error>"); } }, null); } else { this.PerformOperations(Operations, e, null, null); } } catch (Exception ex) { e.IqError(ex); } }
private void Layout(Panel Container, Networking.XMPP.DataForms.Layout.TextElement TextElement, DataForm Form) { TextBlock TextBlock = new TextBlock() { TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 0, 0, 5), Text = TextElement.Text }; Container.Children.Add(TextBlock); }
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\ #region --Constructors-- public CancelFormMessage(string from, string to, DataForm form) : base(from, to, SET, getRandomId()) { FORM = form; }
/// <summary> /// Interaction logic for ParameterDialog.xaml /// </summary> public ParameterDialog(DataForm Form) { InitializeComponent(); this.form = Form; this.Title = Form.Title; Panel Container = this.DialogPanel; TabControl TabControl = null; TabItem TabItem; StackPanel StackPanel; ScrollViewer ScrollViewer; if (Form.HasPages) { TabControl = new TabControl(); this.DialogPanel.Children.Add(TabControl); DockPanel.SetDock(TabControl, Dock.Top); } else { ScrollViewer = new ScrollViewer() { VerticalScrollBarVisibility = ScrollBarVisibility.Auto }; this.DialogPanel.Children.Add(ScrollViewer); DockPanel.SetDock(ScrollViewer, Dock.Top); StackPanel = new StackPanel() { Margin = new Thickness(10, 10, 10, 10), }; ScrollViewer.Content = StackPanel; Container = StackPanel; } foreach (Networking.XMPP.DataForms.Layout.Page Page in Form.Pages) { if (TabControl != null) { TabItem = new TabItem() { Header = Page.Label }; TabControl.Items.Add(TabItem); ScrollViewer = new ScrollViewer() { VerticalScrollBarVisibility = ScrollBarVisibility.Auto }; TabItem.Content = ScrollViewer; StackPanel = new StackPanel() { Margin = new Thickness(10, 10, 10, 10) }; ScrollViewer.Content = StackPanel; Container = StackPanel; } else { TabItem = null; } foreach (LayoutElement Element in Page.Elements) { this.Layout(Container, Element, Form); } if (TabControl != null && TabControl.Items.Count == 1) { TabItem.Focus(); } } this.CheckOkButtonEnabled(); }
/// <summary> /// Sends a PubSubCreateNodeMessage to create a pubsub node. /// https://xmpp.org/extensions/xep-0060.html#owner-create-and-configure /// </summary> /// <param name="to">The target pubsub server (can be null).</param> /// <param name="nodeName">The name of the node, you want to create.</param> /// <param name="config">The configuration for the node.</param> /// <param name="onMessage">The method that should get executed once the helper receives a new valid message (can be null).</param> /// <param name="onTimeout">The method that should get executed once the helper timeout gets triggered (can be null).</param> /// <returns>Returns a MessageResponseHelper listening for PubSubCreateNodeMessage answers.</returns> public MessageResponseHelper <IQMessage> createNode(string to, string nodeName, DataForm config, MessageResponseHelper <IQMessage> .OnMessageHandler onMessage, MessageResponseHelper <IQMessage> .OnTimeoutHandler onTimeout) { MessageResponseHelper <IQMessage> helper = new MessageResponseHelper <IQMessage>(CONNECTION, onMessage, onTimeout); PubSubCreateNodeMessage msg = new PubSubCreateNodeMessage(CONNECTION.account.getFullJid(), to, nodeName, config); helper.start(msg); return(helper); }
private void Layout(Panel Container, HiddenField Field, DataForm Form) { // Do nothing }
public PubSubCreateNodeMessage(string from, string to, string nodeName, DataForm nodeConfig) : base(from, to) { NODE_NAME = nodeName; NODE_CONFIG = nodeConfig; }
private void Layout(Panel Container, MediaField Field, DataForm Form) { MediaElement MediaElement; Uri Uri = null; Grade Best = Runtime.Inventory.Grade.NotAtAll; Grade Grade; bool IsImage = false; bool IsVideo = false; bool IsAudio = false; bool TopMarginLaidOut = this.LayoutControlLabel(Container, Field); foreach (KeyValuePair <string, Uri> P in Field.Media.URIs) { if (P.Key.StartsWith("image/")) { IsImage = true; Uri = P.Value; break; } else if (P.Key.StartsWith("video/")) { switch (P.Key.ToLower()) { case "video/x-ms-asf": case "video/x-ms-wvx": case "video/x-ms-wm": case "video/x-ms-wmx": Grade = Grade.Perfect; break; case "video/mp4": Grade = Grade.Excellent; break; case "video/3gp": case "video/3gpp ": case "video/3gpp2 ": case "video/3gpp-tt": case "video/h263": case "video/h263-1998": case "video/h263-2000": case "video/h264": case "video/h264-rcdo": case "video/h264-svc": Grade = Grade.Ok; break; default: Grade = Grade.Barely; break; } if (Grade > Best) { Best = Grade; Uri = P.Value; IsVideo = true; } } else if (P.Key.StartsWith("audio/")) { switch (P.Key.ToLower()) { case "audio/x-ms-wma": case "audio/x-ms-wax": case "audio/x-ms-wmv": Grade = Grade.Perfect; break; case "audio/mp4": case "audio/mpeg": Grade = Grade.Excellent; break; case "audio/amr": case "audio/amr-wb": case "audio/amr-wb+": case "audio/pcma": case "audio/pcma-wb": case "audio/pcmu": case "audio/pcmu-wb": Grade = Grade.Ok; break; default: Grade = Grade.Barely; break; } if (Grade > Best) { Best = Grade; Uri = P.Value; IsAudio = true; } } } if (IsImage) { BitmapImage BitmapImage = new System.Windows.Media.Imaging.BitmapImage(); BitmapImage.BeginInit(); BitmapImage.UriSource = Uri; BitmapImage.EndInit(); Image Image = new Image() { Source = BitmapImage, ToolTip = Field.Description, Margin = new Thickness(0, TopMarginLaidOut ? 0 : 5, 0, 5) }; if (Field.Media.Width.HasValue) { Image.Width = Field.Media.Width.Value; } if (Field.Media.Height.HasValue) { Image.Height = Field.Media.Height.Value; } Container.Children.Add(Image); } else if (IsVideo || IsAudio) { MediaElement = new MediaElement() { Source = Uri, LoadedBehavior = MediaState.Manual, ToolTip = Field.Description }; Container.Children.Add(MediaElement); if (IsVideo) { MediaElement.Margin = new Thickness(0, TopMarginLaidOut ? 0 : 5, 0, 5); if (Field.Media.Width.HasValue) { MediaElement.Width = Field.Media.Width.Value; } if (Field.Media.Height.HasValue) { MediaElement.Height = Field.Media.Height.Value; } } DockPanel ControlPanel = new DockPanel() { Width = 290 }; Container.Children.Add(ControlPanel); Button Button = new Button() { Width = 50, Height = 23, Margin = new Thickness(0, 0, 5, 0), Content = "<<", Tag = MediaElement }; ControlPanel.Children.Add(Button); Button.Click += new RoutedEventHandler(Rewind_Click); Button = new Button() { Width = 50, Height = 23, Margin = new Thickness(5, 0, 5, 0), Content = "Play", Tag = MediaElement }; ControlPanel.Children.Add(Button); Button.Click += new RoutedEventHandler(Play_Click); Button = new Button() { Width = 50, Height = 23, Margin = new Thickness(5, 0, 5, 0), Content = "Pause", Tag = MediaElement }; ControlPanel.Children.Add(Button); Button.Click += new RoutedEventHandler(Pause_Click); Button = new Button() { Width = 50, Height = 23, Margin = new Thickness(5, 0, 5, 0), Content = "Stop", Tag = MediaElement }; ControlPanel.Children.Add(Button); Button.Click += new RoutedEventHandler(Stop_Click); Button = new Button() { Width = 50, Height = 23, Margin = new Thickness(5, 0, 0, 0), Content = ">>", Tag = MediaElement }; ControlPanel.Children.Add(Button); Button.Click += new RoutedEventHandler(Forward_Click); MediaElement.Play(); } }
/// <summary> /// Class managing a page in a data form layout. /// </summary> /// <param name="Form">Data Form.</param> /// <param name="Label">Label</param> /// <param name="Fields">Fields to include in section. These will be converted to <see cref="FieldReference"/> objects.</param> public Page(DataForm Form, string Label, Field[] Fields) : base(Form, Label, Fields) { }
private void Layout(Panel Container, TextSingleField Field, DataForm Form) { TextBox TextBox = this.LayoutTextBox(Container, Field); TextBox.TextChanged += new TextChangedEventHandler(TextBox_TextChanged); }
internal Page(DataForm Form, string Title, ReportedReference ReportedReference) : base(Form, Title, ReportedReference) { }
/// <summary> /// Contains options for a node subscription /// </summary> public SubscriptionOptions(DataForm Form) { foreach (Field F in Form.Fields) { switch (F.Var) { case "pubsub#deliver": if (CommonTypes.TryParse(F.ValueString, out bool b)) { this.deliver = b; } break; case "pubsub#digest": if (CommonTypes.TryParse(F.ValueString, out b)) { this.digest = b; } break; case "pubsub#include_body": if (CommonTypes.TryParse(F.ValueString, out b)) { this.includeBody = b; } break; case "pubsub#digest_frequency": if (int.TryParse(F.ValueString, out int i)) { this.digestFrequencyMilliseconds = i; } break; case "pubsub#expire": if (DateTime.TryParse(F.ValueString, out DateTime TP)) { this.expires = TP; } break; case "pubsub#subscription_type": if (Enum.TryParse(F.ValueString, out SubscriptionType SubscriptionType)) { this.type = SubscriptionType; } break; case "pubsub#subscription_depth": if (F.ValueString == "1") { this.depth = SubscriptonDepth.one; } else if (Enum.TryParse(F.ValueString, out SubscriptonDepth SubscriptonDepth)) { this.depth = SubscriptonDepth; } break; } } }
/// <summary> /// JidSingle form field. /// </summary> /// <param name="Form">Form containing the field.</param> /// <param name="Var">Variable name</param> /// <param name="Label">Label</param> /// <param name="Required">If the field is required.</param> /// <param name="ValueStrings">Values for the field (string representations).</param> /// <param name="Options">Options, as (Label,Value) pairs.</param> /// <param name="Description">Description</param> /// <param name="DataType">Data Type</param> /// <param name="ValidationMethod">Validation Method</param> /// <param name="Error">Flags the field as having an error.</param> /// <param name="PostBack">Flags a field as requiring server post-back after having been edited.</param> /// <param name="ReadOnly">Flags a field as being read-only.</param> /// <param name="NotSame">Flags a field as having an undefined or uncertain value.</param> public JidSingleField(DataForm Form, string Var, string Label, bool Required, string[] ValueStrings, KeyValuePair <string, string>[] Options, string Description, DataType DataType, ValidationMethod ValidationMethod, string Error, bool PostBack, bool ReadOnly, bool NotSame) : base(Form, Var, Label, Required, ValueStrings, Options, Description, DataType, ValidationMethod, Error, PostBack, ReadOnly, NotSame) { }
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\ #region --Constructors-- /// <summary> /// Basic Constructor /// </summary> /// <history> /// 02/06/2018 Created [Fabian Sauter] /// </history> public PubSubPublishOptions(DataForm options) { OPTIONS = options; }
/// <summary> /// Initializes the test framework. /// </summary> public override void Initialize() { base.Initialize(); this.dataForm = new DataForm() { AutoEdit = false }; }
/// <summary> /// Sends a RoomInfoMessage and saves the given room configuration. /// </summary> /// <param name="roomJid">The bare JID if the room you would like to save the room configuration for. e.g. '*****@*****.**'</param> /// <param name="roomConfiguration">The new room configuration.</param> /// <param name="configLevel">The requested configuration level (the senders affiliation).</param> /// <param name="onMessage">The method that should get executed once the helper receives a new valid message.</param> /// <param name="onTimeout">The method that should get executed once the helper timeout gets triggered.</param> /// <returns>Returns a MessageResponseHelper listening for RoomInfoMessage answers.</returns> public MessageResponseHelper <IQMessage> saveRoomConfiguration(string roomJid, DataForm roomConfiguration, MUCAffiliation configLevel, MessageResponseHelper <IQMessage> .OnMessageHandler onMessage, MessageResponseHelper <IQMessage> .OnTimeoutHandler onTimeout) { MessageResponseHelper <IQMessage> helper = new MessageResponseHelper <IQMessage>(CONNECTION, onMessage, onTimeout); RoomInfoMessage msg = new RoomInfoMessage(CONNECTION.account.getFullJid(), roomJid, roomConfiguration, configLevel); helper.start(msg); return(helper); }
/// <summary> /// Sends a PubSubCreateNodeMessage for creating a pubsub node. /// https://xmpp.org/extensions/xep-0060.html#owner-create-and-configure /// </summary> /// <param name="to">The target pubsub server (can be null).</param> /// <param name="nodeName">The name of the node, you want to create.</param> /// <param name="config">The configuration for the node.</param> /// <param name="onMessage">The method that should get executed once the helper receives a new valid message (can be null).</param> /// <param name="onTimeout">The method that should get executed once the helper timeout gets triggered (can be null).</param> /// <returns>Returns a MessageResponseHelper listening for PubSubCreateNodeMessage answers.</returns> public MessageResponseHelper <IQMessage> createNode(string to, string nodeName, DataForm config, Func <IQMessage, bool> onMessage, Action onTimeout) { MessageResponseHelper <IQMessage> helper = new MessageResponseHelper <IQMessage>(CLIENT, onMessage, onTimeout); PubSubCreateNodeMessage msg = new PubSubCreateNodeMessage(CLIENT.getXMPPAccount().getIdDomainAndResource(), to, nodeName, config); helper.start(msg); return(helper); }
private async Task SetHandler(object Sender, IqEventArgs e) { string ServiceToken = XML.Attribute(e.Query, "st"); string DeviceToken = XML.Attribute(e.Query, "dt"); string UserToken = XML.Attribute(e.Query, "ut"); LinkedList <IThingReference> Nodes = null; SortedDictionary <string, bool> ParameterNames = this.provisioningClient is null ? null : new SortedDictionary <string, bool>(); LinkedList <ControlOperation> Operations = new LinkedList <ControlOperation>(); ControlParameter Parameter; DataForm Form = null; XmlElement E; string Name; foreach (XmlNode N in e.Query.ChildNodes) { E = N as XmlElement; if (E is null) { continue; } switch (E.LocalName) { case "nd": if (Nodes is null) { Nodes = new LinkedList <IThingReference>(); } string NodeId = XML.Attribute(E, "id"); string SourceId = XML.Attribute(E, "src"); string Partition = XML.Attribute(E, "pt"); if (this.OnGetNode is null) { Nodes.AddLast(new ThingReference(NodeId, SourceId, Partition)); } else { IThingReference Ref = await this.OnGetNode(NodeId, SourceId, Partition); if (Ref is null) { throw new ItemNotFoundException("Node not found.", e.IQ); } Nodes.AddLast(Ref); } break; case "b": case "cl": case "d": case "dt": case "db": case "dr": case "e": case "i": case "l": case "s": case "t": if (ParameterNames != null) { ParameterNames[XML.Attribute(E, "n")] = true; } break; case "x": Form = new DataForm(this.client, E, null, null, e.From, e.To); if (Form.Type != FormType.Submit) { ParameterBadRequest(e); return; } if (ParameterNames != null) { foreach (Field Field in Form.Fields) { ParameterNames[Field.Var] = true; } } break; default: ParameterBadRequest(e); return; } } foreach (XmlNode N in e.Query.ChildNodes) { E = N as XmlElement; if (E is null) { continue; } switch (E.LocalName) { case "b": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } BooleanControlParameter BooleanControlParameter = Parameter as BooleanControlParameter; if (BooleanControlParameter is null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new BooleanControlOperation(Node, BooleanControlParameter, XML.Attribute(E, "v", false), e)); } break; case "cl": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } ColorControlParameter ColorControlParameter = Parameter as ColorControlParameter; if (ColorControlParameter is null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new ColorControlOperation(Node, ColorControlParameter, XML.Attribute(E, "v"), e)); } break; case "d": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } DateControlParameter DateControlParameter = Parameter as DateControlParameter; if (DateControlParameter is null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new DateControlOperation(Node, DateControlParameter, XML.Attribute(E, "v", DateTime.MinValue), e)); } break; case "dt": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } DateTimeControlParameter DateTimeControlParameter = Parameter as DateTimeControlParameter; if (DateTimeControlParameter is null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new DateTimeControlOperation(Node, DateTimeControlParameter, XML.Attribute(E, "v", DateTime.MinValue), e)); } break; case "db": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } DoubleControlParameter DoubleControlParameter = Parameter as DoubleControlParameter; if (DoubleControlParameter is null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new DoubleControlOperation(Node, DoubleControlParameter, XML.Attribute(E, "v", 0.0), e)); } break; case "dr": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } DurationControlParameter DurationControlParameter = Parameter as DurationControlParameter; if (DurationControlParameter is null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new DurationControlOperation(Node, DurationControlParameter, XML.Attribute(E, "v", Duration.Zero), e)); } break; case "e": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } string StringValue = XML.Attribute(E, "v"); if (Parameter is EnumControlParameter EnumControlParameter) { Type T = Types.GetType(XML.Attribute(E, "t")); if (T is null) { e.IqError("<error type='modify'><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><paramError xmlns=\"" + ControlClient.NamespaceControl + "\" n=\"" + Name + "\">Type not found.</paramError></error>"); return; } if (!T.GetTypeInfo().IsEnum) { e.IqError("<error type='modify'><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><paramError xmlns=\"" + ControlClient.NamespaceControl + "\" n=\"" + Name + "\">Type is not an enumeration.</paramError></error>"); return; } Enum Value; try { Value = (Enum)Enum.Parse(T, StringValue); } catch (Exception) { e.IqError("<error type='modify'><bad-request xmlns=\"urn:ietf:params:xml:ns:xmpp-stanzas\"/><paramError xmlns=\"" + ControlClient.NamespaceControl + "\" n=\"" + Name + "\">Value not valid element of enumeration.</paramError></error>"); return; } Operations.AddLast(new EnumControlOperation(Node, EnumControlParameter, Value, e)); } else if (Parameter is StringControlParameter StringControlParameter) { Operations.AddLast(new StringControlOperation(Node, StringControlParameter, StringValue, e)); } else if (Parameter is MultiLineTextControlParameter MultiLineTextControlParameter) { Operations.AddLast(new MultiLineTextControlOperation(Node, MultiLineTextControlParameter, StringValue, e)); } else { ParameterWrongType(Name, e); return; } } break; case "i": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } Int32ControlParameter Int32ControlParameter = Parameter as Int32ControlParameter; if (Int32ControlParameter is null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new Int32ControlOperation(Node, Int32ControlParameter, XML.Attribute(E, "v", 0), e)); } break; case "l": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } Int64ControlParameter Int64ControlParameter = Parameter as Int64ControlParameter; if (Int64ControlParameter is null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new Int64ControlOperation(Node, Int64ControlParameter, XML.Attribute(E, "v", 0L), e)); } break; case "s": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } if (Parameter is StringControlParameter StringControlParameter) { Operations.AddLast(new StringControlOperation(Node, StringControlParameter, XML.Attribute(E, "v"), e)); } else if (Parameter is MultiLineTextControlParameter MultiLineTextControlParameter) { Operations.AddLast(new MultiLineTextControlOperation(Node, MultiLineTextControlParameter, XML.Attribute(E, "v"), e)); } else { ParameterWrongType(Name, e); return; } } break; case "t": Name = XML.Attribute(E, "n"); foreach (IThingReference Node in Nodes ?? NoNodes) { Parameter = await this.GetParameter(Node, Name, e); if (Parameter is null) { return; } TimeControlParameter TimeControlParameter = Parameter as TimeControlParameter; if (TimeControlParameter is null) { ParameterWrongType(Name, e); return; } Operations.AddLast(new TimeControlOperation(Node, TimeControlParameter, XML.Attribute(E, "v", TimeSpan.Zero), e)); } break; case "x": Dictionary <string, ControlParameter> Parameters; foreach (IThingReference Node in Nodes ?? NoNodes) { Parameters = await this.GetControlParametersByName(Node); if (Parameters is null) { NotFound(e); return; } foreach (Field Field in Form.Fields) { if (!Parameters.TryGetValue(Field.Var, out Parameter)) { ParameterNotFound(Field.Var, e); return; } Operations.AddLast(new FormControlOperation(Node, Parameter, Field.ValueString, e)); } } break; } } if (this.provisioningClient != null) { string[] ParameterNames2 = new string[ParameterNames.Count]; ParameterNames.Keys.CopyTo(ParameterNames2, 0); this.provisioningClient.CanControl(e.FromBareJid, Nodes, ParameterNames2, ServiceToken.Split(space, StringSplitOptions.RemoveEmptyEntries), DeviceToken.Split(space, StringSplitOptions.RemoveEmptyEntries), UserToken.Split(space, StringSplitOptions.RemoveEmptyEntries), async(sender2, e2) => { if (e2.Ok && e2.CanControl) { LinkedList <ControlOperation> Operations2 = null; bool Restricted; if (e2.Nodes != null || e2.ParameterNames != null) { Dictionary <IThingReference, bool> AllowedNodes = null; Dictionary <string, bool> AllowedParameterNames = null; Operations2 = new LinkedList <ControlOperation>(); Restricted = false; if (e2.Nodes != null) { AllowedNodes = new Dictionary <IThingReference, bool>(); foreach (IThingReference Node in e2.Nodes) { AllowedNodes[Node] = true; } } if (e2.ParameterNames != null) { AllowedParameterNames = new Dictionary <string, bool>(); foreach (string ParameterName in e2.ParameterNames) { AllowedParameterNames[ParameterName] = true; } } foreach (ControlOperation Operation in Operations) { if (AllowedNodes != null && !AllowedNodes.ContainsKey(Operation.Node ?? ThingReference.Empty)) { Restricted = true; continue; } if (AllowedParameterNames != null && !AllowedParameterNames.ContainsKey(Operation.ParameterName)) { Restricted = true; continue; } Operations2.AddLast(Operation); } } else { Restricted = false; } if (Restricted) { await this.PerformOperations(Operations2, e, e2.Nodes, e2.ParameterNames); } else { await this.PerformOperations(Operations, e, null, null); } } else { e.IqError("<error type='cancel'><forbidden xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>" + "<text xmlns='urn:ietf:params:xml:ns:xmpp-stanzas' xml:lang='en'>Access denied.</text></error>"); } }, null); } else { await this.PerformOperations(Operations, e, null, null); } }
private void dataClick(object sender, System.EventArgs e) { DataForm dataForm = new DataForm(graph, null, this); dataForm.Reset(); dataForm.Show(); }
/// <summary> /// Sets parameters from a data form in an object. /// </summary> /// <param name="e">IQ Event Arguments describing the request.</param> /// <param name="EditableObject">Object whose parameters will be set.</param> /// <param name="Form">Data Form.</param> /// <param name="OnlySetChanged">If only changed parameters are to be set.</param> /// <returns>Any errors encountered, or null if parameters was set properly.</returns> public static async Task <SetEditableFormResult> SetEditableForm(IqEventArgs e, object EditableObject, DataForm Form, bool OnlySetChanged) { Type T = EditableObject.GetType(); string DefaultLanguageCode = GetDefaultLanguageCode(T); List <KeyValuePair <string, string> > Errors = null; PropertyInfo PI; Language Language = await ConcentratorServer.GetLanguage(e.Query, DefaultLanguageCode); Namespace Namespace = null; Namespace ConcentratorNamespace = await Language.GetNamespaceAsync(typeof(ConcentratorServer).Namespace); LinkedList <KeyValuePair <PropertyInfo, object> > ToSet = null; ValidationMethod ValidationMethod; OptionAttribute OptionAttribute; RegularExpressionAttribute RegularExpressionAttribute; RangeAttribute RangeAttribute; DataType DataType; Type PropertyType; string NamespaceStr; string LastNamespaceStr = null; object ValueToSet; object ValueToSet2; object[] Parsed; bool ReadOnly; bool Alpha; bool DateOnly; bool HasHeader; bool HasOptions; bool ValidOption; bool Nullable; if (Namespace == null) { Namespace = await Language.CreateNamespaceAsync(T.Namespace); } if (ConcentratorNamespace == null) { ConcentratorNamespace = await Language.CreateNamespaceAsync(typeof(ConcentratorServer).Namespace); } foreach (Field Field in Form.Fields) { PI = T.GetRuntimeProperty(Field.Var); if (PI == null) { AddError(ref Errors, Field.Var, await ConcentratorNamespace.GetStringAsync(1, "Property not found.")); continue; } if (!PI.CanRead || !PI.CanWrite) { AddError(ref Errors, Field.Var, await ConcentratorNamespace.GetStringAsync(2, "Property not editable.")); continue; } NamespaceStr = PI.DeclaringType.Namespace; if (Namespace == null || NamespaceStr != LastNamespaceStr) { Namespace = await Language.GetNamespaceAsync(NamespaceStr); LastNamespaceStr = NamespaceStr; } ValidationMethod = null; ReadOnly = Alpha = DateOnly = HasHeader = HasOptions = ValidOption = false; foreach (Attribute Attr in PI.GetCustomAttributes()) { if (Attr is HeaderAttribute) { HasHeader = true; } else if ((OptionAttribute = Attr as OptionAttribute) != null) { HasOptions = true; if (Field.ValueString == OptionAttribute.Option.ToString()) { ValidOption = true; } } else if ((RegularExpressionAttribute = Attr as RegularExpressionAttribute) != null) { ValidationMethod = new RegexValidation(RegularExpressionAttribute.Pattern); } else if ((RangeAttribute = Attr as RangeAttribute) != null) { ValidationMethod = new RangeValidation(RangeAttribute.Min, RangeAttribute.Max); } else if (Attr is OpenAttribute) { ValidationMethod = new OpenValidation(); } else if (Attr is ReadOnlyAttribute) { ReadOnly = true; } else if (Attr is AlphaChannelAttribute) { Alpha = true; } else if (Attr is DateOnlyAttribute) { DateOnly = true; } } if (!HasHeader) { AddError(ref Errors, Field.Var, await ConcentratorNamespace.GetStringAsync(2, "Property not editable.")); continue; } if (ReadOnly) { if (Field.ValueString != PI.GetValue(EditableObject)?.ToString()) { AddError(ref Errors, Field.Var, await ConcentratorNamespace.GetStringAsync(3, "Property is read-only.")); } continue; } if (HasOptions && !ValidOption) { AddError(ref Errors, Field.Var, await ConcentratorNamespace.GetStringAsync(4, "Select a valid option.")); continue; } PropertyType = PI.PropertyType; ValueToSet = null; ValueToSet2 = null; Parsed = null; DataType = null; Nullable = false; if (PropertyType.GetTypeInfo().IsGenericType) { Type GT = PropertyType.GetGenericTypeDefinition(); if (GT == typeof(Nullable <>)) { Nullable = true; PropertyType = PropertyType.GenericTypeArguments[0]; } } if (Nullable && string.IsNullOrEmpty(Field.ValueString)) { ValueToSet2 = null; } else { if (PropertyType == typeof(string[])) { if (ValidationMethod == null) { ValidationMethod = new BasicValidation(); } ValueToSet = ValueToSet2 = Parsed = Field.ValueStrings; DataType = StringDataType.Instance; } else if (PropertyType.GetTypeInfo().IsEnum) { if (ValidationMethod == null) { ValidationMethod = new BasicValidation(); } try { ValueToSet = ValueToSet2 = Enum.Parse(PropertyType, Field.ValueString); } catch (Exception) { AddError(ref Errors, Field.Var, await ConcentratorNamespace.GetStringAsync(4, "Select a valid option.")); continue; } } else if (PropertyType == typeof(bool)) { if (ValidationMethod == null) { ValidationMethod = new BasicValidation(); } if (!CommonTypes.TryParse(Field.ValueString, out bool b)) { AddError(ref Errors, Field.Var, await ConcentratorNamespace.GetStringAsync(5, "Invalid boolean value.")); continue; } DataType = BooleanDataType.Instance; ValueToSet = ValueToSet2 = b; } else { if (PropertyType == typeof(string)) { DataType = StringDataType.Instance; } else if (PropertyType == typeof(sbyte)) { DataType = ByteDataType.Instance; } else if (PropertyType == typeof(short)) { DataType = ShortDataType.Instance; } else if (PropertyType == typeof(int)) { DataType = IntDataType.Instance; } else if (PropertyType == typeof(long)) { DataType = LongDataType.Instance; } else if (PropertyType == typeof(byte)) { DataType = ShortDataType.Instance; if (ValidationMethod == null) { ValidationMethod = new RangeValidation(byte.MinValue.ToString(), byte.MaxValue.ToString()); } } else if (PropertyType == typeof(ushort)) { DataType = IntDataType.Instance; if (ValidationMethod == null) { ValidationMethod = new RangeValidation(ushort.MinValue.ToString(), ushort.MaxValue.ToString()); } } else if (PropertyType == typeof(uint)) { DataType = LongDataType.Instance; if (ValidationMethod == null) { ValidationMethod = new RangeValidation(uint.MinValue.ToString(), uint.MaxValue.ToString()); } } else if (PropertyType == typeof(ulong)) { DataType = IntegerDataType.Instance; if (ValidationMethod == null) { ValidationMethod = new RangeValidation(ulong.MinValue.ToString(), ulong.MaxValue.ToString()); } } else if (PropertyType == typeof(DateTime)) { if (DateOnly) { DataType = DateDataType.Instance; } else { DataType = DateTimeDataType.Instance; } } else if (PropertyType == typeof(decimal)) { DataType = DecimalDataType.Instance; } else if (PropertyType == typeof(double)) { DataType = DoubleDataType.Instance; } else if (PropertyType == typeof(float)) { DataType = DoubleDataType.Instance; // Use xs:double anyway } else if (PropertyType == typeof(TimeSpan)) { DataType = TimeDataType.Instance; } else if (PropertyType == typeof(Uri)) { DataType = AnyUriDataType.Instance; } else if (PropertyType == typeof(SKColor)) { if (Alpha) { DataType = ColorAlphaDataType.Instance; } else { DataType = ColorDataType.Instance; } } else { DataType = null; } if (ValidationMethod == null) { ValidationMethod = new BasicValidation(); } try { if (DataType == null) { ValueToSet = Field.ValueString; ValueToSet2 = Activator.CreateInstance(PropertyType, ValueToSet); } else { ValueToSet = DataType.Parse(Field.ValueString); if (ValueToSet.GetType() == PropertyType) { ValueToSet2 = ValueToSet; } else { ValueToSet2 = Convert.ChangeType(ValueToSet, PropertyType); } } } catch (Exception) { AddError(ref Errors, Field.Var, await ConcentratorNamespace.GetStringAsync(6, "Invalid value.")); continue; } } if (Parsed == null) { Parsed = new object[] { ValueToSet } } ; ValidationMethod.Validate(Field, DataType, Parsed, Field.ValueStrings); if (Field.HasError) { AddError(ref Errors, Field.Var, Field.Error); continue; } } if (ToSet == null) { ToSet = new LinkedList <KeyValuePair <PropertyInfo, object> >(); } ToSet.AddLast(new KeyValuePair <PropertyInfo, object>(PI, ValueToSet2)); } if (Errors == null) { SetEditableFormResult Result = new SetEditableFormResult() { Errors = null, Tags = new List <KeyValuePair <string, object> >() }; foreach (KeyValuePair <PropertyInfo, object> P in ToSet) { try { if (OnlySetChanged) { object Current = P.Key.GetValue(EditableObject); if (Current == null) { if (P.Value == null) { continue; } } else if (P.Value != null && Current.Equals(P.Value)) { continue; } } P.Key.SetValue(EditableObject, P.Value); Result.Tags.Add(new KeyValuePair <string, object>(P.Key.Name, P.Value)); } catch (Exception ex) { AddError(ref Errors, P.Key.Name, ex.Message); } } return(Result); } else { return(new SetEditableFormResult() { Errors = Errors.ToArray(), Tags = null }); } }