private void Stop(ServiceCell cell) //Label lbl, String serviceName, String serverName)
 {
     if (ServiceHelper.StopService(cell.serverName, cell.serviceName, 10000) == false)
     {
         cell.status = ServiceHelper.ServiceStatus.Unknown;
     }
 }
        private void DoubleClick_Cell(object sender, RoutedEventArgs e)
        {
            Button      lbl  = (Button)sender;
            ServiceCell cell = (ServiceCell)lbl.DataContext;

            if (cell.status == ServiceHelper.ServiceStatus.Running)
            {
                MessageBoxResult result = MessageBox.Show("Please confirm stopping " + Environment.NewLine + cell.serviceName + " on " + cell.serverName, "Warning", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    Thread thread = new Thread(() => Stop(cell));
                    thread.Start();
                }
            }

            if (cell.status == ServiceHelper.ServiceStatus.Stopped)
            {
                MessageBoxResult result = MessageBox.Show("Please confirm starting " + Environment.NewLine + cell.serviceName + " on " + cell.serverName, "Warning", MessageBoxButton.YesNo);
                if (result == MessageBoxResult.Yes)
                {
                    Thread thread = new Thread(() => Start(cell));
                    thread.Start();
                }
            }
        }
        private ServiceCell AddCell(String server, String service) //ServiceAdd.ListViewBindingItem item)
        {
            foreach (ServiceCell cell in s.Items)
            {
                //ServiceCell cell = s.Items[i];

                if (cell.serverName == server && cell.serviceName == service)
                {
                    // already exists
                    return(null);
                }
            }

            ServiceCell newCell = new ServiceCell();

            newCell.serverName  = server;
            newCell.serviceName = service;
            AddButton(newCell);

            //    cells.Add(cell);

/*            cell.button = new Button();
 *          cell.button.Style = Resources["StartedService2"] as Style;
 *          //  cell.button.Content = item.Name;
 *          cell.button.Height = 40;
 *          cell.button.MinWidth = 235;
 *          cell.button.Width = 235;
 *          cell.button.MouseDoubleClick += DoubleClick_Cell;
 *          LinearGradientBrush grad2 = new LinearGradientBrush(Colors.DarkSlateGray, Colors.DarkSlateGray, 0);//Colors.Yellow, 90);
 *          cell.button.Background = grad2;
 *          cell.button.DataContext = cell;
 *          StackPanel sp = new StackPanel();
 *          TextBlock tb = new TextBlock();
 *          tb.Text = service;//item.Name;
 *          tb.FontSize = 12;
 *          tb.HorizontalAlignment = HorizontalAlignment.Right;
 *
 *          SolidColorBrush fore = new SolidColorBrush(Colors.Gainsboro);
 *
 *          tb.Foreground = fore;
 *          TextBlock tb2 = new TextBlock();
 *          tb2.Text = server;//add.Server;
 *          tb2.FontSize = 10;
 *          tb2.Foreground = fore;
 *          tb.HorizontalAlignment = HorizontalAlignment.Right;
 *
 *          sp.Children.Add(tb);
 *          sp.Children.Add(tb2);
 *          cell.button.Content = sp;
 *
 *      //    parent.Children.Add(cell.button);
 *
 *          cell.serverName = server;//add.Server;
 *          cell.serviceName = service;//item.Name;
 *
 *          Thread thread = new Thread(() => Monitor(cell));//lbl, item.Name, add.Server));
 *          thread.Start();
 */
            return(newCell);
        }
Esempio n. 4
0
        public bool Read()
        {
            //services = new ArrayList();
            TextReader tr      = null;
            bool       allRead = true;

            try
            {
                tr = new StreamReader(file);
                String line = "";

                while ((line = tr.ReadLine()) != null)
                {
                    String[] options = line.Split(',');

                    if (options.Length == 1)
                    {
                        ;
                    }
                    //       services.Add(new ServiceItem(options[0].Trim(), "", services.Count + 1));
                    else if (options.Length == 2)
                    {
                        ServiceCell cell = new ServiceCell();
                        cell.serverName = options[0].ToUpper().Trim();
                        if (cell.serverName == "")
                        {
                            cell.serverName = "???";
                        }
                        cell.serviceName = options[1].Trim();
                        if (cell.serviceName == "")
                        {
                            cell.serviceName = "???";
                        }
                        services.Add(cell);
                        //       services.Add(new ServiceItem(options[0].Trim(), options[1].Trim(), services.Count + 1));
                    }
                    else
                    {
                        allRead = false;
                        continue;
                    }
                }
            }
            catch
            {
                allRead = false;
            }
            finally
            {
                tr.Close();
                services = services.OrderBy(e => e.serverName).ThenBy(e => e.serviceName).ToList();
                //  services.Sort();
            }

            return(allRead);
        }
Esempio n. 5
0
        //   public string Server(int idx)
        //   {
        //    foreach (ServiceItem item in services)
        //    {
        //      if (item.ID == idx)
        //          return item.Server;
        //  }
        //
        //  return null;
        // }

        public bool Remove(string server, string service)
        {
            for (int i = 0; i < services.Count; i++)
            {
                ServiceCell item = services[i];
                if (item.serverName == server && item.serviceName == service)
                {
                    services.Remove(item);
                    return(true);
                }
            }
            return(false);
        }
        private void RemoveCell(String server, String service)
        {
            for (int i = 0; i < s.Items.Count; i++)
            //foreach (ServiceCell cell in s.Items)
            {
                ServiceCell cell = s.Items[i];

                if (cell.serverName == server && cell.serviceName == service)
                {
                    RemoveButton(cell);
                    s.Items.Remove(cell);
                    i--;
                }
            }
        }
        private void Monitor(ServiceCell cell)//Label lbl, String serviceName, String serverName)
        {
            while (_terminate == false)
            {
                cell.status = ServiceHelper.Status(cell.serviceName, cell.serverName);
                if (cell.status == ServiceHelper.ServiceStatus.Running)
                {
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        //   cell.label.Background = new LinearGradientBrush(Colors.AntiqueWhite, Colors.Green, 90);
//                        cell.button.Background = new LinearGradientBrush(Colors.LightSeaGreen, Colors.Green, 90);
                        cell.button.Style = Resources["StartedService2"] as Style;
                    }));
                }
                if (cell.status == ServiceHelper.ServiceStatus.Stopped)
                {
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        //    cell.label.Background = new LinearGradientBrush(Colors.AntiqueWhite, Colors.Red, 90);
                        //                      cell.button.Background = new LinearGradientBrush(Colors.LightPink, Colors.Red, 90);
                        cell.button.Style = Resources["StoppedService2"] as Style;
                    }));
                }
                if (cell.status == ServiceHelper.ServiceStatus.Transitional)
                {
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        //    cell.label.Background = new LinearGradientBrush(Colors.AntiqueWhite, Colors.Orange, 90);
//                        cell.button.Background = new LinearGradientBrush(Colors.AntiqueWhite, Colors.Orange, 90);
                        cell.button.Style = Resources["StoppedService2"] as Style;
                    }));
                }
                if (cell.status == ServiceHelper.ServiceStatus.Unknown)
                {
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        //   cell.label.Background = new LinearGradientBrush(Colors.DarkSlateGray, Colors.DarkSlateGray, 90);
                        cell.button.Style = Resources["UnknownService2"] as Style;
                        //      cell.button.Background = new LinearGradientBrush(Colors.DarkSlateGray, Colors.DarkSlateGray, 90);
                    }));
                }

                Thread.Sleep(10000);
            }
        }
        private void AddButton(ServiceCell cell)
        {
            cell.button       = new Button();
            cell.button.Style = Resources["StartedService2"] as Style;
            //  cell.button.Content = item.Name;
            cell.button.Height            = 40;
            cell.button.MinWidth          = 235;
            cell.button.Width             = 235;
            cell.button.MouseDoubleClick += DoubleClick_Cell;
            LinearGradientBrush grad2 = new LinearGradientBrush(Colors.DarkSlateGray, Colors.DarkSlateGray, 0);//Colors.Yellow, 90);

            cell.button.Background  = grad2;
            cell.button.DataContext = cell;
            StackPanel sp = new StackPanel();
            TextBlock  tb = new TextBlock();

            tb.Text                = cell.serviceName;//service;//item.Name;
            tb.FontSize            = 12;
            tb.HorizontalAlignment = HorizontalAlignment.Right;

            SolidColorBrush fore = new SolidColorBrush(Colors.Gainsboro);

            tb.Foreground = fore;
            TextBlock tb2 = new TextBlock();

            tb2.Text               = cell.serverName;//server;//add.Server;
            tb2.FontSize           = 10;
            tb2.Foreground         = fore;
            tb.HorizontalAlignment = HorizontalAlignment.Right;

            sp.Children.Add(tb);
            sp.Children.Add(tb2);
            cell.button.Content = sp;

            //    parent.Children.Add(cell.button);

            //cell.serverName = server;//add.Server;
            //cell.serviceName = service;//item.Name;

            Thread thread = new Thread(() => Monitor(cell));//lbl, item.Name, add.Server));

            thread.Start();

            //  return cell;
        }
        private void RemoveButton(ServiceCell cell)
        {
            foreach (GroupBox gb in stackPanel.Children)
            {
                //GroupBox gb = (GroupBox)sp.Children[0];

                StackPanel sp2 = (StackPanel)gb.Content;
                for (int i = 0; i < sp2.Children.Count; i++)
                //foreach (Control c in sp2.Children)
                {
                    Control c = (Control)sp2.Children[i];
                    if (c.GetType() == typeof(Button))
                    {
                        Button b = (Button)c;
                        if (cell.button == b)
                        {
                            sp2.Children.Remove(b);
                            i--;
                        }
                    }
                }
            }
        }
        private void btnMonitor_Click(object sender, RoutedEventArgs e)
        {
            ServiceAdd add = new ServiceAdd(s);

            // populate combobox
            foreach (String cell in s.Servers) //cells)
            {
                if (!add.comboServers.Items.Contains(cell))
                {
                    add.comboServers.Items.Add(cell);
                }
            }

            add.ShowDialog();

            items = add.Items;

            StackPanel _stackPanel = new StackPanel();

            _stackPanel.HorizontalAlignment = HorizontalAlignment.Left;

            foreach (ServiceAdd.ListViewBindingItem item in items)
            {
                if (item.Checked == false)
                {
                    // check if was previously being monitored
                    RemoveCell(add.Server, item.Name);
                }

                if (item.Checked)
                {
                    ServiceCell cell = AddCell(add.Server, item.Name);

                    if (cell == null)
                    {
                        // cell already being monitored
                        continue;
                    }

                    _stackPanel.Children.Add(cell.button);
                    s.Items.Add(cell);
                }
            }

            try
            {
                Process[] proc = System.Diagnostics.Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension("notepad"), "VSEMPSYSAPP05");
                if (proc.Count() > 0)
                {
                    Debug.WriteLine("proc");
                }
                //String s = proc[0].StartInfo.Arguments.ToString();
            }
            catch (Exception ex)
            {
            }

            if (_stackPanel.Children.Count > 0)
            {
                GroupBox gb = CreateGroupBox(add.Server);
                gb.Content = _stackPanel;
                stackPanel.Children.Add(gb);
            }
        }