Exemplo n.º 1
0
        /// <summary>
        /// Process the <see cref="ParameterValueSet"/> .
        /// </summary>
        /// <param name="parameterValueSet">
        /// The <see cref="ParameterValueSet"/> to be processed.
        /// </param>
        /// <param name="componentIndex">
        /// The index of the <see cref="ParameterTypeComponent"/>.
        /// </param>
        /// <param name="currentRow">
        /// The row in the Parameter sheet that contains the <see cref="ParameterValueSet"/>.
        /// </param>
        /// <param name="manualValue">
        /// The manual value of the <see cref="ParameterValueSet"/>.
        /// </param>
        /// <param name="computedValue">
        /// The result of the computed value of the <see cref="ParameterValueSet"/>.
        /// </param>
        /// <param name="referenceValue">
        /// The reference value of the <see cref="ParameterValueSet"/>.
        /// </param>
        /// <param name="actualValue">
        /// The actual value of the <see cref="ParameterValueSet"/>.
        /// </param>
        /// <param name="switchValue">
        /// The string value of the <see cref="ParameterSwitchKind"/> of the <see cref="ParameterValueSet"/>
        /// </param>
        /// <param name="formulaValue">
        /// The formula that is used to set the computed property 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>
        private void ProcessValueSet(ParameterValueSet parameterValueSet, int componentIndex, int currentRow, object manualValue, object computedValue, object referenceValue, object actualValue, string switchValue, string formulaValue, ref Dictionary <Guid, ProcessedValueSet> processedValueSets, IFormatProvider provider)
        {
            var validationResult = ValidationResultKind.InConclusive;

            ParameterSwitchKind switchKind;
            ParameterType       parameterType    = null;
            MeasurementScale    measurementScale = null;

            ParameterSheetUtilities.QueryParameterTypeAndScale(parameterValueSet, componentIndex, out parameterType, out measurementScale);

            ValidationResult validSwitch;
            var isValidSwitchKind = Enum.IsDefined(typeof(ParameterSwitchKind), switchValue);

            if (isValidSwitchKind)
            {
                switchKind  = (ParameterSwitchKind)Enum.Parse(typeof(ParameterSwitchKind), switchValue);
                validSwitch = new ValidationResult {
                    ResultKind = ValidationResultKind.Valid, Message = string.Empty
                };
            }
            else
            {
                switchKind  = ParameterSwitchKind.MANUAL;
                validSwitch = new ValidationResult {
                    ResultKind = ValidationResultKind.Invalid, Message = string.Format("{0} is not a valid Parameter Switch Kind", switchValue)
                };
            }

            if (validSwitch.ResultKind > validationResult)
            {
                validationResult = validSwitch.ResultKind;
            }

            var validManualValue = new ValidationResult
            {
                ResultKind = ValidationResultKind.InConclusive,
                Message    = string.Empty
            };

            var validComputedValue = new ValidationResult
            {
                ResultKind = ValidationResultKind.InConclusive,
                Message    = string.Empty
            };

            var validReferenceValue = new ValidationResult
            {
                ResultKind = ValidationResultKind.InConclusive,
                Message    = string.Empty
            };

            var validActualValue = new ValidationResult
            {
                ResultKind = ValidationResultKind.InConclusive,
                Message    = string.Empty
            };

            if (parameterType != null)
            {
                if (parameterType is TimeOfDayParameterType)
                {
                    ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref manualValue, parameterType);
                    ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref computedValue, parameterType);
                    ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref referenceValue, parameterType);
                    ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref actualValue, parameterType);
                }

                if (parameterType is EnumerationParameterType)
                {
                    ParameterSheetUtilities.ConvertObjectToString(ref manualValue);
                    ParameterSheetUtilities.ConvertObjectToString(ref computedValue);
                    ParameterSheetUtilities.ConvertObjectToString(ref referenceValue);
                    ParameterSheetUtilities.ConvertObjectToString(ref actualValue);
                }

                validManualValue = parameterType.Validate(manualValue, measurementScale, provider);
                if (validManualValue.ResultKind > validationResult)
                {
                    validationResult = validManualValue.ResultKind;
                }

                validComputedValue = parameterType.Validate(computedValue, measurementScale, provider);
                if (validComputedValue.ResultKind > validationResult)
                {
                    validationResult = validComputedValue.ResultKind;
                }

                validReferenceValue = parameterType.Validate(referenceValue, measurementScale, provider);
                if (validReferenceValue.ResultKind > validationResult)
                {
                    validationResult = validReferenceValue.ResultKind;
                }

                validActualValue = parameterType.Validate(actualValue, measurementScale, provider);
                if (validActualValue.ResultKind > validationResult)
                {
                    validationResult = validActualValue.ResultKind;
                }
            }

            ParameterSheetUtilities.Decorate(validSwitch, this.parameterSheet, currentRow, ParameterSheetConstants.SwitchColumn);
            ParameterSheetUtilities.Decorate(validManualValue, this.parameterSheet, currentRow, ParameterSheetConstants.ManualColumn);
            ParameterSheetUtilities.Decorate(validComputedValue, this.parameterSheet, currentRow, ParameterSheetConstants.ComputedColumn);
            ParameterSheetUtilities.Decorate(validReferenceValue, this.parameterSheet, currentRow, ParameterSheetConstants.ReferenceColumn);
            ParameterSheetUtilities.Decorate(validActualValue, this.parameterSheet, currentRow, ParameterSheetConstants.ActualValueColumn);

            ProcessedValueSet processedValueSet;
            var valueSetExists = processedValueSets.TryGetValue(parameterValueSet.Iid, out processedValueSet);

            if (!valueSetExists)
            {
                processedValueSet = new ProcessedValueSet(parameterValueSet, validationResult);
            }

            ValueSetValues valueSetValues;

            if (processedValueSet.IsDirty(componentIndex, parameterType, switchKind, manualValue, computedValue, referenceValue, formulaValue, out valueSetValues))
            {
                processedValueSet.UpdateClone(valueSetValues);
                if (!valueSetExists)
                {
                    processedValueSets.Add(parameterValueSet.Iid, processedValueSet);
                }
            }
        }