Exemplo n.º 1
0
        private void RestartSpooler(StatusRecord record)
        {
            lock (_serviceLock)
            {
                using (ServiceController serviceController = new ServiceController("spooler"))
                {
                    record.Post("SPOOLER STATUS: {0}".FormatWith(serviceController.Status));

                    if (serviceController.Status != ServiceControllerStatus.Running)
                    {
                        bool restarted = false;

                        UpdateStatus("Spooler stopped, trying to restart...".FormatWith(serviceController.Status.ToString()));
                        record.Post("SPOOLER STATE IS {0}, RESTARTING".FormatWith(serviceController.Status));
                        try
                        {
                            // Attempt to restart
                            serviceController.Start();
                            UpdateStatus("Spooler restarted");
                            record.Post("SPOOLER RESTARTED");
                            restarted = true;
                        }
                        catch (InvalidOperationException exception)
                        {
                            TraceFactory.Logger.Error("Failed to start service", exception);
                            record.Post("SPOOLER NOT STARTED");
                        }
                        catch (Win32Exception exception)
                        {
                            TraceFactory.Logger.Error("Failed to start service", exception);
                            record.Post("SPOOLER NOT STARTED");
                        }

                        if (!restarted)
                        {
                            throw new PrintQueueException("Unable to restart the spooler");
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
 private void RecordError(StatusRecord record, QueueInstallationData queueData, Exception ex)
 {
     UpdateStatus("Error, aborting... " + ex.Message);
     record.Post("ERR - ABORT: {0}".FormatWith(ex.Message));
     queueData.Progress = "ERROR";
 }
Exemplo n.º 3
0
 private void RetryOnError(StatusRecord record, Exception ex)
 {
     UpdateStatus("Error retrying... " + ex.Message);
     record.Post("ERR - RETRY: {0}".FormatWith(ex.Message));
     RestartSpooler(record);
 }