Ejemplo n.º 1
0
 private void AddDaemon()
 {
     if (ListViewDaemons.Items.Count <= 128)
     {
         try
         {
             var  serviceEditWindow = new ServiceEditWindow(null);
             bool?dialogResult      = serviceEditWindow.ShowDialog(); //Wait until the window is closed
             if (dialogResult.HasValue && dialogResult.Value)
             {
                 _processCollection.Add(ServiceListViewItem.CreateFromServiceDefinition(serviceEditWindow.GetServiceStartInfo()));
             }
         }
         catch (Exception ex)
         {
             MessageBox.Show(_resManager.GetString("failed_to_create_a_new_service") + "\n" + ex.Message, _resManager.GetString("error"), MessageBoxButton.OK, MessageBoxImage.Error);
         }
     }
     else
     {
         MessageBox.Show(_resManager.GetString("max_limit_reached"), _resManager.GetString("warning"), MessageBoxButton.OK, MessageBoxImage.Warning);
     }
 }
Ejemplo n.º 2
0
        private void EditDaemon()
        {
            if (ListViewDaemons.SelectedItem == null)
            {
                return;
            }

            var serviceListViewItem = (ServiceListViewItem)ListViewDaemons.SelectedItem;

            //Stop service first
            using (var serviceController = new ServiceController(serviceListViewItem.ServiceName))
            {
                if (serviceController.Status != ServiceControllerStatus.Stopped)
                {
                    MessageBoxResult result = MessageBox.Show(_resManager.GetString("you_must_stop_the_service_first"),
                                                              _resManager.GetString("information"), MessageBoxButton.YesNo, MessageBoxImage.Information);


                    if (result == MessageBoxResult.Yes)
                    {
                        StopService(serviceListViewItem);

                        try
                        {
                            serviceController.WaitForStatus(ServiceControllerStatus.Stopped, TimeSpan.FromSeconds(10));
                        }
                        catch (TimeoutException ex)
                        {
                            //TODO: Better message
                            MessageBox.Show("Cannot stop the service:\n" + ex.Message, _resManager.GetString("error"), MessageBoxButton.OK, MessageBoxImage.Error);
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                }
            }


            try
            {
                //Open service edit window with the data from registry
                var serviceEditWindow = new ServiceEditWindow(RegistryManagement.LoadServiceStartInfosFromRegistry(serviceListViewItem.ServiceName));
                //stops until windows has been closed
                bool?dialogResult = serviceEditWindow.ShowDialog();
                //Check result
                if (dialogResult.HasValue && dialogResult.Value)
                {
                    DmServiceDefinition serviceDefinition = serviceEditWindow.GetServiceStartInfo();
                    if (string.Equals(serviceDefinition.ServiceName, serviceListViewItem.ServiceName))
                    {
                        //Update serviceListViewItem
                        _processCollection[_processCollection.IndexOf(serviceListViewItem)] = ServiceListViewItem.CreateFromServiceDefinition(serviceDefinition);
                    }
                    else
                    {
                        //Create new daemon (Import as happend with a diffrent service name => create new service with that name)
                        _processCollection.Add(ServiceListViewItem.CreateFromServiceDefinition(serviceDefinition));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(_resManager.GetString("cannot_load_data_from_registry") + "\n" + ex.Message, _resManager.GetString("error"), MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }