Ejemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ComponentExcelRow"/> class.
        /// </summary>
        /// <param name="parameterTypeComponent">
        /// The <see cref="ParameterTypeComponent"/> that represents the current row
        /// </param>
        /// <param name="parameterValueSet">
        /// The <see cref="ParameterValueSet"/> from which the value is to be represented
        /// </param>
        /// <param name="level">
        /// the grouping level of the current row.
        /// </param>
        public ComponentExcelRow(ParameterTypeComponent parameterTypeComponent, ParameterValueSet parameterValueSet, int level)
            : base(parameterTypeComponent)
        {
            this.Level         = level;
            this.Name          = string.Format("{0}{1}", new string(' ', 3 * level), parameterTypeComponent.ShortName);
            this.ShortName     = parameterTypeComponent.ShortName;
            this.Type          = ParameterSheetConstants.PVSCT;
            this.Switch        = parameterValueSet.ValueSwitch.ToString();
            this.Id            = string.Format("{0}:{1}", parameterValueSet.Iid, parameterTypeComponent.Index);
            this.Owner         = parameterValueSet.Owner.ShortName;
            this.ParameterType = parameterTypeComponent.ParameterType;

            this.Format = NumberFormat.Format(parameterTypeComponent.ParameterType, parameterTypeComponent.Scale);

            this.ModelCode = parameterValueSet.ModelCode(parameterTypeComponent.Index);

            if (parameterTypeComponent.Scale == null)
            {
                this.ParameterTypeShortName = parameterTypeComponent.ParameterType.ShortName;
            }
            else
            {
                this.ParameterTypeShortName = string.Format("{0} [{1}]", parameterTypeComponent.ParameterType.ShortName, parameterTypeComponent.Scale.ShortName);
            }

            try
            {
                this.ActualValue    = ParameterValueConverter.ConvertToObject(this.Thing.ParameterType, parameterValueSet.ActualValue[parameterTypeComponent.Index]);
                this.ComputedValue  = ParameterValueConverter.ConvertToObject(this.Thing.ParameterType, parameterValueSet.Computed[parameterTypeComponent.Index]);
                this.ManualValue    = ParameterValueConverter.ConvertToObject(this.Thing.ParameterType, parameterValueSet.Manual[parameterTypeComponent.Index]);
                this.ReferenceValue = ParameterValueConverter.ConvertToObject(this.Thing.ParameterType, parameterValueSet.Reference[parameterTypeComponent.Index]);
                this.Formula        = parameterValueSet.Formula[parameterTypeComponent.Index];
            }
            catch (Exception ex)
            {
                this.SetDefaultValues();
                Logger.Debug(ex);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterOverrideValueSetExcelRow"/> class.
        /// </summary>
        /// <param name="parameterOverrideValueSet">
        /// The <see cref="ParameterOverrideValueSet"/> that is represented by the current row.
        /// </param>
        /// <param name="level">
        /// the grouping level of the current row.
        /// </param>
        /// <param name="clones">
        /// The <see cref="Thing"/>s for which the values need to be restored to what the user provided.
        /// </param>
        public ParameterOverrideValueSetExcelRow(ParameterOverrideValueSet parameterOverrideValueSet, int level, IReadOnlyDictionary <Guid, ProcessedValueSet> processedValueSets)
            : base(parameterOverrideValueSet)
        {
            this.Level = level;
            this.Id    = this.Thing.Iid.ToString();

            ProcessedValueSet processedValueSet;

            if (processedValueSets.TryGetValue(parameterOverrideValueSet.Iid, out processedValueSet))
            {
                parameterOverrideValueSet = (ParameterOverrideValueSet)processedValueSet.ClonedThing;
            }

            var parameterOverride = parameterOverrideValueSet.Container as ParameterOverride;

            if (parameterOverride != null)
            {
                this.ParameterType = parameterOverride.ParameterType;

                if (this.ParameterType is CompoundParameterType)
                {
                    this.Type = ParameterSheetConstants.POVSCD;
                }
                else if (this.ParameterType is SampledFunctionParameterType)
                {
                    this.Type = ParameterSheetConstants.SFPOVS;
                }
                else
                {
                    this.Type = ParameterSheetConstants.POVS;
                }

                var spaces = new string(' ', 3 * Math.Abs(level - 1));
                this.ParameterTypeShortName = parameterOverride.Scale == null ? parameterOverride.ParameterType.ShortName : string.Format("{0} [{1}]", parameterOverride.ParameterType.ShortName, parameterOverride.Scale.ShortName);
                var optionPart = parameterOverrideValueSet.ActualOption != null ? parameterOverrideValueSet.ActualOption.ShortName : string.Empty;
                var statePart  = parameterOverrideValueSet.ActualState != null ? parameterOverrideValueSet.ActualState.ShortName : string.Empty;

                this.Name      = string.Format("{0}{1}\\{2}\\{3}", spaces, parameterOverride.ParameterType.Name, optionPart, statePart);
                this.ShortName = string.Format("{0}\\{1}\\{2}", parameterOverride.ParameterType.ShortName, optionPart, statePart);
                this.Format    = NumberFormat.Format(parameterOverride.ParameterType, parameterOverride.Scale);
                this.Switch    = parameterOverrideValueSet.ValueSwitch.ToString();

                this.ModelCode = parameterOverrideValueSet.ModelCode();

                var sampledFunctionParameterType = this.ParameterType as SampledFunctionParameterType;
                if (sampledFunctionParameterType != null)
                {
                    this.Id             = parameterOverrideValueSet.Iid.ToString();
                    this.Switch         = parameterOverrideValueSet.ValueSwitch.ToString();
                    this.ActualValue    = "N/A";
                    this.ComputedValue  = "N/A";
                    this.ManualValue    = "N/A";
                    this.ReferenceValue = "N/A";
                    this.Formula        = string.Empty;

                    this.Format = NumberFormat.Format(this.ParameterType, null);

                    this.ModelCode = parameterOverrideValueSet.ModelCode();

                    // do not create sub rows, the parameter row represents the only valueset that exists
                    return;
                }

                var compoundParameterType = parameterOverride.ParameterType as CompoundParameterType;
                if (compoundParameterType == null)
                {
                    this.ActualValue    = ParameterValueConverter.ConvertToObject(this.ParameterType, parameterOverrideValueSet.ActualValue[0]);
                    this.ComputedValue  = ParameterValueConverter.ConvertToObject(this.ParameterType, parameterOverrideValueSet.Computed[0]);
                    this.ManualValue    = ParameterValueConverter.ConvertToObject(this.ParameterType, parameterOverrideValueSet.Manual[0]);
                    this.ReferenceValue = ParameterValueConverter.ConvertToObject(this.ParameterType, parameterOverrideValueSet.Reference[0]);
                    this.Formula        = parameterOverrideValueSet.Formula[0];
                }
                else
                {
                    // create rows for each component
                    foreach (ParameterTypeComponent component in compoundParameterType.Component)
                    {
                        var componentExcelRow = new ComponentExcelRow(component, parameterOverrideValueSet, this.Level + 1);
                        this.ContainedRows.Add(componentExcelRow);
                        componentExcelRow.Container = this;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Process the current <see cref="ParameterSubscription"/>s to create any ContainedRows for value-sets
        /// </summary>
        /// <param name="processedValueSets">
        /// The <see cref="Thing"/>s for which the values need to be restored to what the user provided.
        /// </param>
        private void ProcessParameter(IReadOnlyDictionary <Guid, ProcessedValueSet> processedValueSets)
        {
            if (!this.Thing.IsOptionDependent && this.Thing.StateDependence == null)
            {
                var scalarParameterType = this.Thing.ParameterType as ScalarParameterType;
                if (scalarParameterType != null)
                {
                    var parameterValueSet = this.Thing.ValueSet.FirstOrDefault();
                    if (parameterValueSet != null)
                    {
                        ProcessedValueSet processedValueSet;
                        if (processedValueSets.TryGetValue(parameterValueSet.Iid, out processedValueSet))
                        {
                            parameterValueSet = (ParameterSubscriptionValueSet)processedValueSet.ClonedThing;
                        }

                        this.Id             = parameterValueSet.Iid.ToString();
                        this.Switch         = parameterValueSet.ValueSwitch.ToString();
                        this.ActualValue    = ParameterValueConverter.ConvertToObject(scalarParameterType, parameterValueSet.ActualValue[0]);
                        this.ComputedValue  = ParameterValueConverter.ConvertToObject(scalarParameterType, parameterValueSet.Computed[0]);
                        this.ManualValue    = ParameterValueConverter.ConvertToObject(scalarParameterType, parameterValueSet.Manual[0]);
                        this.ReferenceValue = ParameterValueConverter.ConvertToObject(scalarParameterType, parameterValueSet.Reference[0]);

                        this.Format = NumberFormat.Format(this.Thing.ParameterType, this.Thing.Scale);

                        this.ModelCode = parameterValueSet.ModelCode();
                    }

                    // do not create sub rows, the parameter row represents the only valueset that exists
                    return;
                }

                var compoundParameterType = this.Thing.ParameterType as CompoundParameterType;
                if (compoundParameterType != null)
                {
                    this.Format    = NumberFormat.Format(this.Thing.ParameterType, this.Thing.Scale);
                    this.ModelCode = this.Thing.ModelCode();

                    var parameterValueSet = this.Thing.ValueSet.FirstOrDefault();
                    if (parameterValueSet != null)
                    {
                        ProcessedValueSet processedValueSet;
                        if (processedValueSets.TryGetValue(parameterValueSet.Iid, out processedValueSet))
                        {
                            parameterValueSet = (ParameterSubscriptionValueSet)processedValueSet.ClonedThing;
                        }

                        this.Id     = parameterValueSet.Iid.ToString();
                        this.Switch = parameterValueSet.ValueSwitch.ToString();
                    }

                    // create rows for each component
                    foreach (ParameterTypeComponent component in compoundParameterType.Component)
                    {
                        var componentExcelRow = new ComponentExcelRow(component, parameterValueSet, this.Level + 1);
                        this.ContainedRows.Add(componentExcelRow);
                        componentExcelRow.Container = this;
                    }
                }

                return;
            }

            var sortedvaluesets = this.Thing.ValueSet.OrderBy(p => p, new ParameterSubscriptionValueSetComparer());

            foreach (var valueset in sortedvaluesets)
            {
                if (valueset.ActualState != null && valueset.ActualState.Kind == ActualFiniteStateKind.FORBIDDEN)
                {
                    continue;
                }

                var valueSetRow = new ParameterSubscriptionValuesetExcelRow(valueset, this.Level + 1, processedValueSets);
                this.ContainedRows.Add(valueSetRow);
                valueSetRow.Container = this;
            }
        }
Ejemplo n.º 4
0
        public void VerifyThatConvertForQuantityKindWorks()
        {
            var test = (double)ParameterValueConverter.ConvertToObject(this.simpleQuantityKind, "1.2e5");

            Assert.AreEqual(1.2e5, test);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ParameterSubscriptionValuesetExcelRow"/> class.
        /// </summary>
        /// <param name="parameterSubscriptionValueSet">
        /// The <see cref="ParameterSubscriptionValueSet"/> that is represented by the row.
        /// </param>
        /// <param name="level">
        /// the grouping level of the current row.
        /// </param>
        /// <param name="processedValueSets">
        /// The <see cref="Thing"/>s for which the values need to be restored to what the user provided.
        /// </param>
        public ParameterSubscriptionValuesetExcelRow(ParameterSubscriptionValueSet parameterSubscriptionValueSet, int level, IReadOnlyDictionary <Guid, ProcessedValueSet> processedValueSets)
            : base(parameterSubscriptionValueSet)
        {
            this.Level = level;
            this.Id    = this.Thing.Iid.ToString();

            ProcessedValueSet processedValueSet;

            if (processedValueSets.TryGetValue(parameterSubscriptionValueSet.Iid, out processedValueSet))
            {
                parameterSubscriptionValueSet = (ParameterSubscriptionValueSet)processedValueSet.ClonedThing;
            }

            var parameterSubscription = parameterSubscriptionValueSet.Container as ParameterSubscription;

            if (parameterSubscription != null)
            {
                this.ParameterType = parameterSubscription.ParameterType;

                if (this.ParameterType is CompoundParameterType)
                {
                    this.Type = ParameterSheetConstants.PSVSCD;
                }
                else
                {
                    this.Type = ParameterSheetConstants.PSVS;
                }

                var spaces = new string(' ', 3 * Math.Abs(level - 1));

                this.ParameterTypeShortName = parameterSubscription.Scale == null ? parameterSubscription.ParameterType.ShortName : string.Format("{0} [{1}]", parameterSubscription.ParameterType.ShortName, parameterSubscription.Scale.ShortName);
                var optionPart = parameterSubscriptionValueSet.ActualOption != null ? parameterSubscriptionValueSet.ActualOption.ShortName : string.Empty;
                var statePart  = parameterSubscriptionValueSet.ActualState != null ? parameterSubscriptionValueSet.ActualState.ShortName : string.Empty;

                this.Name      = string.Format("{0}{1}\\{2}\\{3}", spaces, parameterSubscription.ParameterType.Name, optionPart, statePart);
                this.ShortName = string.Format("{0}\\{1}\\{2}", parameterSubscription.ParameterType.ShortName, optionPart, statePart);
                this.Format    = NumberFormat.Format(parameterSubscription.ParameterType, parameterSubscription.Scale);
                this.Switch    = parameterSubscriptionValueSet.ValueSwitch.ToString();
                this.Owner     = string.Format("--{0}", PropertyHelper.ComputeContainerOwnerShortName(parameterSubscription));

                this.ModelCode = parameterSubscriptionValueSet.ModelCode();

                var compoundParameterType = parameterSubscription.ParameterType as CompoundParameterType;
                if (compoundParameterType == null)
                {
                    this.ActualValue    = ParameterValueConverter.ConvertToObject(this.ParameterType, parameterSubscriptionValueSet.ActualValue[0]);
                    this.ComputedValue  = ParameterValueConverter.ConvertToObject(this.ParameterType, parameterSubscriptionValueSet.Computed[0]);
                    this.ManualValue    = ParameterValueConverter.ConvertToObject(this.ParameterType, parameterSubscriptionValueSet.Manual[0]);
                    this.ReferenceValue = ParameterValueConverter.ConvertToObject(this.ParameterType, parameterSubscriptionValueSet.Reference[0]);
                    this.Formula        = string.Empty;
                }
                else
                {
                    // create rows for each component
                    foreach (ParameterTypeComponent component in compoundParameterType.Component)
                    {
                        var componentExcelRow = new ComponentExcelRow(component, parameterSubscriptionValueSet, this.Level + 1);
                        this.ContainedRows.Add(componentExcelRow);
                        componentExcelRow.Container = this;
                    }
                }
            }
        }
Ejemplo n.º 6
0
        public void VerifyThatConvertForTextPtWorks()
        {
            var test = ParameterValueConverter.ConvertToObject(new TextParameterType(), "date");

            Assert.AreEqual("date", test);
        }
Ejemplo n.º 7
0
        public void VerifyThatfalseReturnFalse()
        {
            var test = ParameterValueConverter.ConvertToObject(new BooleanParameterType(), "false");

            Assert.AreEqual("FALSE", test);
        }
Ejemplo n.º 8
0
        public void VerifyThattrueReturnTRUE()
        {
            var test = ParameterValueConverter.ConvertToObject(new BooleanParameterType(), "true");

            Assert.AreEqual("TRUE", test);
        }
Ejemplo n.º 9
0
        public void VerifyThatDefaultReturnDefault()
        {
            var test = ParameterValueConverter.ConvertToObject(this.simpleQuantityKind, "-");

            Assert.AreEqual("-", test);
        }
Ejemplo n.º 10
0
        public void VerifyThatConvertForQuantityKindWorksOnWrongFormat()
        {
            var test = ParameterValueConverter.ConvertToObject(this.simpleQuantityKind, "yalayala");

            Assert.AreEqual("yalayala", test);
        }