/// <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);
        }
        /// <summary>
        /// Get the arguments from the Repeating Group
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public List <Tuple <string, string> > GetArgumentsFromSimio(IStepExecutionContext context)
        {
            List <Tuple <string, string> > argList = new List <Tuple <string, string> >();
            string marker = "";

            int numArguments = _prArguments.GetCount(context);
            int ii           = -1;

            try
            {
                // Get the values of all the arguments (repeating group)
                for (ii = 0; ii < numArguments; ii++)
                {
                    marker = $"Argument #{ii}";
                    using (IPropertyReaders argsRow = _prArguments.GetRow(ii, context))
                    {
                        IExpressionPropertyReader prExpression = argsRow.GetProperty("ArgumentName") as IExpressionPropertyReader;
                        string argName = prExpression.GetExpressionValue(context).ToString();

                        prExpression = argsRow.GetProperty("Expression") as IExpressionPropertyReader;

                        string exprVal = prExpression.GetExpressionValue(context).ToString();

                        marker = $"{marker}: Name={argName} Value={exprVal}";
                        argList.Add(new Tuple <string, string>(argName, exprVal));
                    }
                } // for

                return(argList);
            }
            catch (Exception ex)
            {
                throw new ApplicationException($"Marker={marker}. Processing argument {ii} of {numArguments}. Err={ex.Message}");
            }
        }
Example #3
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);
        }
        /// <summary>
        /// Method called when a process token executes the step.
        /// </summary>
        public ExitType Execute(IStepExecutionContext context)
        {
            rgReader = (IRepeatingPropertyReader)_props.GetProperty("MyMappedFields");

            // If not set up (e.g. this is the first time), create the CalcDataList
            // Since the RG references the table the count is the number of rows.
            if (CalcDataList == null)
            {
                CalcDataList = new List <CalculationRow>();

                int tableRowCount = rgReader.GetCount(context);
                for (int ri = 0; ri < tableRowCount; ri++)
                {
                    CalculationRow cr = new CalculationRow();
                    cr.MyKey = ri;
                    CalcDataList.Add(cr);
                }
            }

            //// Create values and put them in the CalculationRow objects
            foreach (CalculationRow cr in CalcDataList)
            {
                using (IPropertyReaders rowReader2 = rgReader.GetRow(cr.MyKey, context))
                {
                    PutSimioValuesToCalculationRowObject(context, RandomGenerator, rowReader2, cr);
                }
            } // next table row

            //======= Run a mock calculator/optimizer/whatever ==============
            if (RunMockCalculator(CalcDataList, out string explanation))
            {
                // Put the data back into Simio
                foreach (CalculationRow cr in CalcDataList)
                {
                    using (IPropertyReaders rowReader2 = rgReader.GetRow(cr.MyKey, context))
                    {
                        PutCalculationRowObjectToSimioValues(context, rowReader2, cr);
                    }
                }
                return(ExitType.FirstExit);
            }
            else
            {
                Logit(context, $"Calculation Err={explanation}");
                return(ExitType.AlternateExit);
            }

            ////}
        }
Example #5
0
        private List <double> ReadRepeatingProperty(IStepExecutionContext context, IRepeatingPropertyReader rp, string propertyname)
        {
            var result = new List <double>();

            for (int i = 0; i < rp.GetCount(context); i++)
            {
                using (IPropertyReaders row = rp.GetRow(i, context))
                {
                    IStateProperty stateprop = (IStateProperty)row.GetProperty(propertyname);
                    IState         state     = stateprop.GetState(context);
                    result.Add(state.StateValue);
                }
            }
            return(result);
        }