private void PipeListener() { CheckIfDisposed(); try { Listen = MainWindow.PipeManager.Listen; while (Listen) { LastAction = DateTime.Now; string request = PipeConnection.Read(); LastAction = DateTime.Now; string use = request.Replace("\0", ""); if (use != "") { PipeConnection.Write("Ok"); if (use == "start") { PipeManager._callback.OnLoadStart(); } else if (use == "finish") { PipeManager._callback.OnLoadFinish(); } else if (use.Contains("$")) { PipeManager._callback.OnLoadStep(use); } } else { PipeConnection.Write("Error: bad request"); } LastAction = DateTime.Now; PipeConnection.Disconnect(); if (Listen) { Connect(); } MainWindow.PipeManager.WakeUp(); } } catch (System.Threading.ThreadAbortException ex) { } catch (System.Threading.ThreadStateException ex) { } catch (Exception ex) { // Log exception } finally { this.Close(); } }
private void PipeListener() { CheckIfDisposed(); try { Listen = Program.PipeManager.Listen; //Form1.ActivityRef.AppendText("Pipe " + this.PipeConnection.NativeHandle.ToString() + ": new pipe started" + Environment.NewLine); while (Listen) { LastAction = DateTime.Now; string request = PipeConnection.Read(); //byte[] bytes = PipeConnection.ReadBytes(); LastAction = DateTime.Now; if (request.Trim() != "") { Console.WriteLine(request); PipeConnection.Write("Ok"); } else { PipeConnection.Write("Error: bad request"); } LastAction = DateTime.Now; PipeConnection.Disconnect(); if (Listen) { //Form1.ActivityRef.AppendText("Pipe " + this.PipeConnection.NativeHandle.ToString() + ": listening" + Environment.NewLine); Connect(); } Program.PipeManager.WakeUp(); } } catch (System.Threading.ThreadAbortException ex) { } catch (System.Threading.ThreadStateException ex) { } catch (Exception ex) { // Log exception } finally { this.Close(); } }
private void PipeListener() { CheckIfDisposed(); try { Listen = AppClient.Server.Listen; AppClient.ChatHistory.Add("Pipe " + this.PipeConnection.NativeHandle.ToString() + ": new pipe started"); while (Listen) { LastAction = DateTime.Now; string request = PipeConnection.Read(); LastAction = DateTime.Now; if (request.Trim() != "") { PacketReceivedArgs es = new PacketReceivedArgs(PacketBuilder.Open(request), request); OnPR(es); AppClient.ChatHistory.Add("Pipe " + this.PipeConnection.NativeHandle.ToString() + ": request handled"); } else { PipeConnection.Write("ERROR 51 BAD REQUEST"); } LastAction = DateTime.Now; PipeConnection.Disconnect(); if (Listen) { Connect(); } AppClient.Server.WakeUp(); } } catch (System.Threading.ThreadAbortException ex) { Log.Write(ex); } catch (System.Threading.ThreadStateException ex) { Log.Write(ex); } catch (Exception ex) { // Log exception Log.Write(ex); } finally { this.Close(); } }
public void StartPipeServer() { isListening = true; ServerPipeConnection PipeConnection = new ServerPipeConnection(pipeName, 512, 512, 5000, false); Task.Run(() => { while (isListening) { PipeConnection.Disconnect(); PipeConnection.Connect(); try { string request = PipeConnection.Read(); onMessage?.Invoke(this, JsonConvert.DeserializeObject <pipeMessageData <object> >(request)); } catch (Exception ex) { } } PipeConnection.Dispose(); }); }
private void PipeListener() { CheckIfDisposed(); try { Listen = HluArcMapExtension.PipeManager.Listen; HluArcMapExtension.PipeData = new List <string>(); StringBuilder sbRequest; bool continueString = false; while (Listen) { LastAction = DateTime.Now; string request = PipeConnection.Read(); while (!String.IsNullOrEmpty(request) && (request != "@")) { if (request == _stringContinue) { continueString = true; } else { if (continueString) { sbRequest = new StringBuilder( HluArcMapExtension.PipeData[HluArcMapExtension.PipeData.Count - 1]); HluArcMapExtension.PipeData[HluArcMapExtension.PipeData.Count - 1] = sbRequest.Append(request).ToString(); continueString = false; } else { HluArcMapExtension.PipeData.Add(request); } } request = PipeConnection.Read(); } if ((HluArcMapExtension.PipeData.Count > 0) && (request == "@")) { // wire event to be notified of outgoing data ready HluArcMapExtension.OutgoingDataReady += new EventHandler(HluArcMapExtension_OutgoingDataReady); // raise event in HluArcMapExtension HluArcMapExtension.PipeManager.HandleRequest(String.Empty); // unwire event HluArcMapExtension.OutgoingDataReady -= HluArcMapExtension_OutgoingDataReady; // send response foreach (string s in HluArcMapExtension.PipeData) { PipeConnection.Write(s); } HluArcMapExtension.PipeData.Clear(); PipeConnection.Write("@"); } LastAction = DateTime.Now; PipeConnection.Disconnect(); if (Listen) { Connect(); } HluArcMapExtension.PipeManager.WakeUp(); } } catch (System.Threading.ThreadAbortException ex) { } catch (System.Threading.ThreadStateException ex) { } catch (Exception ex) { // Log exception } finally { this.Close(); } }