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); }
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); }
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); }
private void SetupSharingAction(InstallerPrintDevice printDevice, StatusRecord record) { try { printDevice.EnableSharedQueue(); } catch (Win32Exception ex) { RetryOnError(record, ex); throw; } }
private void SetupClientRenderingAction(InstallerPrintDevice printDevice, StatusRecord record) { try { printDevice.EnableClientRendering(); } catch (Win32Exception ex) { RetryOnError(record, ex); throw; } }
private void InstallQueueAction(InstallerPrintDevice printDevice, StatusRecord record) { try { printDevice.CreatePrintQueue(_installationTimeout); } catch (Win32Exception ex) { RetryOnError(record, ex); throw; } }
private void SetupPortAction(InstallerPrintDevice printDevice, StatusRecord record) { try { printDevice.Port.CreatePort(); } catch (Win32Exception ex) { RetryOnError(record, ex); throw; } }
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); }
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); } }