/// <summary> /// Processes all BigMatrix worksheets in a given Workbook /// </summary> /// <param name="activeWorkbook"></param> /// <returns></returns> public static bool ProcessAll(IBIGMatrixStatus bmStatus) { DateTime start = DateTime.Now; HydroSharedAddIn.TransitLoss2 tl2 = new HydroSharedAddIn.TransitLoss2(); tl2.DoLock(true); _inputParameterArrays.Clear(); bmStatus.log(Globals.ThisWorkbook.Name + " begin simulation."); List<string> wrkBookNames = GetWorksheetNames(); // Determine if we will use the new Matrix_Workbook algorithm (new) or the BIG Matrix algorithm (legacy) if (HydroSharedAddIn.Simulation.Matrix_Workbook.ProcessAll(bmStatus)) { return true; } bmStatus.log("found j349 worksheet, using BIG Matrix technique."); foreach (string wrkBookName in wrkBookNames) { string lowername = wrkBookName.ToLower(); if (lowername.IndexOf("big matrix") == 0) { string bigMatrixSuffix = wrkBookName.Replace("BIG Matrix", ""); bigMatrixSuffix = bigMatrixSuffix.Replace("BIG matrix", ""); string j349WBName = "j349" + bigMatrixSuffix; string j349LogWBName = "j349" + bigMatrixSuffix + "_log"; Worksheet bigMatrixWS = GetWorksheet(wrkBookName); Worksheet j349WS = GetWorksheet(j349WBName); Worksheet j349LogWS = GetWorksheet(j349LogWBName); try { if (!ProcessBigMatrix(bigMatrixWS, j349WS, j349LogWS, bmStatus)) { StringCollection sc = bmStatus.getInfo(); foreach (string info in sc) { bmStatus.log(info); } tl2.DoLock(false); return false; } } catch (Exception e) { bmStatus.log("Error: Exception thrown"); bmStatus.log(e.ToString()); StringCollection sc = bmStatus.getInfo(); foreach (string info in sc) { bmStatus.log(info); } tl2.DoLock(false); return false; } } } TimeSpan ts = DateTime.Now - start; bmStatus.log(Globals.ThisWorkbook.Name + " simulations completed in " + ts.Seconds.ToString() + " secs."); bmStatus.setBigMatrixStatus(Globals.ThisWorkbook.Name, "successfully completed all simulations."); ExcelHelper.flush(); tl2.DoLock(false); Globals.ThisWorkbook.Application.CalculateFull(); return true; }
public bool ProcessAll() { DateTime start = DateTime.Now; HydroSharedAddIn.TransitLoss2 tl2 = new HydroSharedAddIn.TransitLoss2(); tl2.DoLock(true); _inputParameterArrays.Clear(); Status.log(Globals.ThisWorkbook.Name + " begin simulation."); List<string> wsNames = hydroLib.ExcelHelper.GetWorksheetNames(); foreach (string wrkSheetName in wsNames) { string lowername = wrkSheetName.ToLower(); if (lowername.IndexOf(" matrix") > 0 || lowername.IndexOf("total flow") == 0 || lowername.IndexOf("native flow") == 0 ) { try { Worksheet excelWS = hydroLib.ExcelHelper.GetWorksheet(wrkSheetName); Matrix_Worksheet matrixWS = new Matrix_Worksheet(this, excelWS); if (!matrixWS.Process()) { StringCollection sc = Status.getInfo(); foreach (string info in sc) { Status.log(info); } tl2.DoLock(false); return false; } } catch (Exception e) { Status.log("Error: Exception thrown"); Status.log(e.ToString()); StringCollection sc = Status.getInfo(); foreach (string info in sc) { Status.log(info); } tl2.DoLock(false); return false; } } } TimeSpan ts = DateTime.Now - start; Status.log(Globals.ThisWorkbook.Name + " simulations completed in " + ts.Seconds.ToString() + " secs."); Status.setBigMatrixStatus(Globals.ThisWorkbook.Name, "successfully completed all simulations."); hydroLib.ExcelHelper.flush(); tl2.DoLock(false); Globals.ThisWorkbook.Application.CalculateFull(); return true; }
//D:\wrk\hydro\trunk\HydroSharedAddIn\Simulation\Matrix_Worksheet.cs //jhb the RoutingSimulation Run() method public void Run() { HydroSharedAddIn.TransitLoss2 tl2 = new HydroSharedAddIn.TransitLoss2(); tl2.DoLock(true); //jhb Collect all of the Worksheet Names with matrix string[] wsNames = SimulationWorksheetNames; //jhb loop over all the worksheets, processing each one foreach (string name in wsNames) { // raise an event announcing the change to a specific worksheet //jhb if(WorksheetChanged != null) tests whether any other classes have subscribed to this event //jhb WorksheetChanged(name) fires the event; runs all the event handlers - in other words, runs all the registered delegate methods if (WorksheetChanged != null) WorksheetChanged(name); //jhb collect the subreach data for the current worksheet Worksheet excelWS = hydroLib.ExcelHelper.GetWorksheet(name); //jhb create the necessary data, worksheet and workbook objects hydroLib.BIGMatrixStatus status = new hydroLib.BIGMatrixStatus(); Simulation.Matrix_Workbook matrixWB = new HydroSharedAddIn.Simulation.Matrix_Workbook(status); Simulation.Matrix_Worksheet matrixWS = new Simulation.Matrix_Worksheet(matrixWB, excelWS); //jhb try { Process(matrixWS); } catch (Exception e) { tl2.DoLock(false); System.Windows.Forms.MessageBox.Show(e.ToString()); throw e; } GC.Collect(); } tl2.DoLock(false); tl2 = null; //jhb raise an event announcing we are about to begin the workbook recalculation if (OnBeginSpreadsheetRecalc != null) OnBeginSpreadsheetRecalc(); //jhb recalculate the workbook Globals.ThisWorkbook.Application.CalculateFull(); //jhb raise an event announcing the workbook recalculation just completed if (OnEndSpreadsheetRecalc != null) OnEndSpreadsheetRecalc(); //_workbook = null; GC.Collect(); //jhb raise an event announcing the run has completed if (OnRunCompleted != null) { OnRunCompleted(); } }