private string CurrentCultureStringToValueSetString(string currentCultureString) { var defaultValue = ValueSetConverter.DefaultObject(this.SelectedParameterType); if (currentCultureString == null) { return((string)defaultValue); } if (!currentCultureString.Equals(defaultValue)) { if (new[] { ClassKind.DateTimeParameterType, ClassKind.DateParameterType, ClassKind.TimeOfDayParameterType }.Contains(this.SelectedParameterType.ClassKind)) { if (!DateTime.TryParse(currentCultureString, out var dateTimeObject)) { throw new Cdp4ModelValidationException($"{currentCultureString} is not a valid value for a {this.SelectedParameterType.ClassKind}."); } var validationResult = ParameterValueValidator.Validate(dateTimeObject, this.SelectedParameterType, this.SelectedScale); if (validationResult != null) { throw new Cdp4ModelValidationException(validationResult); } return(dateTimeObject.ToValueSetString(this.SelectedParameterType)); } } return(currentCultureString); }
/// <summary> /// Gets the published value <see cref="ValueArray{String}"/> for this <see cref="NestedParameter"/> /// </summary> /// <returns>The published <see cref="ValueArray{String}"/></returns> public ValueArray <string> GetPublishedValue() { if (this.AssociatedParameter is ParameterSubscription) { return(this.ValueSet.Computed); } if (this.AssociatedParameter is ParameterOrOverrideBase parameterOrOverrideBase) { var parameterValueSetBase = parameterOrOverrideBase.QueryParameterBaseValueSet(this.Option, this.ActualState) as ParameterValueSetBase; var published = parameterValueSetBase?.Published; if (published != null) { return(published); } } return(new ValueArray <string>( new [] { ValueSetConverter.DefaultObject(this.AssociatedParameter.ParameterType).ToValueSetString(this.AssociatedParameter.ParameterType) }, this.AssociatedParameter )); }
/// <summary> /// Update value-set for a not-compound parameter. /// </summary> /// <param name="valueSet">The value set to update</param> /// <param name="row">The value row containing the information. If null the data is retrieved from the current row.</param> /// <remarks> /// If <paramref name="row"/> is null, it means the parameter is not compound, not option dependent and not state dependent. /// </remarks> private void UpdateSimpleValueSet(ParameterSubscriptionValueSet valueSet, ParameterValueBaseRowViewModel row = null) { valueSet.ValueSwitch = row == null ? this.Switch.Value : row.Switch.Value; valueSet.Manual = row == null ? new ValueArray <string>(new List <string> { ValueSetConverter.ToValueSetString(this.Manual, this.ParameterType) }) : new ValueArray <string>(new List <string> { ValueSetConverter.ToValueSetString(row.Manual, this.ParameterType) }); }
/// <summary> /// Process the <see cref="ParameterValueSet"/> . /// </summary> /// <param name="parameterValueSet"> /// The <see cref="ParameterValueSetBase"/> to be processed. /// </param> /// <param name="parameterOrOverrideBase"> /// The <see cref="ParameterOrOverrideBase"/> the <see cref="ParameterValueSetBase"/ belongs to. /// </param> /// <param name="componentIndex"> /// The index of the <see cref="ParameterTypeComponent"/>. /// </param> /// <param name="computedValue"> /// The manual value of the <see cref="ParameterValueSet"/>. /// </param> /// <param name="processedValueSets"> /// A <see cref="Dictionary{Guid,ProcessedValueSet}"/> of ProcessedValueSe that capture the updated <see cref="Thing"/>s with its value validation result /// </param> /// <param name="provider"> /// The <see cref="IFormatProvider"/> used to validate. /// </param> /// <param name="validationErrorText"> /// <see cref="String"/> that holds the validation error text. /// </param> /// <returns> /// The added or changed <see cref="ProcessedValueSet"/> /// </returns> private ProcessedValueSet ProcessValueSet(ParameterValueSetBase parameterValueSet, ParameterOrOverrideBase parameterOrOverrideBase, int componentIndex, string computedValue, ref Dictionary <Guid, ProcessedValueSet> processedValueSets, IFormatProvider provider, out string validationErrorText) { var validationResult = ValidationResultKind.InConclusive; var switchKind = parameterValueSet.ValueSwitch; var measurementScale = parameterOrOverrideBase.Scale; var parameterType = parameterOrOverrideBase.ParameterType; validationErrorText = string.Empty; if (parameterType != null) { if (ValueSetConverter.TryParseDouble(computedValue, parameterType, out var convertedComputedValue)) { computedValue = convertedComputedValue.ToString(CultureInfo.InvariantCulture); } computedValue = computedValue?.ToValueSetObject(parameterType).ToValueSetString(parameterType) ?? parameterValueSet.Computed[componentIndex]; var validManualValue = parameterType.Validate(computedValue, measurementScale, provider); if (validManualValue.ResultKind > validationResult) { validationResult = validManualValue.ResultKind; validationErrorText = validManualValue.Message; } } var valueSetExists = processedValueSets.TryGetValue(parameterValueSet.Iid, out var processedValueSet); if (!valueSetExists) { processedValueSet = new ProcessedValueSet(parameterValueSet, validationResult); } if (processedValueSet.IsDirty(componentIndex, parameterType, switchKind, parameterValueSet.Manual[componentIndex], computedValue, parameterValueSet.Reference[componentIndex], computedValue, out var valueSetValues)) { processedValueSet.UpdateClone(valueSetValues); if (!valueSetExists) { processedValueSets.Add(parameterValueSet.Iid, processedValueSet); } } return(processedValueSet); }
/// <summary> /// Sets the values of the <see cref="ParameterValueSetBase"/>. /// </summary> /// <param name="valueSet"> /// The valueSet. /// </param> private void SetValueSetValues(ParameterValueSetBase valueSet) { this.Value = valueSet.ActualValue.Any() ? valueSet.ActualValue.First() : "-"; this.ScaleShortName = this.Thing.Scale == null ? "-" : this.Thing.Scale.ShortName; this.Switch = valueSet.ValueSwitch; this.Formula = valueSet.Formula.Any() ? valueSet.Formula.First() : "-"; this.Computed = valueSet.Computed.Any() ? valueSet.Computed.First() : "-"; this.Manual = valueSet.Manual.Any() ? valueSet.Manual.First().ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Reference = valueSet.Reference.Any() ? valueSet.Reference.First().ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.State = valueSet.ActualState == null ? "-" : valueSet.ActualState.ShortName; this.Option = valueSet.ActualOption; this.Published = valueSet.Published.Any() ? valueSet.Published.First() : "-"; }
/// <summary> /// Update value-set for a not-compound parameter. /// </summary> /// <param name="valueSet">The value set to update</param> /// <param name="row">The value row containing the information. If null the data is retrieved from the current row.</param> /// <remarks> /// If <paramref name="row"/> is null, it means the parameter is not compound, not option dependent and not state dependent. /// </remarks> private void UpdateScalarValueSet(ParameterValueSetBase valueSet, ParameterValueBaseRowViewModel row = null) { valueSet.ValueSwitch = row == null ? this.Switch.Value : row.Switch.Value; valueSet.Computed = row == null ? new ValueArray <string>(new List <string> { this.Computed }) : new ValueArray <string>(new List <string> { row.Computed }); valueSet.Manual = row == null ? new ValueArray <string>(new List <string> { this.Manual.ToValueSetString(this.ParameterType) }) : new ValueArray <string>(new List <string> { row.Manual.ToValueSetString(this.ParameterType) }); valueSet.Reference = row == null ? new ValueArray <string>(new List <string> { this.Reference.ToValueSetString(this.ParameterType) }) : new ValueArray <string>(new List <string> { ValueSetConverter.ToValueSetString(row.Reference, this.ParameterType) }); }
public void VerifyThatValuesAreCalculatedCorrectly(string valueArrayValue, double expectedValue1, double expectedValue2, bool expectedTryParseResult, ParameterType parameterType) { var culture = new CultureInfo("en-GB") { NumberFormat = { NumberDecimalSeparator = ",", NumberGroupSeparator = "." } }; System.Threading.Thread.CurrentThread.CurrentCulture = culture; Assert.AreEqual(expectedTryParseResult, ValueSetConverter.TryParseDouble(valueArrayValue, parameterType, out var calculatedValue1)); Assert.AreEqual(expectedValue1, calculatedValue1); culture.NumberFormat.NumberDecimalSeparator = "."; culture.NumberFormat.NumberGroupSeparator = ","; Assert.AreEqual(expectedTryParseResult, ValueSetConverter.TryParseDouble(valueArrayValue, parameterType, out var calculatedValue2)); Assert.AreEqual(expectedValue2, calculatedValue2); }
/// <summary> /// Sets the values of this row in the case where the represented thing is a <see cref="ParameterSubscription"/> /// </summary> private void SetParameterSubscriptionValues() { var parameterSubscription = this.Thing as ParameterSubscription; if (parameterSubscription == null) { return; } if (this.ContainedRows.Any()) { return; } var valueSet = this.GetParameterSubscriptionValueSet(); if (valueSet == null) { logger.Error("No Value set was found for the option: {0}, state: {1}", (this.ActualOption == null) ? "null" : this.ActualOption.Name, (this.ActualState == null) ? "null" : this.ActualState.Name); return; } this.Switch = valueSet.ValueSwitch; this.Computed = valueSet.Computed.Count() > this.ValueIndex ? valueSet.Computed[this.ValueIndex] : "-"; this.Manual = valueSet.Manual.Count() > this.ValueIndex ? valueSet.Manual[this.ValueIndex].ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Reference = valueSet.Reference.Count() > this.ValueIndex ? valueSet.Reference[this.ValueIndex].ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Value = valueSet.ActualValue.Count() > this.ValueIndex ? valueSet.ActualValue[this.ValueIndex] : "-"; }
public void VerifyThatRowIsBuiltCorrectlyCompoundNoOptionWithState() { this.cptParameter.IsOptionDependent = false; this.cptParameter.ValueSet.Clear(); this.valueset1.ActualOption = null; this.valueset2.ActualOption = null; this.cptParameter.ValueSet.Add(this.valueset1); this.cptParameter.ValueSet.Add(this.valueset2); this.subscription = new ParameterSubscription(Guid.NewGuid(), null, this.uri); this.cptParameter.ParameterSubscription.Add(subscription); this.subscription.ValueSet.Add(new ParameterSubscriptionValueSet(Guid.NewGuid(), null, this.uri) { SubscribedValueSet = this.valueset1 }); this.subscription.ValueSet.Add(new ParameterSubscriptionValueSet(Guid.NewGuid(), null, this.uri) { SubscribedValueSet = this.valueset2 }); var row = new ParameterSubscriptionRowViewModel(this.subscription, this.session.Object, null); var s1Row = row.ContainedRows.OfType <ParameterStateRowViewModel>().Single(x => x.ActualState == this.actualState1); var s2Row = row.ContainedRows.OfType <ParameterStateRowViewModel>().Single(x => x.ActualState == this.actualState2); var s1c1Row = s1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var s1c2Row = s1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); var s2c1Row = s2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var s2c2Row = s2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); // state row Assert.IsFalse(s1Row.IsEditable()); Assert.IsFalse(s1Row.IsEditable()); // component row Assert.IsTrue(s1c1Row.IsEditable()); Assert.IsTrue(s1c2Row.IsEditable()); Assert.IsTrue(s2c1Row.IsEditable()); Assert.IsTrue(s2c2Row.IsEditable()); s1c1Row.Switch = ParameterSwitchKind.MANUAL; s1c2Row.Switch = ParameterSwitchKind.MANUAL; s2c1Row.Switch = ParameterSwitchKind.MANUAL; s2c2Row.Switch = ParameterSwitchKind.MANUAL; s1c2Row.Manual = new ReactiveList <EnumerationValueDefinition> { this.enum1 }; s2c2Row.Manual = new ReactiveList <EnumerationValueDefinition> { this.enum2 }; var s1Set = this.subscription.ValueSet.Single(x => x.ActualState == this.actualState1); var s2Set = this.subscription.ValueSet.Single(x => x.ActualState == this.actualState2); row.UpdateValueSets(this.subscription); Assert.AreEqual(s1Set.ValueSwitch, s1c1Row.Switch); Assert.AreEqual(s2Set.ValueSwitch, s2c2Row.Switch); Assert.AreEqual(s1Set.Manual[0], s1c1Row.Manual); Assert.AreEqual(s2Set.Manual[0], s2c1Row.Manual); Assert.AreEqual(s1Set.Manual[1], ValueSetConverter.ToValueSetString(s1c2Row.Manual, s1c2Row.ParameterType)); Assert.AreEqual(s2Set.Manual[1], ValueSetConverter.ToValueSetString(s2c2Row.Manual, s2c2Row.ParameterType)); }
public void VerifyThatRowIsBuiltCorrectlyCompoundOptionNoState() { this.cptParameter.StateDependence = null; this.cptParameter.ValueSet.Clear(); this.valueset1.ActualState = null; this.valueset3.ActualState = null; this.cptParameter.ValueSet.Add(this.valueset1); this.cptParameter.ValueSet.Add(this.valueset3); this.subscription = new ParameterSubscription(Guid.NewGuid(), null, this.uri); this.cptParameter.ParameterSubscription.Add(subscription); this.subscription.ValueSet.Add(new ParameterSubscriptionValueSet(Guid.NewGuid(), null, this.uri) { SubscribedValueSet = this.valueset1 }); this.subscription.ValueSet.Add(new ParameterSubscriptionValueSet(Guid.NewGuid(), null, this.uri) { SubscribedValueSet = this.valueset3 }); var row = new ParameterSubscriptionRowViewModel(this.subscription, this.session.Object, null); var option1Row = row.ContainedRows.OfType <ParameterOptionRowViewModel>().Single(x => x.ActualOption == this.option1); var option2Row = row.ContainedRows.OfType <ParameterOptionRowViewModel>().Single(x => x.ActualOption == this.option2); var o1c1Row = option1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var o1c2Row = option1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); var o2c1Row = option2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var o2c2Row = option2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); // option row Assert.IsFalse(option1Row.IsEditable()); Assert.IsFalse(option1Row.IsEditable()); // component row Assert.IsTrue(o1c1Row.IsEditable()); Assert.IsTrue(o1c2Row.IsEditable()); Assert.IsTrue(o2c1Row.IsEditable()); Assert.IsTrue(o2c2Row.IsEditable()); o1c1Row.Switch = ParameterSwitchKind.MANUAL; o1c2Row.Switch = ParameterSwitchKind.MANUAL; o2c1Row.Switch = ParameterSwitchKind.MANUAL; o2c2Row.Switch = ParameterSwitchKind.MANUAL; o1c2Row.Manual = new ReactiveList <EnumerationValueDefinition> { this.enum1 }; o2c2Row.Manual = new ReactiveList <EnumerationValueDefinition> { this.enum2 }; var o1Set = this.subscription.ValueSet.Single(x => x.ActualOption == this.option1); var o2Set = this.subscription.ValueSet.Single(x => x.ActualOption == this.option2); row.UpdateValueSets(this.subscription); Assert.AreEqual(o1Set.ValueSwitch, o1c1Row.Switch); Assert.AreEqual(o2Set.ValueSwitch, o2c2Row.Switch); Assert.AreEqual(o1Set.Manual[0], o1c1Row.Manual); Assert.AreEqual(o2Set.Manual[0], o2c1Row.Manual); Assert.AreEqual(o1Set.Manual[1], ValueSetConverter.ToValueSetString(o1c2Row.Manual, o1c2Row.ParameterType)); Assert.AreEqual(o2Set.Manual[1], ValueSetConverter.ToValueSetString(o2c2Row.Manual, o2c2Row.ParameterType)); }
public void VerifyThatUpdateValueSetWorksCompoundOptionState() { this.subscription = new ParameterSubscription(Guid.NewGuid(), null, this.uri); this.cptParameter.ParameterSubscription.Add(subscription); this.subscription.ValueSet.Add(new ParameterSubscriptionValueSet(Guid.NewGuid(), null, this.uri) { SubscribedValueSet = this.valueset1 }); this.subscription.ValueSet.Add(new ParameterSubscriptionValueSet(Guid.NewGuid(), null, this.uri) { SubscribedValueSet = this.valueset2 }); this.subscription.ValueSet.Add(new ParameterSubscriptionValueSet(Guid.NewGuid(), null, this.uri) { SubscribedValueSet = this.valueset3 }); this.subscription.ValueSet.Add(new ParameterSubscriptionValueSet(Guid.NewGuid(), null, this.uri) { SubscribedValueSet = this.valueset4 }); var row = new ParameterSubscriptionRowViewModel(this.subscription, this.session.Object, null); var option1Row = row.ContainedRows.OfType <ParameterOptionRowViewModel>().Single(x => x.ActualOption == this.option1); var option2Row = row.ContainedRows.OfType <ParameterOptionRowViewModel>().Single(x => x.ActualOption == this.option2); var o1s1Row = option1Row.ContainedRows.OfType <ParameterStateRowViewModel>() .Single(x => x.ActualState == this.actualState1); var o1s2Row = option1Row.ContainedRows.OfType <ParameterStateRowViewModel>() .Single(x => x.ActualState == this.actualState2); var o2s1Row = option2Row.ContainedRows.OfType <ParameterStateRowViewModel>() .Single(x => x.ActualState == this.actualState1); var o2s2Row = option2Row.ContainedRows.OfType <ParameterStateRowViewModel>() .Single(x => x.ActualState == this.actualState2); var o1s1c1Row = o1s1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var o1s1c2Row = o1s1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); var o1s2c1Row = o1s2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var o1s2c2Row = o1s2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); var o2s1c1Row = o2s1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var o2s1c2Row = o2s1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); var o2s2c1Row = o2s2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var o2s2c2Row = o2s2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); // option row Assert.IsFalse(option1Row.IsEditable()); Assert.IsFalse(option2Row.IsEditable()); // state row Assert.IsFalse(o1s1Row.IsEditable()); Assert.IsFalse(o1s2Row.IsEditable()); Assert.IsFalse(o2s1Row.IsEditable()); Assert.IsFalse(o2s2Row.IsEditable()); // component row Assert.IsTrue(o1s1c1Row.IsEditable()); Assert.IsTrue(o1s2c1Row.IsEditable()); Assert.IsTrue(o2s1c1Row.IsEditable()); Assert.IsTrue(o2s2c1Row.IsEditable()); o1s1c1Row.Switch = ParameterSwitchKind.REFERENCE; o1s1c2Row.Switch = ParameterSwitchKind.REFERENCE; o1s2c1Row.Switch = ParameterSwitchKind.REFERENCE; o1s2c2Row.Switch = ParameterSwitchKind.REFERENCE; o2s1c1Row.Switch = ParameterSwitchKind.REFERENCE; o2s1c2Row.Switch = ParameterSwitchKind.REFERENCE; o2s2c1Row.Switch = ParameterSwitchKind.REFERENCE; o2s2c2Row.Switch = ParameterSwitchKind.REFERENCE; o1s1c2Row.Manual = new ReactiveList <EnumerationValueDefinition> { this.enum1 }; o1s2c2Row.Manual = new ReactiveList <EnumerationValueDefinition> { this.enum1 }; o2s1c2Row.Manual = new ReactiveList <EnumerationValueDefinition> { this.enum2 }; o2s2c2Row.Manual = new ReactiveList <EnumerationValueDefinition> { this.enum2 }; var o1s1Set = this.subscription.ValueSet.Single(x => x.ActualOption == this.option1 && x.ActualState == this.actualState1); var o1s2Set = this.subscription.ValueSet.Single(x => x.ActualOption == this.option1 && x.ActualState == this.actualState2); var o2s1Set = this.subscription.ValueSet.Single(x => x.ActualOption == this.option2 && x.ActualState == this.actualState1); var o2s2Set = this.subscription.ValueSet.Single(x => x.ActualOption == this.option2 && x.ActualState == this.actualState2); row.UpdateValueSets(this.subscription); Assert.AreEqual(o1s1Set.ValueSwitch, o1s1c1Row.Switch); Assert.AreEqual(o1s2Set.ValueSwitch, o1s2c1Row.Switch); Assert.AreEqual(o2s1Set.ValueSwitch, o2s1c1Row.Switch); Assert.AreEqual(o2s2Set.ValueSwitch, o2s2c1Row.Switch); Assert.AreEqual(o1s1Set.Manual[0], o1s1c1Row.Manual); Assert.AreEqual(o1s2Set.Manual[0], o1s2c1Row.Manual); Assert.AreEqual(o2s1Set.Manual[0], o2s1c1Row.Manual); Assert.AreEqual(o2s2Set.Manual[0], o2s2c1Row.Manual); Assert.AreEqual(o1s1Set.Manual[1], ValueSetConverter.ToValueSetString(o1s1c2Row.Manual, o1s1c2Row.ParameterType)); Assert.AreEqual(o1s2Set.Manual[1], ValueSetConverter.ToValueSetString(o1s2c2Row.Manual, o1s2c2Row.ParameterType)); Assert.AreEqual(o2s1Set.Manual[1], ValueSetConverter.ToValueSetString(o2s1c2Row.Manual, o2s1c2Row.ParameterType)); Assert.AreEqual(o2s2Set.Manual[1], ValueSetConverter.ToValueSetString(o2s2c2Row.Manual, o2s2c2Row.ParameterType)); }
[ExcludeFromCodeCoverage] // Remove attribute when more logic is added to this method. It's only SDK functionality now and that is fully covered. public override double Parse(string value) { ValueSetConverter.TryParseDouble(value, this.ParameterBase?.ParameterType, out var parsedValue); return(parsedValue); }
/// <summary> /// Set the Values of this row /// </summary> private void SetValues() { if (this.Thing.ParameterType == null) { return; } var cptPt = this.Thing.ParameterType as CompoundParameterType; if (cptPt == null) { this.ParameterType = this.Thing.ParameterType; this.Scale = this.Thing.Scale; } else { var cpt = cptPt.Component[this.valueIndex]; this.ParameterType = cpt.ParameterType; this.Scale = cpt.Scale; } this.ParameterTypeName = this.ParameterType.Name; this.ParameterTypeClassKind = this.ParameterType.ClassKind; this.Manual = this.Thing.Value.Count() > this.valueIndex ? this.Thing.Value[this.valueIndex].ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); }
/// <summary> /// Sets the values of this row in case where the <see cref="ParameterSubscription"/> is neither option-dependent nor state-dependent and is a <see cref="ScalarParameterType"/> /// </summary> public override void SetProperties() { var valueset = this.Thing.ValueSet.FirstOrDefault(); if (valueset == null) { logger.Error("No value set was found for parameter subscription {0}", this.Thing.Iid); return; } this.Value = valueset.ActualValue.Any() ? valueset.ActualValue.First() : "-"; this.ScaleShortName = this.Thing.Scale == null ? "-" : this.Thing.Scale.ShortName; this.Switch = valueset.ValueSwitch; this.Computed = valueset.Computed.Any() ? valueset.Computed.First() : "-"; this.Manual = valueset.Manual.Any() ? valueset.Manual.First().ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Reference = valueset.Reference.Any() ? valueset.Reference.First().ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Formula = valueset.SubscribedValueSet.Formula.Any() ? valueset.SubscribedValueSet.Formula.First() : "-"; }
/// <summary> /// Sets the values of this row in case where the <see cref="ParameterSubscription"/> is neither option-dependent nor state-dependent and is a <see cref="ScalarParameterType"/> /// </summary> public override void SetProperties() { var valueset = this.Thing.ValueSet.FirstOrDefault(); if (valueset == null) { logger.Error("No value set was found for parameter subscription {0}", this.Thing.Iid); return; } this.Value = valueset.ActualValue.Any() ? valueset.ActualValue.First() : "-"; if (this.ContainedRows.Count == 0) { this.ScaleShortName = this.Thing.Scale == null ? "-" : this.Thing.Scale.ShortName; } this.Switch = valueset.ValueSwitch; this.Computed = valueset.Computed.Any() ? valueset.Computed.First() : "-"; this.Published = this.Computed; this.Manual = valueset.Manual.Any() ? valueset.Manual.First().ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Reference = valueset.Reference.Any() ? valueset.Reference.First().ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Formula = valueset.SubscribedValueSet.Formula.Any() ? valueset.SubscribedValueSet.Formula.First() : "-"; if (this.valueSetListener.Any()) { return; } var listener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(valueset) .Where(objectChange => objectChange.EventKind == EventKind.Updated && objectChange.ChangedThing.RevisionNumber > this.RevisionNumber) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => this.SetProperties()); this.valueSetListener.Add(listener); var subscribedListener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(valueset.SubscribedValueSet) .Where(objectChange => objectChange.EventKind == EventKind.Updated && objectChange.ChangedThing.RevisionNumber > this.RevisionNumber) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(_ => this.SetProperties()); this.valueSetListener.Add(subscribedListener); }
/// <summary> /// Sets the values of this row in the case where the represented thing is a <see cref="ParameterOrOverrideBase"/> /// </summary> private void SetParameterOrOverrideValues() { if (this.ContainedRows.Any()) { return; } ParameterValueSetBase valueSet; if (this.Thing is Parameter) { valueSet = this.GetParameterValueSet(); } else { valueSet = this.GetParameterOverrideValueSet(); } if (valueSet == null) { logger.Error("No Value set was found for the option: {0}, state: {1}", (this.ActualOption == null) ? "null" : this.ActualOption.Name, (this.ActualState == null) ? "null" : this.ActualState.Name); return; } this.Computed = valueSet.Computed.Count() > this.ValueIndex ? valueSet.Computed[this.ValueIndex] : "-"; this.Manual = valueSet.Manual.Count() > this.ValueIndex ? valueSet.Manual[this.ValueIndex].ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Reference = valueSet.Reference.Count() > this.ValueIndex ? valueSet.Reference[this.ValueIndex].ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Value = valueSet.ActualValue.Count() > this.ValueIndex ? valueSet.ActualValue[this.ValueIndex] : "-"; this.Formula = valueSet.Formula.Count() > this.ValueIndex ? valueSet.Formula[this.ValueIndex] : "-"; this.State = valueSet.ActualState != null ? valueSet.ActualState.Name : "-"; this.Option = valueSet.ActualOption; this.Switch = valueSet.ValueSwitch; this.Published = valueSet.Published.Count() > this.ValueIndex ? valueSet.Published[this.ValueIndex] : "-"; if (valueSet.Published.Count() <= this.ValueIndex) { this.Error = "No ValueSet found for this component"; } }
public void VerifyThatRowBuiltCorrectly() { var row = new ParameterRowViewModel(this.cptParameter, this.session.Object, null); var option1Row = row.ContainedRows.OfType <ParameterOptionRowViewModel>().Single(x => x.ActualOption == this.option1); var option2Row = row.ContainedRows.OfType <ParameterOptionRowViewModel>().Single(x => x.ActualOption == this.option2); var o1s1Row = option1Row.ContainedRows.OfType <ParameterStateRowViewModel>() .Single(x => x.ActualState == this.actualState1); var o1s2Row = option1Row.ContainedRows.OfType <ParameterStateRowViewModel>() .Single(x => x.ActualState == this.actualState2); var o2s1Row = option2Row.ContainedRows.OfType <ParameterStateRowViewModel>() .Single(x => x.ActualState == this.actualState1); var o2s2Row = option2Row.ContainedRows.OfType <ParameterStateRowViewModel>() .Single(x => x.ActualState == this.actualState2); var o1s1c1Row = o1s1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var o1s1c2Row = o1s1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); var o1s2c1Row = o1s2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var o1s2c2Row = o1s2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); var o2s1c1Row = o2s1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var o2s1c2Row = o2s1Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); var o2s2c1Row = o2s2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().First(); var o2s2c2Row = o2s2Row.ContainedRows.OfType <ParameterComponentValueRowViewModel>().Last(); // option row Assert.IsFalse(option1Row.IsEditable()); Assert.IsFalse(option2Row.IsEditable()); // state row Assert.IsFalse(o1s1Row.IsEditable()); Assert.IsFalse(o1s2Row.IsEditable()); Assert.IsFalse(o2s1Row.IsEditable()); Assert.IsFalse(o2s2Row.IsEditable()); // component row Assert.IsTrue(o1s1c1Row.IsEditable()); Assert.IsTrue(o1s2c1Row.IsEditable()); Assert.IsTrue(o2s1c1Row.IsEditable()); Assert.IsTrue(o2s2c1Row.IsEditable()); o1s1c1Row.Switch = ParameterSwitchKind.REFERENCE; o1s1c2Row.Switch = ParameterSwitchKind.REFERENCE; o1s2c1Row.Switch = ParameterSwitchKind.REFERENCE; o1s2c2Row.Switch = ParameterSwitchKind.REFERENCE; o2s1c1Row.Switch = ParameterSwitchKind.REFERENCE; o2s1c2Row.Switch = ParameterSwitchKind.REFERENCE; o2s2c1Row.Switch = ParameterSwitchKind.REFERENCE; o2s2c2Row.Switch = ParameterSwitchKind.REFERENCE; o1s1c2Row.Reference = new ReactiveList <EnumerationValueDefinition> { this.enum1 }; o1s2c2Row.Reference = new ReactiveList <EnumerationValueDefinition> { this.enum1 }; o2s1c2Row.Reference = new ReactiveList <EnumerationValueDefinition> { this.enum2 }; o2s2c2Row.Reference = new ReactiveList <EnumerationValueDefinition> { this.enum2 }; var o1s1Set = this.cptParameter.ValueSet.Single(x => x.ActualOption == this.option1 && x.ActualState == this.actualState1); var o1s2Set = this.cptParameter.ValueSet.Single(x => x.ActualOption == this.option1 && x.ActualState == this.actualState2); var o2s1Set = this.cptParameter.ValueSet.Single(x => x.ActualOption == this.option2 && x.ActualState == this.actualState1); var o2s2Set = this.cptParameter.ValueSet.Single(x => x.ActualOption == this.option2 && x.ActualState == this.actualState2); row.UpdateValueSets(o1s1Set); row.UpdateValueSets(o1s2Set); row.UpdateValueSets(o2s1Set); row.UpdateValueSets(o2s2Set); Assert.AreEqual(o1s1Set.ValueSwitch, o1s1c1Row.Switch); Assert.AreEqual(o1s2Set.ValueSwitch, o1s2c1Row.Switch); Assert.AreEqual(o2s1Set.ValueSwitch, o2s1c1Row.Switch); Assert.AreEqual(o2s2Set.ValueSwitch, o2s2c1Row.Switch); Assert.AreEqual(o1s1Set.Reference[0], o1s1c1Row.Reference); Assert.AreEqual(o1s2Set.Reference[0], o1s2c1Row.Reference); Assert.AreEqual(o2s1Set.Reference[0], o2s1c1Row.Reference); Assert.AreEqual(o2s2Set.Reference[0], o2s2c1Row.Reference); Assert.AreEqual(o1s1Set.Reference[1], ValueSetConverter.ToValueSetString(o1s1c2Row.Reference, o1s1c2Row.ParameterType)); Assert.AreEqual(o1s2Set.Reference[1], ValueSetConverter.ToValueSetString(o1s2c2Row.Reference, o1s2c2Row.ParameterType)); Assert.AreEqual(o2s1Set.Reference[1], ValueSetConverter.ToValueSetString(o2s1c2Row.Reference, o2s1c2Row.ParameterType)); Assert.AreEqual(o2s2Set.Reference[1], ValueSetConverter.ToValueSetString(o2s2c2Row.Reference, o2s2c2Row.ParameterType)); }
/// <summary> /// Sets the values of this row in case where the <see cref="ParameterSubscription"/> is neither option-dependent nor state-dependent and is a <see cref="ScalarParameterType"/> /// </summary> public override void SetProperties() { var valueset = this.Thing.ValueSet.FirstOrDefault(); if (valueset == null) { logger.Error("No value set was found for parameter subscription {0}", this.Thing.Iid); return; } if (this.ContainedRows.Count == 0) { this.ScaleShortName = this.Thing.Scale == null ? "-" : this.Thing.Scale.ShortName; } if (this.Thing.ParameterType is SampledFunctionParameterType samplesFunctionParameterType) { var cols = samplesFunctionParameterType.NumberOfValues; this.Computed = $"[{valueset.Computed.Count / cols}x{cols}]"; this.Manual = $"[{valueset.Manual.Count / cols}x{cols}]"; this.Reference = $"[{valueset.Reference.Count / cols}x{cols}]"; this.Value = $"[{valueset.ActualValue.Count / cols}x{cols}]"; this.Formula = $"[{valueset.Formula.Count / cols}x{cols}]"; this.Published = $"[{valueset.Computed.Count / cols}x{cols}]"; } else { this.Computed = valueset.Computed.Any() ? valueset.Computed.First() : "-"; this.Value = valueset.ActualValue.Any() ? valueset.ActualValue.First() : "-"; this.Published = this.Computed; this.Manual = valueset.Manual.Any() ? valueset.Manual.First().ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Reference = valueset.Reference.Any() ? valueset.Reference.First().ToValueSetObject(this.ParameterType) : ValueSetConverter.DefaultObject(this.ParameterType); this.Formula = valueset.SubscribedValueSet.Formula.Any() ? valueset.SubscribedValueSet.Formula.First() : "-"; } this.Switch = valueset.ValueSwitch; if (this.valueSetListener.Any()) { return; } Func <ObjectChangedEvent, bool> discriminator = objectChange => objectChange.EventKind == EventKind.Updated && objectChange.ChangedThing.RevisionNumber > this.RevisionNumber; Action <ObjectChangedEvent> action = x => this.SetProperties(); if (this.AllowMessageBusSubscriptions) { var listener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(valueset) .Where(discriminator) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(action); this.valueSetListener.Add(listener); var subscribedListener = CDPMessageBus.Current.Listen <ObjectChangedEvent>(valueset.SubscribedValueSet) .Where(discriminator) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(action); this.valueSetListener.Add(subscribedListener); } else { var parameterSubscriptionValueSetObserver = CDPMessageBus.Current.Listen <ObjectChangedEvent>(typeof(ParameterSubscriptionValueSet)); this.valueSetListener.Add( this.MessageBusHandler.GetHandler <ObjectChangedEvent>().RegisterEventHandler(parameterSubscriptionValueSetObserver, new ObjectChangedMessageBusEventHandlerSubscription(valueset, discriminator, action))); var parameterValueSetObserver = CDPMessageBus.Current.Listen <ObjectChangedEvent>(typeof(ParameterValueSetBase)); this.valueSetListener.Add( this.MessageBusHandler.GetHandler <ObjectChangedEvent>().RegisterEventHandler(parameterValueSetObserver, new ObjectChangedMessageBusEventHandlerSubscription(valueset.SubscribedValueSet, discriminator, action))); } }