private static async void ConnectAsTcpClient(object iHost) { try { System.Net.WebClient WC = new WebClient(); string RESULT = WC.DownloadString("http://" + FRITZCallMonitor.Gw.ToString()); if (RESULT.IndexOf("FRITZ!Box", StringComparison.OrdinalIgnoreCase) > 0) { FBC = new System.Net.Sockets.TcpClient(); FRITZCallMonitor iH = (FRITZCallMonitor)iHost; using (var tcpClient = new TcpClient()) { FeuerwehrCloud.Helper.Logger.WriteLine("| < [FRITZCallMonitor] *** FRITZ!Box found at " + FRITZCallMonitor.Gw.ToString() + ", trying to attach to CallMonitor"); await tcpClient.ConnectAsync(FRITZCallMonitor.Gw, 1012); FeuerwehrCloud.Helper.Logger.WriteLine("| < [FRITZCallMonitor] *** CallMonitor attached, waiting for calls..."); using (var networkStream = tcpClient.GetStream()) { do { var buffer = new byte[4096]; var byteCount = await networkStream.ReadAsync(buffer, 0, buffer.Length); var response = Encoding.UTF8.GetString(buffer, 0, byteCount); string[] rLine = response.Split(new [] { ";" }, StringSplitOptions.None); switch (rLine [1]) { case "CALL": FeuerwehrCloud.Helper.Logger.WriteLine("| < [FRITZCallMonitor] *** Outgoing call with " + rLine [3] + "/" + rLine [4] + " to: " + rLine [5]); iH.RaiseFinish("text", rLine); break; case "RING": FeuerwehrCloud.Helper.Logger.WriteLine("| < [FRITZCallMonitor] *** Incoming call from: " + rLine [3] + " on number " + rLine [4]); if (BOSConfig.ContainsValue(rLine [3])) { FeuerwehrCloud.Helper.Logger.WriteLine("| < [FRITZCallMonitor] *** Incoming call FAX FROM ILS! Forcing printer tp warm up..."); try { // There's a new Method wo wake up the printer -> FeuerwehrCloud.Generic.PrinterStatus //System.Diagnostics.Process.Start("/usr/bin/lp wakeup.txt"); } catch (Exception ex) { } } break; iH.RaiseFinish("text", rLine); case "CONNECT": FeuerwehrCloud.Helper.Logger.WriteLine("| < [FRITZCallMonitor] *** Pickup call: " + rLine [4]); iH.RaiseFinish("text", rLine); break; case "DISCONNECT": FeuerwehrCloud.Helper.Logger.WriteLine("| < [FRITZCallMonitor] *** Hangup call after " + rLine [3]); iH.RaiseFinish("text", rLine); break; default: FeuerwehrCloud.Helper.Logger.WriteLine("| < [FRITZCallMonitor] *** response was {0}", response); break; } } while (Disposing == false); } } } } catch (Exception ex) { } }