private void StartBT_Click(object sender, EventArgs e) { string filepath = ErrorLogFilePathValidation.IsValid(this.errorLogPathTextBox.Text); ErrorsHandling.FilesExtenstions extenstionSelected = (ErrorsHandling.FilesExtenstions)Enum.Parse(typeof(ErrorsHandling.FilesExtenstions), filesExtComboBox.Text); pairs.Clear(); if (File.Exists(PathTB.Text)) { ReadXML(PathTB.Text); if (Int32.TryParse(OperationCountTB.Text, out numberofoperations)) { if (pairs.Count > 0) { foreach (var pair in pairs) { a = pair.Item1; b = pair.Item2; Replicator(numberofoperations); } } else { ErrorsHandling.ShowMessageAndSaveLogWithErrors("XML doesn;t contain any valid pairs of 'a' and 'b' attributes", filepath, extenstionSelected); } } else { ErrorsHandling.ShowMessageAndSaveLogWithErrors(String.Format("This: {0} is not an integer", OperationCountTB.Text), filepath, extenstionSelected); } } else { if (!String.IsNullOrEmpty(PathTB.Text)) { ErrorsHandling.ShowMessageAndSaveLogWithErrors($"File under path {PathTB.Text} doesn't exist.", filepath, extenstionSelected); } else { ErrorsHandling.ShowMessageAndSaveLogWithErrors($"Path to file wasn't selected.", filepath, extenstionSelected); } } }
private void ReadXML(string path) { string logline = "\r\nValues in XML: \r\n"; int count = 0; try { pairs = NewXmlReader.GetNodes(path); foreach (Tuple <double, double> tuple in pairs) { logline += String.Format("{0}: a={1}, b={2}\r\n", count, tuple.Item1.ToString(), tuple.Item2.ToString()); } } catch (XmlException e) { MessageBox.Show(e.Message.ToString()); string filepath = ErrorLogFilePathValidation.IsValid(this.errorLogPathTextBox.Text); ErrorsHandling.FilesExtenstions extenstionSelected = (ErrorsHandling.FilesExtenstions)Enum.Parse(typeof(ErrorsHandling.FilesExtenstions), filesExtComboBox.Text); ErrorsHandling.ShowMessageAndSaveLogWithErrors(e.Message.ToString(), filepath, extenstionSelected); } #region Previous XML Reader /* * using (XmlTextReader reader = new XmlTextReader(path)) * { * try * { * while (reader.Read()) * { * switch (reader.NodeType) * { * case XmlNodeType.Element: * if (reader.Name == "value") * { * if (Double.TryParse(reader.GetAttribute("first"), out valA) && Double.TryParse(reader.GetAttribute("second"), out valB)) * { * count++; * * pairs.Add(Tuple.Create(valA, valB)); * logline += String.Format("{0}: a={1}, b={2}\r\n", count, valA.ToString(), valB.ToString()); * * } * else * { * * } * } * break; * } * } * } * catch (XmlException e) * { * MessageBox.Show(e.Message.ToString()); * string filepath = ErrorLogFilePathValidation.IsValid(this.errorLogPathTextBox.Text); * ErrorsHandling.FilesExtenstions extenstionSelected = * (ErrorsHandling.FilesExtenstions)Enum.Parse(typeof(ErrorsHandling.FilesExtenstions), filesExtComboBox.Text); * ErrorsHandling.ShowMessageAndSaveLogWithErrors(e.Message.ToString(), filepath, extenstionSelected); * } * } */ #endregion SaveLog(logline); }