/// <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}"); } }
/// <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> /// Constructor called as the run begins. /// </summary> /// <param name="data"></param> public SimioTableElement(IElementData data) { _Data = data; _Props = _Data.Properties; // Property readers _Context = _Data.ExecutionContext; // run-time execution context rprTableFields = (IRepeatingPropertyReader)_Props.GetProperty(MyStrings.TableColumnMappingsName); prTableRowIndex = (IStateProperty)_Props.GetProperty(MyStrings.TableIndexName); IExpressionPropertyReader prExpression = (IExpressionPropertyReader)_Props.GetProperty(MyStrings.TableRowCountName); double tableRowCount = (double)prExpression.GetExpressionValue(data.ExecutionContext); // Build a structure to hold data?? ////CalcDataList = new List<CalculationRow>(); ////for (int tr = 1; tr <= NbrTableRows; tr++) ////{ //// CalculationRow cr = new CalculationRow(); //// cr.MyKey = tr; //// CalcDataList.Add(cr); ////} }