예제 #1
0
        private bool SetupSharing(InstallerPrintDevice printDevice, StatusRecord record, QueueInstallationData queueData)
        {
            bool status = true;

            try
            {
                UpdateStatus("Configuring sharing...");
                record.Start("SHARING");

                Retry.WhileThrowing
                (
                    () => SetupSharingAction(printDevice, record),
                    3,
                    TimeSpan.FromSeconds(3),
                    new List <Type>()
                {
                    typeof(Win32Exception)
                }
                );

                record.End();
            }
            catch (PrintQueueException ex)
            {
                RecordError(record, queueData, ex);
                status = false;
            }

            return(status);
        }
예제 #2
0
        private bool SetupClientRendering(InstallerPrintDevice printDevice, StatusRecord record, QueueInstallationData queueData)
        {
            bool status = true;

            try
            {
                UpdateStatus(@"Configuring ""Render on Client"" setting...");
                record.Start("RENDERING");

                Retry.WhileThrowing
                (
                    () => SetupClientRenderingAction(printDevice, record),
                    3,
                    TimeSpan.FromSeconds(3),
                    new List <Type>()
                {
                    typeof(ArgumentNullException),
                    typeof(SecurityException),
                    typeof(ObjectDisposedException),
                    typeof(UnauthorizedAccessException),
                    typeof(IOException)
                }
                );

                record.End();
            }
            catch (PrintQueueException ex)
            {
                RecordError(record, queueData, ex);
                status = false;
            }

            return(status);
        }
예제 #3
0
        private bool SetupPort(InstallerPrintDevice printDevice, StatusRecord record, QueueInstallationData queueData)
        {
            bool status = true;

            try
            {
                UpdateStatus("Creating port... " + printDevice.Port.PortName);
                record.Start("PORT");

                Retry.WhileThrowing
                (
                    () => SetupPortAction(printDevice, record),
                    3,
                    TimeSpan.FromSeconds(3),
                    new List <Type>()
                {
                    typeof(Win32Exception)
                }
                );

                record.End();
            }
            catch (PrintQueueException ex)
            {
                RecordError(record, queueData, ex);
                status = false;
            }

            return(status);
        }
예제 #4
0
 private void SetupSharingAction(InstallerPrintDevice printDevice, StatusRecord record)
 {
     try
     {
         printDevice.EnableSharedQueue();
     }
     catch (Win32Exception ex)
     {
         RetryOnError(record, ex);
         throw;
     }
 }
예제 #5
0
 private void SetupClientRenderingAction(InstallerPrintDevice printDevice, StatusRecord record)
 {
     try
     {
         printDevice.EnableClientRendering();
     }
     catch (Win32Exception ex)
     {
         RetryOnError(record, ex);
         throw;
     }
 }
예제 #6
0
 private void InstallQueueAction(InstallerPrintDevice printDevice, StatusRecord record)
 {
     try
     {
         printDevice.CreatePrintQueue(_installationTimeout);
     }
     catch (Win32Exception ex)
     {
         RetryOnError(record, ex);
         throw;
     }
 }
예제 #7
0
 private void SetupPortAction(InstallerPrintDevice printDevice, StatusRecord record)
 {
     try
     {
         printDevice.Port.CreatePort();
     }
     catch (Win32Exception ex)
     {
         RetryOnError(record, ex);
         throw;
     }
 }
예제 #8
0
        private bool InstallQueue(InstallerPrintDevice printDevice, StatusRecord record, QueueInstallationData queueData)
        {
            bool status = true;

            try
            {
                UpdateStatus("Creating queue... " + queueData.QueueName);
                record.Start("QUEUE");

                Retry.WhileThrowing
                (
                    () => InstallQueueAction(printDevice, record),
                    3,
                    TimeSpan.FromSeconds(2),
                    new List <Type>()
                {
                    typeof(Win32Exception)
                }
                );

                record.End();
            }
            catch (PrintQueueException ex)
            {
                RecordError(record, queueData, ex);
                status = false;
            }
            catch (Win32Exception ex)
            {
                RecordError(record, queueData, ex);
                status = false;
            }
            catch (InvalidOperationException ex)
            {
                RecordError(record, queueData, ex);
                status = false;
            }

            return(status);
        }
예제 #9
0
        private void CreatePrintQueue(object state)
        {
            _installThreads.Add(Thread.CurrentThread);

            QueueInstallationData queueData = state as QueueInstallationData;
            InstallStatusData     status    = _installStatus.Create(queueData);

            try
            {
                if (queueData.QueueIsInstalled)
                {
                    // This queue is already installed, so return
                    return;
                }

                if (string.IsNullOrEmpty(queueData.Address))
                {
                    UpdateStatus("NO ADDRESS - SKIPPING");
                    status.Record("NO ADDRESS - SKIPPING");
                    return;
                }

                // Install the initial Print Driver for this queue if needed
                PrintDeviceDriver driver = queueData.Driver;

                InstallDriver(driver);

                DateTime queueInstallStart = DateTime.Now;
                status.Record("NEW ENTRY START", out queueInstallStart);

                TcpIPPortInstaller port = TcpIPPortInstaller.CreateRawPortManager
                                          (
                    queueData.Address,
                    portNumber: queueData.Port,
                    portName: "IP_{0}:{1}".FormatWith(queueData.Address, queueData.Port),
                    snmpEnabled: queueData.SnmpEnabled
                                          );

                queueData.Progress = "Working...";
                UpdateStatus("Installing... " + queueData.QueueName);

                TraceFactory.Logger.Debug("UseConfigurationFile: {0}".FormatWith(queueData.UseConfigurationFile));
                if (!queueData.UseConfigurationFile)
                {
                    // Make sure there are no CFM files sitting in the driver directory
                    RemoveConfigFiles(status);
                    RestoreDriverDefaults(driver, status);
                }

                InstallerPrintDevice printDevice = new InstallerPrintDevice(driver, port);
                printDevice.ConfigFile         = (queueData.UseConfigurationFile) ? queueData.ConfigurationFilePath : string.Empty;
                printDevice.QueueName          = queueData.QueueName;
                printDevice.IsSharedQueue      = queueData.Shared;
                printDevice.IsRenderedOnClient = queueData.ClientRender;

                bool         queueCreated = true;
                StatusRecord record       = new StatusRecord(status);
                while (true)
                {
                    if (!SetupPort(printDevice, record, queueData))
                    {
                        queueCreated = false;
                        break;
                    }

                    if (!InstallQueue(printDevice, record, queueData))
                    {
                        queueCreated = false;
                        break;
                    }

                    if (!SetupClientRendering(printDevice, record, queueData))
                    {
                        queueCreated = false;
                        break;
                    }

                    if (!SetupSharing(printDevice, record, queueData))
                    {
                        queueCreated = false;
                        break;
                    }

                    break;
                }

                DateTime queueInstallEnd = DateTime.Now;
                status.Record("NEW ENTRY END", out queueInstallEnd);
                TimeSpan totalTime = queueInstallEnd.Subtract(queueInstallStart);
                status.Record("NEW ENTRY TOTAL", totalTime);

                if (queueCreated)
                {
                    queueData.Progress = "{0:D2}:{1:D2}.{2:D3}".FormatWith(totalTime.Minutes, totalTime.Seconds, totalTime.Milliseconds);
                    UpdateStatus("1");
                    UpdateStatus("Queue creation complete.");
                }
                else
                {
                    queueData.Progress = "ERROR";
                    UpdateStatus("1");
                    UpdateStatus("Queue creation failed.");
                }

                _threadSemaphore.Release();
            }
            catch (Win32Exception ex)
            {
                status.Record("FAILED: " + ex.Message);
                string message = new Win32Exception(ex.NativeErrorCode).Message;
                UpdateStatus("Queue creation failed: {0}".FormatWith(message));
                FireComplete();
                return;
            }
            finally
            {
                _installThreads.Remove(Thread.CurrentThread);
            }
        }