// Output IEnumerable<string> creator private IList <string[]> FormatOutputData(AnalysisManager results) { // Set up list of data to write List <string[]> dataToWrite = new List <string[]>(); //Create list of output strings in csv format dataToWrite.Add(new string[] { "Node", "X", "Y", "theta", "P", "V", "M", "Sa", "Ss", "Sb" }); IEnumerator <INode> nodesEnumerator = results.Nodes.GetEnumerator(); IEnumerator <double?> nodeForces = results.Forces.GetEnumerator(); IEnumerator <double> stressesEnumerator = results.Stresses.GetEnumerator(); for (int i = 0; nodesEnumerator.MoveNext(); i++) { int n = 0; string[] line = new string[dataToWrite[0].Count()]; line[n++] = i.ToString(); for (int j = 0; j < nodesEnumerator.Current.Location.Count(); j++) { line[n++] = nodesEnumerator.Current.Location[j].ToString(); } for (int j = 0; j < nodesEnumerator.Current.Force.Count(); j++) { nodeForces.MoveNext(); line[n++] = nodeForces.Current.Value.ToString(); } for (int j = 0; j < nodesEnumerator.Current.Force.Count(); j++) { stressesEnumerator.MoveNext(); line[n++] = stressesEnumerator.Current.ToString(); } dataToWrite.Add(line); } return(dataToWrite); }
// Event handler for clicking the solve button private void toolStripSolveButton_Click(object sender, EventArgs e) { AnalysisManager analysis = new AnalysisManager(objectHolder1); toolStripProgressBar1.Value = 0; toolStripProgressBar1.Visible = true; toolStrip1.Enabled = false; objectHolder1.Enabled = false; componentPallette1.Enabled = false; solveWorker.RunWorkerAsync(analysis); }
// Async work completed function private void solveWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (e.Error != null) { MessageBox.Show(e.Error.Message); } else { AnalysisManager analysis = (AnalysisManager)e.Result; PrintResult(FormatOutputData(analysis)); } toolStripProgressBar1.Visible = false; toolStrip1.Enabled = true; objectHolder1.Enabled = true; componentPallette1.Enabled = true; }
// Async helper function public AnalysisManager Process(AnalysisManager analysis, BackgroundWorker worker) { analysis.RunAnalysis(worker); return(analysis); }