private void message_Received(string msg) { try { NetMessage message = NetParser.ParseMessage(msg); List <string> args = message.GetArguments(); if (message.HasCommand()) { string command = message.GetCommand(); switch (command) { case "connection": string status = args[0]; if (status != "success") { MessageBox.Show(status, "Connection status", MessageBoxButtons.OK, MessageBoxIcon.Warning); Environment.Exit(0); } break; } } } catch (Exception ex) { // Something went wrong throw new Exception(ex.Message); } }
public Result Send(TRequest request, out TResponse response) { response = null; try { Result send; EndPoint endpoint; Socket clientSocket; if (!(send = NetParser.BuildNetworkBindings(Config, out clientSocket, out endpoint))) { return(send); } byte[] data; if (!(send = Package(request, out data))) { return(send); } clientSocket.Connect(endpoint); clientSocket.Send(data); return(ReceiveResponse(clientSocket, out response)); } catch (Exception e) { return(Result.Error(e)); } }
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; }
/// <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; } }