/// <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
                       ));
        }
        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);
        }
Ejemplo n.º 3
0
 /// <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() : "-";
 }
Ejemplo n.º 4
0
        /// <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";
            }
        }
Ejemplo n.º 5
0
        /// <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] : "-";
        }
Ejemplo n.º 6
0
        /// <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)));
            }
        }
Ejemplo n.º 7
0
        /// <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() : "-";
        }
Ejemplo n.º 9
0
        /// <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);
        }