/// <summary> /// Set up a parser test. This method will <see cref="Initialize(string)"/> /// the <paramref name="value"/> passed, read the value using an <see cref="InpFileReader"/>, /// parse the file using an <see cref="InpParser"/> and then return the created /// <see cref="InpProject"/>. /// </summary> /// <param name="value">The string that will be parsed</param> protected virtual IInpProject SetupProject(string value) { // Initialize the project from the string passed to // this method Initialize(value); // Initialize the project, reader and parser var project = new InpProject(); var reader = new InpFileReader(MemoryStream); var parser = new InpParser(); // Parse the file using the above project, reader and parser parser.ParseFile(project, reader); // return the project return(project); }
private void DoOpen(string netFile) { string fileExtension = (Path.GetExtension(netFile) ?? string.Empty).ToLowerInvariant(); if (fileExtension != ".net" && fileExtension != ".inp" && fileExtension != ".xml" && fileExtension != ".gz") { return; } _inpFile = netFile; InputParser inpParser; switch (fileExtension.ToLowerInvariant()) { case ".inp": inpParser = new InpParser(); break; case ".net": inpParser = new NetParser(); break; case ".xml": inpParser = new XmlParser(false); break; case ".gz": inpParser = new XmlParser(true); break; default: MessageBox.Show( "Not supported file type: *" + fileExtension, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } EpanetNetwork net; try { net = inpParser.Parse(new EpanetNetwork(), _inpFile); } catch (ENException ex) { MessageBox.Show( this, ex + "\nCheck epanet.log for detailed error description", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); ClearInterface(); _inpFile = null; return; } catch (Exception ex) { MessageBox.Show( this, "Unable to parse network configuration file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Log.Error("Unable to parse network configuration file: {0}", ex); ClearInterface(); _inpFile = null; return; } Net = net; }
private void LoadNetwork() { var parser = new InpParser(); Network = parser.Parse(new Network(), InpPath); }
/// <summary>Report options dialog constructor.</summary> public ReportOptions(string inpFile, string msxFile) : this() { if (inpFile == null) { return; } _fileInp = inpFile; _net = new EpanetNetwork(); try { InputParser inpParser; string extension = Path.GetExtension(inpFile); switch (extension.ToLowerInvariant()) { case ".inp": inpParser = new InpParser(); break; case ".net": inpParser = new NetParser(); break; case ".xml": inpParser = new XmlParser(false); break; case ".gz": inpParser = new XmlParser(true); break; default: inpParser = new InpParser(); break; } _net = inpParser.Parse(new EpanetNetwork(), inpFile); } catch (ENException ex) { MessageBox.Show( ex.Message + "\nCheck epanet.log for detailed error description", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (msxFile == null) { return; } _fileMsx = msxFile; _epanetTk = new EnToolkit2(_net); _netMsx = new EpanetMSX(_epanetTk); try { ErrorCodeType ret = _netMsx.Load(_fileMsx); if (ret != 0) { MessageBox.Show("MSX parsing error " + ret, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); _fileMsx = null; _netMsx = null; _epanetTk = null; } } catch (IOException) { MessageBox.Show( "IO error while reading the MSX file", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); _fileMsx = null; _netMsx = null; _epanetTk = null; } }