/// <summary> /// Initializes a new instance of the <see cref="InstallerPrintDevice" /> class. /// </summary> /// <param name="driver">The driver.</param> /// <param name="port">The port.</param> public InstallerPrintDevice(PrintDeviceDriver driver, TcpIPPortInstaller port) { Driver = driver; Port = port; QueueName = "{0} ({1})".FormatWith(driver.Name, port.PortName); }
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); } }