public void TestControlTypes() { TextControl textControl = new TextControl(); Assert.AreEqual(ControlType.Text, textControl.Type); ComboControl comboControl = new ComboControl(); Assert.AreEqual(ControlType.Combo, comboControl.Type); RadioControl radioControl = new RadioControl(); Assert.AreEqual(ControlType.Radio, radioControl.Type); CheckboxControl checkboxControl = new CheckboxControl(); Assert.AreEqual(ControlType.Checkbox, checkboxControl.Type); CheckboxGroupControl checkboxGroupControl = new CheckboxGroupControl(); Assert.AreEqual(ControlType.CheckboxGroup, checkboxGroupControl.Type); DateControl dateControl = new DateControl(); Assert.AreEqual(ControlType.Date, dateControl.Type); TimeControl timeControl = new TimeControl(); Assert.AreEqual(ControlType.Time, timeControl.Type); FileBrowserControl fileBrowserControl = new FileBrowserControl(); Assert.AreEqual(ControlType.FileBrowser, fileBrowserControl.Type); HiddenControl hiddenControl = new HiddenControl(); Assert.AreEqual(ControlType.Hidden, hiddenControl.Type); LabelControl labelControl = new LabelControl(); Assert.AreEqual(ControlType.Label, labelControl.Type); HtmlControl htmlControl = new HtmlControl(); Assert.AreEqual(ControlType.Html, htmlControl.Type); GroupControl groupControl = new GroupControl(); Assert.AreEqual(ControlType.Group, groupControl.Type); RepeaterControl repeaterControl = new RepeaterControl(); Assert.AreEqual(ControlType.Repeater, repeaterControl.Type); CalculationControl calculationControl = new CalculationControl(); Assert.AreEqual(ControlType.Calculation, calculationControl.Type); SignaturePadControl signaturePadControl = new SignaturePadControl(); Assert.AreEqual(ControlType.SignaturePad, signaturePadControl.Type); GeolocationControl geolocationControl = new GeolocationControl(); Assert.AreEqual(ControlType.Geolocation, geolocationControl.Type); HeadingControl headingControl = new HeadingControl(); Assert.AreEqual(ControlType.Heading, headingControl.Type); }
/// <summary> /// Runs a calculation and adds the result to <paramref name="resultsContainer"/>. /// </summary> /// <param name="control">The calculation to run.</param> /// <param name="resultsContainer">A dictionary of results.</param> /// <param name="exceptionList">A list that <see cref="ExpressionEvaluatorException"/>s will be added to before returning to the client.</param> private void Calculate(CalculationControl control, Dictionary<string, object> resultsContainer, List<ExpressionEvaluatorException> exceptionList) { ApplicationDataPath absolutePath = control.CreatePathTemplate(this.controlList); if (control.IsRepeaterDescendant(this.controlList)) { ApplicationDataPath relativePath = new ApplicationDataPath(absolutePath); this.CalculateRepeater(control, relativePath, absolutePath, resultsContainer, this.Application.ApplicationData, exceptionList); return; } try { resultsContainer[control.Name] = this.Evaluate(control.CalculationExpression, absolutePath); this.Application.ApplicationData.SetValue(control.Name, resultsContainer[control.Name], true); } catch (ExpressionEvaluatorException e) { e.Tag = control.Name; exceptionList.Add(e); } }
/// <summary> /// Runs a calculation for all instances of a repeater and adds the result to <paramref name="resultsContainer"/>. /// </summary> /// <param name="control">The calculation to run.</param> /// <param name="relativePath">The relative path to <paramref name="control"/> within <paramref name="resultsContainer"/> and <paramref name="applicationContainer"/>.</param> /// <param name="absolutePath">The absolute path to <paramref name="control"/> from the root of the application data.</param> /// <param name="resultsContainer">A dictionary of results.</param> /// <param name="applicationContainer">The application data container.</param> /// <param name="exceptionList">A list that <see cref="ExpressionEvaluatorException"/>s will be added to before returning to the client.</param> private void CalculateRepeater(CalculationControl control, ApplicationDataPath relativePath, ApplicationDataPath absolutePath, Dictionary<string, object> resultsContainer, Dictionary<string, object> applicationContainer, List<ExpressionEvaluatorException> exceptionList) { if (relativePath.Count == 0) { try { var result = this.Evaluate(control.CalculationExpression, absolutePath); resultsContainer[control.Name] = result; applicationContainer[control.Name] = result; } catch (ExpressionEvaluatorException e) { e.Tag = absolutePath.ToString(control.Name); exceptionList.Add(e); } return; } ApplicationDataPathSegment segment = relativePath.TraverseDown(); Dictionary<string, object>[] repeaterCalculationResults = (Dictionary<string, object>[])resultsContainer[segment.Name]; Dictionary<string, object>[] repeaterApplicationData = applicationContainer.GetRepeaterItemsOrDefault(segment.Name); for (var i = 0; i < repeaterCalculationResults.Length; i++) { segment.Index = i; absolutePath.FirstOrDefault(s => s.Name == segment.Name).Index = segment.Index; this.CalculateRepeater(control, new ApplicationDataPath(relativePath), absolutePath, repeaterCalculationResults[i], repeaterApplicationData[i], exceptionList); } }