async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { string ip = ""; try { string pp = Environment.GetFolderPath(Environment.SpecialFolder.Personal); string fn = Path.Combine(pp, "conn.txt"); using (StreamReader sr = new StreamReader(fn)) { String line = sr.ReadToEnd(); ip = line; } } catch (IOException e) { Console.WriteLine("The file could not be read:"); } bool go = false; IPAddress IP; if (IPAddress.TryParse(ip, out IP)) { Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); s.ReceiveTimeout = 3000; s.SendTimeout = 3000; try { s.Connect(IP, 8883); go = true; s.Close(); } catch (Exception ex) { // something went wrong go = false; } } Items.Clear(); if (go) { tcp server = new tcp(); string[] arr = server.tcpProc(ip).Split(','); for (int i = 0; i < arr.Length; i += 2) { if (arr[i].ToLower().Contains("host") || arr[i].ToLower().Contains("microsoft") || arr[i].ToLower().Equals("idle") || arr[i].ToLower().Equals("system") || arr[i].ToLower().Equals("registry")) { } else { Item item = new Item { Text = arr[i], Description = arr[i + 1] }; Items.Add(item); } } } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }
async Task ExecuteLoadItemsCommand() { if (IsBusy) { return; } IsBusy = true; try { string ip = ""; try { String line = ""; string pp = Environment.GetFolderPath(Environment.SpecialFolder.Personal); string fn = Path.Combine(pp, "conn.txt"); using (StreamReader sr = new StreamReader(fn)) { line = sr.ReadToEnd(); ip = line; } line = ""; using (StreamReader sr = new StreamReader("C:/Users/Spencer Crawford/Documents/GitHub/ComputerController/shortcuts.txt")) { while ((line = sr.ReadLine()) != null) { Apps app = new Apps(); app.Dir = line; apps.Add(app); } } } catch (IOException e) { Console.WriteLine("The file could not be read:"); } bool go = false; IPAddress IP; if (IPAddress.TryParse(ip, out IP)) { Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); s.ReceiveTimeout = 3000; s.SendTimeout = 3000; try { s.Connect(IP, 8883); go = true; s.Close(); } catch (Exception ex) { // something went wrong go = false; } } Items.Clear(); if (go) { tcp server = new tcp(); string[] arr = server.tcpProc(ip).Split(','); //for (int i = 0; i < arr.Length; i += 2) //{ // if (arr[i].ToLower().Contains("host") || arr[i].ToLower().Contains("microsoft") || arr[i].ToLower().Equals("idle") // || arr[i].ToLower().Equals("system") || arr[i].ToLower().Equals("registry")) { } // else // { // Apps App = new Item // { // Text = arr[i], // Description = arr[i + 1] // }; // Items.Add(item); // } //} } } catch (Exception ex) { Debug.WriteLine(ex); } finally { IsBusy = false; } }