/// <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); } ////} }
private static bool PutCalculationRowObjectToSimioValues(IStepExecutionContext context, IPropertyReaders rowReader, CalculationRow calcRow) { try { IStateProperty stateReader = (IStateProperty)rowReader.GetProperty("StateField1"); IState state = stateReader.GetState(context); state.StateValue = calcRow.MyReal1; stateReader = (IStateProperty)rowReader.GetProperty("StateField2"); state = stateReader.GetState(context); state.StateValue = calcRow.MyReal2; stateReader = (IStateProperty)rowReader.GetProperty("StateField3"); state = stateReader.GetState(context); state.StateValue = calcRow.MyReal3; stateReader = (IStateProperty)rowReader.GetProperty("StateField4"); state = stateReader.GetState(context); state.StateValue = calcRow.MyReal4; return(true); } catch (Exception ex) { Logit(context, $"Err={ex.Message}"); return(false); } }
private static bool PutSimioValuesToCalculationRowObject(IStepExecutionContext context, Random rand, IPropertyReaders rowReader, CalculationRow calcRow) { try { // Use the row reader to get a state reader IStateProperty stateReader = (IStateProperty)rowReader.GetProperty("StateField1"); IState state = stateReader.GetState(context); state.StateValue = (10 * calcRow.MyKey) + 1; // Mock to create a value for the state calcRow.MyReal1 = state.StateValue; stateReader = (IStateProperty)rowReader.GetProperty("StateField2"); state = stateReader.GetState(context); state.StateValue = (10 * calcRow.MyKey) + 2; // Mock to create a value for the State calcRow.MyReal2 = state.StateValue; stateReader = (IStateProperty)rowReader.GetProperty("StateField3"); state = stateReader.GetState(context); state.StateValue = (10 * calcRow.MyKey) + 3; // Mock to create a value for the State calcRow.MyReal3 = state.StateValue; stateReader = (IStateProperty)rowReader.GetProperty("StateField4"); state = stateReader.GetState(context); state.StateValue = (10 * calcRow.MyKey) + 4; // Mock to create a value for the State calcRow.MyReal4 = state.StateValue; return(true); } catch (Exception ex) { Logit(context, $"Err={ex.Message}"); return(false); } }