/// <summary>
        /// Method called when a process token executes the step.
        /// </summary>
        public ExitType Execute(IStepExecutionContext context)
        {
            // Get an array of double values from the repeat group's list of expressions
            object[] paramsArray = new object[_items.GetCount(context)];
            for (int i = 0; i < _items.GetCount(context); i++)
            {
                // The thing returned from GetRow is IDisposable, so we use the using() pattern here
                using (IPropertyReaders row = _items.GetRow(i, context))
                {
                    // Get the expression property
                    IExpressionPropertyReader expressionProp = row.GetProperty("Expression") as IExpressionPropertyReader;
                    // Resolve the expression to get the value
                    paramsArray[i] = expressionProp.GetExpressionValue(context);
                }
            }

            // set Excel data
            ExcelConnectElementEPPlus Excelconnect = (ExcelConnectElementEPPlus)_ExcelconnectElementProp.GetElement(context);

            if (Excelconnect == null)
            {
                context.ExecutionInformation.ReportError("ExcelConnectEPPlus element is null.  Makes sure ExcelWorkbook is defined correctly.");
            }
            String worksheetString   = _worksheetProp.GetStringValue(context);
            Int32  rowInt            = (Int32)_rowProp.GetDoubleValue(context);
            Int32  startingColumnInt = Convert.ToInt32(_startingColumnProp.GetDoubleValue(context));

            try
            {
                // for each parameter
                for (int ii = 0; ii < paramsArray.Length; ii++)
                {
                    double doubleValue = TryAsDouble((Convert.ToString(paramsArray[ii], CultureInfo.InvariantCulture)));
                    if (!System.Double.IsNaN(doubleValue))
                    {
                        Excelconnect.WriteResults(worksheetString, rowInt, startingColumnInt + ii, doubleValue, DateTime.MinValue, String.Empty, context);
                    }
                    else
                    {
                        DateTime datetimeValue = TryAsDateTime((Convert.ToString(paramsArray[ii], CultureInfo.InvariantCulture)));
                        if (datetimeValue > System.DateTime.MinValue)
                        {
                            Excelconnect.WriteResults(worksheetString, rowInt, startingColumnInt + ii, System.Double.MinValue, datetimeValue, String.Empty, context);
                        }
                        else
                        {
                            Excelconnect.WriteResults(worksheetString, rowInt, startingColumnInt + ii, System.Double.MinValue, System.DateTime.MinValue, (Convert.ToString(paramsArray[ii], CultureInfo.InvariantCulture)), context);
                        }
                    }
                }
            }
            catch (FormatException)
            {
                context.ExecutionInformation.ReportError("Bad format provided in Excel Write step.");
            }

            // We are done writing, have the token proceed out of the primary exit
            return(ExitType.FirstExit);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Method called when a process token executes the step.
        /// </summary>
        public ExitType Execute(IStepExecutionContext context)
        {
            // Get Excel data
            ExcelConnectElementEPPlus Excelconnect = (ExcelConnectElementEPPlus)prExcelconnectElement.GetElement(context);

            if (Excelconnect == null)
            {
                context.ExecutionInformation.ReportError("ExcelConnectEPPlus element is null.  Makes sure ExcelWorkbook is defined correctly.");
            }
            String worksheetString   = prWorksheet.GetStringValue(context);
            Int32  rowInt            = (Int32)prRow.GetDoubleValue(context);
            Int32  startingColumnInt = Convert.ToInt32(prStartingColumn.GetDoubleValue(context));

            int numReadIn       = 0;
            int numReadFailures = 0;

            for (int ii = 0; ii < rprStates.GetCount(context); ii++)
            {
                // Tokenize the input
                string resultsString = Excelconnect.ReadResults(worksheetString, rowInt, startingColumnInt + ii, context);

                // The thing returned from GetRow is IDisposable, so we use the using() pattern here
                using (IPropertyReaders row = rprStates.GetRow(ii, context))
                {
                    // Get the state property out of the i-th tuple of the repeat group
                    IStateProperty stateprop = (IStateProperty)row.GetProperty("State");
                    // Resolve the property value to get the runtime state
                    IState state = stateprop.GetState(context);

                    if (TryAsNumericState(state, resultsString) ||
                        TryAsDateTimeState(state, resultsString) ||
                        TryAsStringState(state, resultsString))
                    {
                        numReadIn++;
                    }
                    else
                    {
                        numReadFailures++;
                    }
                }
            }

            string worksheetName = prWorksheet.GetStringValue(context);

            context.ExecutionInformation.TraceInformation($"Read from row={rowInt} worksheet={worksheetName} into {numReadIn} state columns. {numReadFailures} read failures");

            // We are done reading, have the token proceed out of the primary exit
            return(ExitType.FirstExit);
        }