private async Task <Pc> InitPC() { Pc tempPc = new Pc(); if (File.Exists("Secret.Data")) { using (FileStream fs = new FileStream("Secret.Data", FileMode.Open, FileAccess.Read)) using (StreamReader sr = new StreamReader(fs)) { int tempo = -1; if (!int.TryParse(sr.ReadLine(), out tempo)) { System.Windows.MessageBox.Show("Server Connection Error", "OverSeerAgent"); return(null); } tempPc.id = tempo; tempPc.GUID = sr.ReadLine(); } } Pc temp = HttpMessage.MethodPost("api/Pcs", tempPc).Result; if (temp == null) { System.Windows.MessageBox.Show("Server Connection Error", "OverSeerAgent"); App.Current.Shutdown(); return(temp); } using (FileStream fs = new FileStream("Secret.Data", FileMode.Create, FileAccess.Write)) using (StreamWriter sw = new StreamWriter(fs)) { sw.WriteLine(temp.id); sw.WriteLine(temp.GUID); } return(temp); }
public AddPCMV() { IPAddress ip; Pc = Data.Pc; Save = new CustomCUMmand <string>( (s) => { if (!IPAddress.TryParse(Pc.IP, out ip)) { System.Windows.MessageBox.Show("Wrong IP"); return; } ; PC res = HttpMessage.MethodPost("api/PcEditor/", Pc).Result; if (res.id == -1) { System.Windows.MessageBox.Show("Wrong Input"); return; } Manager.Close(typeof(AddPC)); }, () => { if (string.IsNullOrEmpty(Pc.Name) || string.IsNullOrEmpty(Pc.IP) || string.IsNullOrEmpty(Pc.Port.ToString())) { return(false); } else { return(true); } }); }
public EditMV() { Init(); AddPC = new CustomCUMmand <string>( (s) => { switch (s) { case "Chouse": Data.Pc = ChosenGroupePC; break; case "All": Data.Pc = ChosenAllPC; break; } Manager.AddWindowsOpen(new AddPC()); Data.Pc = new PC(); }); Save = new CustomCUMmand <string>( (s) => { List <PcGroupe> temp = new List <PcGroupe>(); temp.Add(UnGroupe); temp.AddRange(MainGroupe); Data.PcGroupe = new ObservableCollection <PcGroupe>(temp); Manager.Close(typeof(EditV)); }); Remove = new CustomCUMmand <string>( (s) => { PC ret = HttpMessage.MethodDell <PC>("api/PcEditor/", ChosenGroupePC.id).Result; if (ret.id == -1) { System.Windows.MessageBox.Show("Wrong Input"); return; } PC temp = ChosenGroupePC; UnGroupe.PcMs.Add(temp); SelectedGroupe.PcMs.Remove(temp); ChosenGroupePC = null; }, () => { if (ChosenGroupePC == null) { return(false); } else { return(true); } }); Add = new CustomCUMmand <string>( (s) => { PC ret = HttpMessage.MethodPut("api/PcEditor/" + SelectedGroupe.id, ChosenAllPC).Result; if (ret.id == -1) { System.Windows.MessageBox.Show("Wrong Input"); return; } PC temp = ChosenAllPC; SelectedGroupe.PcMs.Add(temp); UnGroupe.PcMs.Remove(temp); ChosenAllPC = null; }, () => { if (ChosenAllPC == null || SelectedGroupe == null) { return(false); } else { return(true); } }); AddGroupe = new CustomCUMmand <string>( (s) => { PcGroupe newGroup = new PcGroupe() { Name = "NewGroup" }; newGroup = HttpMessage.MethodPost("api/PcGroups", newGroup).Result; if (newGroup.id == 0 || string.IsNullOrWhiteSpace(newGroup.Name)) { System.Windows.MessageBox.Show("Wrong Input"); return; } MainGroupe.Add(newGroup); }); UpdateName = new CustomCUMmand <string>( (s) => { PcGroupe result = HttpMessage.MethodPut("api/PcGroups/" + SelectedGroupe.id, SelectedGroupe).Result; if (result.id != selectedGroupe.id) { System.Windows.MessageBox.Show("Wrong Input"); } }, () => { if (SelectedGroupe != null) { if (!string.IsNullOrWhiteSpace(SelectedGroupe.Name)) { return(true); } else { return(false); } } else { return(false); } }); RemoveGroupe = new CustomCUMmand <string>( (s) => { //TODO Ебанет? PcGroupe respounce = HttpMessage.MethodDell <PcGroupe>("api/PcGroups", SelectedGroupe.id).Result; if (respounce.id == -1) { System.Windows.MessageBox.Show("WrongInput"); return; } PcGroupe temp = SelectedGroupe; temp.PcMs.ToList().ForEach(x => unGroupe.PcMs.Add(x)); MainGroupe.Remove(temp); Data.PcGroupe.Remove(temp); SelectedGroupe = null; }, () => { if (SelectedGroupe == null) { return(false); } else { return(true); } }); }