Esempio n. 1
0
 private void RemoveConfigFiles(InstallStatusData status)
 {
     foreach (string file in Directory.GetFiles(DriverController.SystemVersion3DriverDirectory, "*.cfm"))
     {
         try
         {
             string message = "Deleting {0}".FormatWith(file);
             TraceFactory.Logger.Debug(message);
             UpdateStatus(message);
             File.Delete(file);
         }
         catch (ArgumentException ex)
         {
             LogDeleteError(status, file, ex);
         }
         catch (IOException ex)
         {
             LogDeleteError(status, file, ex);
         }
         catch (UnauthorizedAccessException ex)
         {
             LogDeleteError(status, file, ex);
         }
         catch (NotSupportedException ex)
         {
             LogDeleteError(status, file, ex);
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Upgrades the driver.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="queueName">Name of the queue.</param>
        public void UpgradeDriver(PrintDeviceDriver driver, string queueName)
        {
            if (driver == null)
            {
                throw new ArgumentNullException("driver");
            }

            DateTime start = DateTime.Now;
            DateTime end   = DateTime.Now;

            InstallStatusData status = _installStatus.Create(queueName);

            lock (_driverLock)
            {
                UpdateStatus("Upgrading print driver... " + driver.Name);
                status.Record("DRIVER UPGRADE START", out start);

                // Upgrade the driver, but do not check to see if the driver is installed,
                // this has already been done.
                DriverInstaller.Upgrade(driver.CreateDetail(), queueName);

                status.Record("DRIVER UPGRADE END", out end);
                status.Record("DRIVER UPGRADE TOTAL", end.Subtract(start));
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Installs the designated driver.
        /// </summary>
        /// <param name="driver">The driver.</param>
        /// <param name="forceInstall">if set to <c>true</c> then an install is forced.</param>
        public void InstallDriver(PrintDeviceDriver driver, bool forceInstall = false)
        {
            if (driver == null)
            {
                throw new ArgumentNullException("driver");
            }

            DateTime start = DateTime.Now;
            DateTime end   = DateTime.Now;

            InstallStatusData status = _installStatus.Create(driver.Name);

            lock (_driverLock)
            {
                UpdateStatus("Installing print driver... " + driver.Name);
                status.Record("DRIVER INSTALL START", out start);
                DriverInstaller.Install(driver.CreateDetail(), forceInstall);
                status.Record("DRIVER INSTALL END", out end);
                _installedDrivers.Add(driver.Name);
                status.Record("DRIVER INSTALL TOTAL", end.Subtract(start));
            }
        }
Esempio n. 4
0
 private static void LogDeleteError(InstallStatusData status, string fileName, Exception ex)
 {
     TraceFactory.Logger.Error("File delete failed", ex);
     status.Record("ERR: DELETE FAILED: {0}".FormatWith(Path.GetFileName(fileName)));
 }
Esempio n. 5
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);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// When a .cfm file is applied to a driver installation, the settings propagate to the .cfg file.  So, even when the .cfm file
        /// is removed from the driver install directory, the settings persist.  To complicate things further, sometimes additional .cfg
        /// files are created which have a higher usage priority during queue creation.  For example, if the default config file is hpcpu140.cfg,
        /// in the driver installation directory there may also be hpcpu140_p6.cfg.  The _p6 file has priority over the original .cfg file
        /// during queue creation.  Therefore, when restoring the original default .cfg file, it is necessary to remove all files that start with
        /// "hpcpu140".
        /// The intent of this method is to copy the original .cfg file from the driver location chosen by the user into the driver installation
        /// directory.  We can't just do a File.Copy here because there may be other files related to the .cfg filename that need to be removed.
        /// So the restore is done in 2 phases - delete and copy.
        /// </summary>
        /// <param name="driver">The driver properties</param>
        /// <param name="status">The install status data</param>
        private static void RestoreDriverDefaults(PrintDeviceDriver driver, InstallStatusData status)
        {
            string defaultConfigFile = GetDefaultConfigFile(driver);

            //Remove all cfg files that match the default .cfg file name.
            foreach (string file in Directory.GetFiles(DriverController.SystemVersion3DriverDirectory, "{0}*.cfg".FormatWith(defaultConfigFile)))
            {
                try
                {
                    TraceFactory.Logger.Debug("Deleting {0}".FormatWith(file));
                    File.Delete(file);
                }
                catch (ArgumentException ex)
                {
                    LogDeleteError(status, file, ex);
                }
                catch (IOException ex)
                {
                    LogDeleteError(status, file, ex);
                }
                catch (UnauthorizedAccessException ex)
                {
                    LogDeleteError(status, file, ex);
                }
                catch (NotSupportedException ex)
                {
                    LogDeleteError(status, file, ex);
                }
            }

            // Copy the original .cfg file over to the driver installation location
            string source      = @"{0}\{1}.cfg".FormatWith(driver.Location, defaultConfigFile);
            string destination = @"{0}\{1}.cfg".FormatWith(DriverController.SystemVersion3DriverDirectory, defaultConfigFile);

            if (!File.Exists(destination))
            {
                try
                {
                    TraceFactory.Logger.Debug("Source: {0}".FormatWith(source));
                    TraceFactory.Logger.Debug("Destination: {0}".FormatWith(destination));
                    File.Copy(source, destination, true);
                }
                catch (ArgumentException ex)
                {
                    LogFileCopyError("CFG", ex);
                    throw;
                }
                catch (IOException ex)
                {
                    LogFileCopyError("CFG", ex);
                    throw;
                }
                catch (UnauthorizedAccessException ex)
                {
                    LogFileCopyError("CFG", ex);
                    throw;
                }
                catch (NotSupportedException ex)
                {
                    LogFileCopyError("CFG", ex);
                    throw;
                }
            }
        }
Esempio n. 7
0
 private static void UnableToCopyError(InstallStatusData status, Exception ex)
 {
     status.Record("Unable to copy CFM file");
     TraceFactory.Logger.Error("Unable to copy CFM file", ex);
 }
Esempio n. 8
0
 public StatusRecord(InstallStatusData status)
 {
     _status = status;
 }