Ejemplo n.º 1
0
        /// <summary>
        /// Add the Main Form thread to the thread list and start it
        /// </summary>
        public void StartMainWindowThread()
        {
            if (_mainFormThread != null)
            {
                return;
            }

            _logger.Debug("Starting main form thread");

            var t = new SynchronizedThread(() =>
            {
                try
                {
                    MainWindow.ShowDialogTopMost();
                    _mainFormThread = null;
                }
                catch (Exception ex) { _logger.Error(ex); }
            });

            _mainFormThread      = t;
            _mainFormThread.Name = "MainFormThread";
            _mainFormThread.SetApartmentState(ApartmentState.STA);

            StartSynchronizedThread(t);
        }
Ejemplo n.º 2
0
 public void LaunchMainWindow()
 {
     if (_mainWindowThread != null)
     {
         _shellManager.MainShellToFront();
         return;
     }
     _mainWindowThread = _threadManager.StartSynchronizedUiThread(MainWindowLaunchThreadMethod, "MainWindowThread");
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Restarts the thread if other threads are available in the queue
 /// </summary>
 /// <param name="sender">Event sender</param>
 /// <param name="e">Detailed information about the event</param>
 private void ConversionThreadFinished(object sender, ThreadFinishedEventArgs e)
 {
     _conversionThread = null;
     _isThreadRunning  = false;
     if (Count > 0)
     {
         StartThread();
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        ///     Starts the first thread from the thread queue
        /// </summary>
        private void StartThread()
        {
            Logger.Trace("COM: Starting thread...");
            _isThreadRunning  = true;
            _conversionThread = ThreadQueue.Dequeue();

            _conversionThread.OnThreadFinished += ConversionThreadFinished;
            _conversionThread.Start();
        }
Ejemplo n.º 5
0
 private void MainWindowLaunchThreadMethod()
 {
     try
     {
         _interactionInvoker.Invoke(new MainWindowInteraction());
     }
     finally
     {
         _mainWindowThread = null;
     }
 }
Ejemplo n.º 6
0
 private void MainWindowLaunchThreadMethod()
 {
     try
     {
         _shellManager.ShowMainShell();
     }
     finally
     {
         _mainWindowThread = null;
     }
 }
Ejemplo n.º 7
0
        private void StartProcessing()
        {
            if (_jobInfoQueue.IsEmpty && !_managePrintJobs)
            {
                return;
            }

            _processingThread = new SynchronizedThread(ProcessJobs) { Name = "ProcessingThread" };
            _processingThread.SetApartmentState(ApartmentState.STA);

            _threadManager.StartSynchronizedThread(_processingThread);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Add the clean up thread to the thread list and start it.
        /// The thread will look for outdated temporary files and will delete them
        /// </summary>
        public void StartCleanUpThread()
        {
            if (_cleanUpThread != null)
            {
                return;
            }

            _logger.Debug("Starting cleanup");

            var t = new SynchronizedThread(() => { JobInfoQueue.Instance.CleanTempFiles(); _cleanUpThread = null; });

            _cleanUpThread      = t;
            _cleanUpThread.Name = "CleanUpThread";

            StartSynchronizedThread(t);
        }
Ejemplo n.º 9
0
        private void MainWindowLaunchThreadMethod()
        {
            try
            {
                if (_routine == null)
                {
                    _routine = new StartupRoutine();
                }

                _shellManager.ShowMainShell();
            }
            finally
            {
                _mainWindowThread = null;
            }
        }
Ejemplo n.º 10
0
#pragma warning restore CS0067

        /// <summary>
        ///     Adds and starts a synchronized thread to the thread list. The application will wait for all of these to end before
        ///     it terminates
        /// </summary>
        /// <param name="thread">A thread that needs to be synchronized. This thread will not be automatically started</param>
        public void StartSynchronizedThread(ISynchronizedThread thread)
        {
            if (_isShuttingDown)
            {
                _logger.Warn("Tried to start thread while shutdown already started!");
                return;
            }

            _logger.Debug("Adding thread " + thread.Name);

            _threads.Enqueue(thread);

            if (thread.ThreadState == ThreadState.Unstarted)
            {
                thread.Start();
            }
        }
Ejemplo n.º 11
0
        private void MainWindowLaunchThreadMethod()
        {
            try
            {
                if (_routine == null)
                {
                    _routine = new StartupRoutine();
                    _routine.AddAction(new StartupNavigationAction(RegionNames.MainRegion, MainRegionViewNames.HomeView));
                }

                _shellManager.ShowMainShell(_routine);
            }
            finally
            {
                _mainWindowThread = null;
            }
        }
Ejemplo n.º 12
0
        /// <summary>
        ///     Adds a new thread to the thread pool
        /// </summary>
        /// <param name="aThread">The thread to be added</param>
        public void AddThread(ISynchronizedThread aThread)
        {
            if (aThread.ThreadState != ThreadState.Unstarted)
            {
                throw new ArgumentException(nameof(aThread));
            }

            Logger.Trace("COM: Pushing new thread into the thread queue.");
            ThreadQueue.Enqueue(aThread);

            if (Count != 1 || _isThreadRunning)
            {
                return;
            }

            Logger.Trace("COM: Thread was added therefore the corresponding event is fired.");
            OnThreadAdded?.Invoke(this, new EventArgs());
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     Adds a new thread to the thread pool
        /// </summary>
        /// <param name="aThread">The thread to be added</param>
        public void AddThread(ISynchronizedThread aThread)
        {
            if (aThread.ThreadState == ThreadState.Running)
            {
                aThread.Abort();
            }

            Logger.Trace("COM: Pushing new thread into the thread queue.");
            ThreadQueue.Enqueue(aThread);

            if (Count != 1 || _isThreadRunning)
            {
                return;
            }

            Logger.Trace("COM: Thread was added therefore the corresponding event is fired.");
            OnThreadAdded?.Invoke(new object(), new EventArgs());
        }
Ejemplo n.º 14
0
        /// <summary>
        ///     Adds and starts a synchronized thread to the thread list. The application will wait for all of these to end before
        ///     it terminates
        /// </summary>
        /// <param name="thread">A thread that needs to be synchronized. This thread will not be automatically started</param>
        public void StartSynchronizedThread(ISynchronizedThread thread)
        {
            lock (LockObject)
            {
                if (_isShuttingDown)
                {
                    _logger.Warn("Tried to start thread while shutdown already started!");
                    return;
                }

                _logger.Debug("Adding thread " + thread.Name);

                _threads.Add(thread);
                thread.OnThreadFinished += thread_OnThreadFinished;

                if (thread.ThreadState == ThreadState.Unstarted)
                {
                    thread.Start();
                }
            }
        }
Ejemplo n.º 15
0
        private void ProcessJobs()
        {
            try
            {
                while (!_jobInfoQueue.IsEmpty || _managePrintJobs)
                {
                    try
                    {
                        if (_managePrintJobs)
                        {
                            throw new ManagePrintJobsException();
                        }

                        var jobInfo = _jobInfoQueue.NextJob;

                        if (jobInfo.SourceFiles.Count == 0)
                        {
                            _logger.Info("JobInfo has no source files and will be skipped");
                            _jobInfoQueue.Remove(jobInfo, true);
                            continue;
                        }

                        _logger.Debug("New PrintJob {0} from Printer {1}", jobInfo.InfFile,
                            jobInfo.SourceFiles[0].PrinterName);

                        var repeatJob = true;

                        try
                        {
                            ProcessJob(jobInfo);
                            // If Job was processed without ManagePrintJobsException, it can be removed
                            repeatJob = false;
                        }
                        catch (InvalidDataException ex)
                        {
                            _logger.Error("There was an invalid data exception while parsing the ps file: " + ex);
                            repeatJob = false;
                        }
                        finally
                        {
                            if (!repeatJob)
                            {
                                // ensure that the current job is removed even if an exception is thrown
                                _logger.Trace("Removing job from Queue");
                                _jobInfoQueue.Remove(jobInfo, true);
                            }
                        }
                    }
                    catch (ManagePrintJobsException)
                    {
                        _managePrintJobs = false;
                        _logger.Trace("Managing print jobs");
                        _managePrintJobExceptionHandler.HandleException();
                    }
                }
            }
            catch (InterruptWorkflowException)
            {
                _logger.Warn("Interrupted workflow");
            }
            catch (Exception ex)
            {
                _logger.Error("There was an error while processing the print jobs: " + ex);

                throw;
            }
            finally
            {
                if (!_jobInfoQueue.IsEmpty)
                    _logger.Warn("Processing finishes while there are print jobs left.");

                _processingThread = null;
            }
        }
Ejemplo n.º 16
0
        private void ProcessJobs()
        {
            try
            {
                while (!JobInfoQueue.Instance.IsEmpty || _managePrintJobs)
                {
                    try
                    {
                        if (_managePrintJobs)
                        {
                            throw new ManagePrintJobsException();
                        }

                        IJobInfo jobInfo = JobInfoQueue.Instance.NextJob;

                        if (jobInfo.SourceFiles.Count == 0)
                        {
                            _logger.Info("JobInfo has no source files and will be skipped");
                            JobInfoQueue.Instance.Remove(jobInfo);
                            continue;
                        }

                        _logger.Debug("New PrintJob {0} from Printer {1}", jobInfo.InfFile,
                                      jobInfo.SourceFiles[0].PrinterName);

                        bool repeatJob = true;

                        try
                        {
                            ProcessJob(jobInfo);

                            // If Job was processed without ManagePrintJobsException, it can be removed
                            repeatJob = false;
                        }
                        finally
                        {
                            if (!repeatJob)
                            {
                                // ensure that the current job is removed even if an exception is thrown
                                _logger.Trace("Removing job from Queue");
                                JobInfoQueue.Instance.Remove(jobInfo);
                            }
                        }
                    }
                    catch (ManagePrintJobsException)
                    {
                        _managePrintJobs = false;
                        _logger.Trace("Managing print jobs");
                        if (ManagePrintJobsAction != null)
                        {
                            ManagePrintJobsAction();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.Error("There was an error while processing the print jobs: " + ex);
            }
            finally
            {
                if (!JobInfoQueue.Instance.IsEmpty)
                {
                    _logger.Warn("Processing finishes while there are print jobs left.");
                }

                _processingThread = null;
            }
        }
Ejemplo n.º 17
0
 /// <summary>
 ///     Create new EventArgs
 /// </summary>
 /// <param name="thread">SynchronizedThread that is concerned</param>
 public ThreadFinishedEventArgs(ISynchronizedThread thread)
 {
     SynchronizedThread = thread;
 }