//public List<DistantHosts> DistantHosts { get; set; } public Hosts(int n, HostLogs tj) { window = tj; //NewLog("Konstruktor host", window, "LightBlue"); ReadConfig(n); Task.Run(() => MyConnect(window));; }
private void MyListen(HostLogs window) { while (FlagListening == true) { while (!mySocket.Connected || mySocket == null) { MyConnect(window); } try { myPacket = mySocket.Receive(); if (myPacket != null) { NewLog($"Received message: {myPacket.Payload} on port: {myPacket.Port}", window, "Pink"); } } catch (SocketException e) { if (e.SocketErrorCode == SocketError.Shutdown || e.SocketErrorCode == SocketError.ConnectionReset) { NewLog("Połączenie z chmurą zerwane", window, "LightBlue"); continue; } else { NewLog("Nie można połączyć się z chmurą", window, "LightBlue"); } } } }
public void NewLog(string info, HostLogs tmp2, string color) { HostLogs tmp = tmp2; string timeNow = DateTime.Now.ToString("h:mm:ss") + "." + DateTime.Now.Millisecond.ToString(); string restLog = info; string fullLog = timeNow + " " + restLog; tmp.logBox.AppendText(Environment.NewLine); ColorLog(tmp.logBox, fullLog, color); tmp.logBox.ScrollToEnd(); }
private void MyConnect(HostLogs window) { try { mySocket = new MySocket(CloudIPAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp); mySocket.Connect(new IPEndPoint(CloudIPAddress, CloudPort)); mySocket.Send(Encoding.ASCII.GetBytes("HELLO " + HostName)); Task.Run(() => { MyListen(window); }); } catch (Exception) { } }
public MainWindow() { InitializeComponent(); logBox.Document.Blocks.Remove(logBox.Document.Blocks.FirstBlock); this.Hide(); HostLog1 = new HostLogs(); HostLog1.Title = "Host 1"; HostLog2 = new HostLogs(); HostLog2.Title = "Host 2"; HostLog3 = new HostLogs(); HostLog3.Title = "Host 3"; HostLog1.Show(); HostLog2.Show(); HostLog3.Show(); Hosts hosts1 = new Hosts(1, HostLog1); Hosts hosts2 = new Hosts(2, HostLog2); Hosts hosts3 = new Hosts(3, HostLog3); CPCC cpcc1 = new CPCC(HostLog1); cpcc1.CPCCStart(1); CPCC cpcc2 = new CPCC(HostLog2); cpcc2.CPCCStart(2); CPCC cpcc3 = new CPCC(HostLog3); cpcc3.CPCCStart(3); HostLog1.myHost = hosts1; HostLog1.myCPCC = cpcc1; HostLog2.myHost = hosts2; HostLog2.myCPCC = cpcc2; HostLog3.myHost = hosts3; HostLog3.myCPCC = cpcc3; HostLog1.FillDistantHosts(); HostLog2.FillDistantHosts(); HostLog3.FillDistantHosts(); //Task.Run(() => { hosts1.SendMessage(); }); //Task.Run(() => { cpcc1.SendMessage("127.0.0.1", "dzien dobry"); }); //Task.Run(() => { cpcc1.SendMessage("127.0.0.1", "dzien dobry"); }); //Task.Run(() => { hosts1.SendMessage("127.0.0.10", "127.0.0.30", "13"); }); //Task.Run(() => { cpcc1.SendCallRequest("host1", "host3", "600"); }); //Task.Run(() => { cpcc1.SendMessage("127.0.0.2", "dzien dobry "); }); }
public void NewLog(string info, HostLogs tmp, string color) { window.Dispatcher.Invoke(() => window.NewLog(info, tmp, color)); }
public CPCC(HostLogs tmp) { myWindow = tmp; _cpcc = this; }