public void VerifyThatConvertNumericValueToStringReturnsExpectedResult()
        {
            object number = 1;

            ParameterSheetUtilities.ConvertObjectToString(ref number);
            Assert.AreEqual("1", number);
        }
        public void VerifThatConvertDoubleToDateTimeObjectConvertsAsExpected()
        {
            var      timeOfDayParameterType = new TimeOfDayParameterType(Guid.NewGuid(), null, null);
            DateTime expectedDate;

            var stringValue         = "-";
            var stringValueAsObject = (object)stringValue;

            ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref stringValueAsObject, timeOfDayParameterType);
            Assert.AreEqual("-", stringValueAsObject);

            var timeDoubleValue         = 0.11111111111111111111111111111d;
            var timeDoubleValueAsObject = (object)timeDoubleValue;

            ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref timeDoubleValueAsObject, timeOfDayParameterType);
            expectedDate = new DateTime(1, 1, 1, 2, 40, 0);
            Assert.AreEqual(expectedDate, timeDoubleValueAsObject);

            var dateParameterType       = new DateParameterType(Guid.NewGuid(), null, null);
            var dateDoubleValue         = 0.11111111111111111111111111111d;
            var dateDoubleValueAsObject = (object)dateDoubleValue;

            ParameterSheetUtilities.ConvertDoubleToDateTimeObject(ref dateDoubleValueAsObject, dateParameterType);
            expectedDate = new DateTime(1899, 12, 30, 2, 40, 0);
            Assert.AreEqual(expectedDate, dateDoubleValueAsObject);
        }
Exemple #3
0
        /// <summary>
        /// rebuild the parameter sheet, replace it if it already exists.
        /// </summary>
        /// <param name="application">
        /// The excel application object that contains the <see cref="Workbook"/> in which the parameter sheet is to be rebuilt.
        /// </param>
        /// <param name="workbook">
        /// The <see cref="Workbook"/> in which the parameter sheet is to be rebuilt.
        /// </param>
        /// <param name="clones">
        /// The <see cref="Thing"/>s that have been changed on the Parameter sheet that need to be kept
        /// </param>
        public void Rebuild(Application application, Workbook workbook, IReadOnlyDictionary <Guid, ProcessedValueSet> processedValueSets)
        {
            var sw = new Stopwatch();

            sw.Start();

            this.excelApplication = application;

            this.excelApplication.StatusBar = "Rebuilding Parameter Sheet";

            this.listSeparator = (string)application.International(XlApplicationInternational.xlListSeparator);
            this.xlCountryCode = Convert.ToInt32(application.International(XlApplicationInternational.xlCountryCode));
            this.SetLanguageSpecificVariables();
            this.SetSwitchString();

            var enabledEvents  = application.EnableEvents;
            var displayAlerts  = application.DisplayAlerts;
            var screenupdating = application.ScreenUpdating;
            var calculation    = application.Calculation;

            application.EnableEvents   = false;
            application.DisplayAlerts  = false;
            application.Calculation    = XlCalculation.xlCalculationManual;
            application.ScreenUpdating = false;

            try
            {
                application.Cursor = XlMousePointer.xlWait;

                this.parameterSheet = ParameterSheetUtilities.RetrieveParameterSheet(workbook, true);

                ParameterSheetUtilities.ApplyLocking(this.parameterSheet, false);

                this.PopulateSheetArrays(processedValueSets);
                this.WriteParameterSheet();
                this.ApplySheetSettings();

                ParameterSheetUtilities.ApplyLocking(this.parameterSheet, true);

                this.excelApplication.StatusBar = $"CDP4: Parameter Sheet rebuilt in {sw.ElapsedMilliseconds} [ms]";
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                this.excelApplication.StatusBar = $"CDP4: The following error occured while rebuilding the sheet: {ex.Message}";
            }
            finally
            {
                application.EnableEvents   = enabledEvents;
                application.DisplayAlerts  = displayAlerts;
                application.Calculation    = calculation;
                application.ScreenUpdating = screenupdating;

                application.Cursor = XlMousePointer.xlDefault;
            }
        }
        public void VerifyThatReformatTimeOfDayReturnsExpectedResult()
        {
            var value = "-";

            Assert.AreEqual(value, ParameterSheetUtilities.ReformatTimeOfDay(value));

            value = string.Empty;
            Assert.AreEqual(value, ParameterSheetUtilities.ReformatTimeOfDay(value));

            value = "24:01:59";
            Assert.AreEqual(value, ParameterSheetUtilities.ReformatTimeOfDay(value));

            var doubleValue = "0.11111111111111111111111111111";

            Assert.AreEqual("02:40:00", ParameterSheetUtilities.ReformatTimeOfDay(doubleValue));
        }
        public void VerifyThatParameterOverrideValueSetQueryParameterTypeAndScaleReturnsExpectedResult()
        {
            var simpleQuantityKind = new SimpleQuantityKind(Guid.NewGuid(), null, null);
            var ratioScale         = new RatioScale(Guid.NewGuid(), null, null);

            var parameter = new Parameter(Guid.NewGuid(), null, null)
            {
                ParameterType = simpleQuantityKind,
                Scale         = ratioScale
            };
            var paramterValueSet = new ParameterValueSet(Guid.NewGuid(), null, null);

            parameter.ValueSet.Add(paramterValueSet);

            var parameterOverride = new ParameterOverride(Guid.NewGuid(), null, null);

            parameterOverride.Parameter = parameter;
            var parameterOverrideValueSet = new ParameterOverrideValueSet(Guid.NewGuid(), null, null);

            parameterOverride.ValueSet.Add(parameterOverrideValueSet);

            ParameterType    parameterType;
            MeasurementScale measurementScale;

            ParameterSheetUtilities.QueryParameterTypeAndScale(parameterOverrideValueSet, 0, out parameterType, out measurementScale);

            Assert.AreEqual(simpleQuantityKind, parameterType);
            Assert.AreEqual(ratioScale, measurementScale);

            var compoundParameterType = new CompoundParameterType(Guid.NewGuid(), null, null);
            var component             = new ParameterTypeComponent(Guid.NewGuid(), null, null);

            compoundParameterType.Component.Add(component);
            component.ParameterType = simpleQuantityKind;
            component.Scale         = ratioScale;

            parameter.ParameterType = compoundParameterType;
            parameter.Scale         = null;

            ParameterSheetUtilities.QueryParameterTypeAndScale(parameterOverrideValueSet, 0, out parameterType, out measurementScale);

            Assert.AreEqual(simpleQuantityKind, parameterType);
            Assert.AreEqual(ratioScale, measurementScale);
        }
        public void VerifyThatReformatDateReturnsExpectedResult()
        {
            var value = "-";

            Assert.AreEqual(value, ParameterSheetUtilities.ReformatDate(value));

            value = string.Empty;
            Assert.AreEqual(value, ParameterSheetUtilities.ReformatDate(value));

            value = "2012-12-01";
            Assert.AreEqual(value, ParameterSheetUtilities.ReformatDate(value));

            value = "2012 february 1";
            Assert.AreEqual("2012-02-01", ParameterSheetUtilities.ReformatDate(value));

            var doubleValue = "0.11111111111111111111111111111";

            Assert.AreEqual("1899-12-30", ParameterSheetUtilities.ReformatDate(doubleValue));
        }
        /// <summary>
        /// Write the <see cref="Option"/> sheets to the <see cref="Workbook"/>
        /// </summary>
        /// <param name="workbook">
        /// The <see cref="Workbook"/> in which the <see cref="Option"/> sheets are to be rebuilt.
        /// </param>
        protected override void Write(Workbook workbook)
        {
            foreach (var item in this.iteration.Option)
            {
                var option = (Option)item;
                Logger.Info("Writing Option sheet {0} to the workbook", option.ShortName);

                var optionSheet = ParameterSheetUtilities.RetrieveOptionSheet(workbook, option);
                ParameterSheetUtilities.ApplyLocking(optionSheet, false);

                var headerEndRow = this.PopulateAndWriteHeaderArray(optionSheet, option);
                var startrow     = headerEndRow + 2;
                this.PopulateAndWriteParameterArray(optionSheet, option, startrow);

                this.ApplySheetSettings(optionSheet);

                ParameterSheetUtilities.ApplyLocking(optionSheet, true);
            }
        }