private void lv_SelectionChanged(object sender, SelectionChangedEventArgs e) { if (lv.SelectedItem == null) { btnStart.IsEnabled = false; btnStop.IsEnabled = false; btnRestart.IsEnabled = false; return; } ServiceStruct ss = (ServiceStruct)lv.SelectedItem; if (ss.status.ToString().Equals("Running")) { btnStart.IsEnabled = false; btnStop.IsEnabled = true; btnRestart.IsEnabled = true; } else { btnStart.IsEnabled = true; btnStop.IsEnabled = false; btnRestart.IsEnabled = false; } }
private void btnStart_Click(object sender, RoutedEventArgs e) { ServiceStruct ss = (ServiceStruct)lv.SelectedItem; ServiceController sc = new ServiceController(ss.name); sc.Start(); sc.WaitForStatus(ServiceControllerStatus.Running); sc.Close(); GetAllServices(); }
private void GetAllServices() { allServices = ServiceController.GetServices(); allServicesList = new List <ServiceStruct>(); foreach (ServiceController sc in allServices) { if (btnFilter.IsChecked == true) { int isContains = 0; foreach (string arg in filter) { if (string.IsNullOrWhiteSpace(arg)) { continue; } if (sc.DisplayName.ToLower().Contains(arg)) { isContains++; } } if (isContains == 0) { continue; } } ServiceStruct ss = new ServiceStruct(); ss.name = sc.ServiceName; ss.status = sc.Status; ss.Name = sc.DisplayName; ss.Status = ss.GetDisplayName(sc.Status); allServicesList.Add(ss); } lv.ItemsSource = allServicesList; txtNum.Text = "服务个数:" + allServicesList.Count.ToString(); }
public void parseConfig() { StreamReader data = new StreamReader("config.ini");//open the config file string temp = ""; ServiceStruct tempStruct = new ServiceStruct { Methods = new string[10], MethodNames = new string[10] }; temp = data.ReadLine(); do { int i = 0; if (temp.Contains("--NAME")) { tempStruct.Name = data.ReadLine(); if (data.ReadLine().Contains("IP")) { tempStruct.IP = data.ReadLine(); temp = data.ReadLine(); while (data.EndOfStream != true && temp.Contains("--METHOD")) { tempStruct.MethodNames[i] += data.ReadLine(); temp = data.ReadLine(); while (!data.EndOfStream && !temp.Contains("--END")) { tempStruct.Methods[i] += temp + Environment.NewLine; temp = data.ReadLine(); } i++; temp = data.ReadLine(); } configInfo.Add(tempStruct); // temp = data.ReadLine(); } } } while (data.EndOfStream != true) ; }
private void GetAllServices() { allServices = ServiceController.GetServices(); allServicesList = new List<ServiceStruct>(); foreach (ServiceController sc in allServices) { if (btnFilter.IsChecked == true) { int isContains = 0; foreach (string arg in filter) { if (string.IsNullOrWhiteSpace(arg)) continue; if (sc.DisplayName.ToLower().Contains(arg)) isContains++; } if (isContains == 0) continue; } ServiceStruct ss = new ServiceStruct(); ss.name = sc.ServiceName; ss.status = sc.Status; ss.Name = sc.DisplayName; ss.Status = ss.GetDisplayName(sc.Status); allServicesList.Add(ss); } lv.ItemsSource = allServicesList; txtNum.Text = "服务个数:" + allServicesList.Count.ToString(); }