Beispiel #1
0
        /// <summary>
        /// upgrades the print queue with the new driver
        /// </summary>
        /// <param name="pqmTask">contains the info about the driver to be upgraded to</param>
        private void UpgradePrintQueue(PrintQueueManagementTask pqmTask, SettingsDictionary pluginSettings)
        {
            var upgradeDriverInfo = (PrintDriverInfo)pqmTask.TargetObject;

            string printDriverPath = Path.Combine(pluginSettings["PrintDriverServer"], Environment.Is64BitOperatingSystem ? upgradeDriverInfo.InfX64 : upgradeDriverInfo.InfX86);

            StringBuilder upgradeDriverArgs = new StringBuilder();

            upgradeDriverArgs.Append(
                $"/ia /v \"Type 3 - User Mode\" /m \"{_localPrintQueueInfo.PrintDriver.DriverName}\"");
            upgradeDriverArgs.Append($" /n \"{_defaultPrintQueue.FullName}\"");
            upgradeDriverArgs.Append($" /f \"{printDriverPath}\"");
            upgradeDriverArgs.Append($" /l \"{Path.GetDirectoryName(printDriverPath)}\"");
            var action = new Action(() =>
            {
                var result = ProcessUtil.Execute("rundll32", $"printui.dll,PrintUIEntry { (object)upgradeDriverArgs.ToString()}");
                if (result.ExitCode != 0)
                {
                    pqmTask.Status = Status.Failed;
                }

                pqmTask.Status = Status.Passed;
                ExecutionServices.SystemTrace.LogInfo(
                    $"Upgraded the driver for the device: {_printQueueInfo.AssociatedAssetId}");
                device_textBox.Text = _printQueueInfo.AssociatedAssetId + @", " +
                                      GetDriverInfo(_defaultPrintQueue.FullName);
            });
            var token = new LocalLockToken(_defaultPrintQueue.FullName, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));

            ExecutionServices.CriticalSection.Run(token, action);
        }
Beispiel #2
0
        /// <summary>
        /// Configures the print preferences of the print queue
        /// </summary>
        /// <param name="pqmTask">contains the info about print queue</param>
        private void ConfigureQueueForm(PrintQueueManagementTask pqmTask)
        {
            string queueName = _defaultPrintQueue.FullName;
            var    action    = new Action(() =>
            {
                PrintPreferences preferences =
                    new PrintPreferences(TopCat.TestApi.GUIAutomation.Enums.UIAFramework.ManagedUIA)
                {
                    DriverModel = _localPrintQueueInfo.PrintDriver.DriverName
                };

                ProcessUtil.Execute("cmd.exe", $"/c rundll32 printui.dll,PrintUIEntry /p /n \"{queueName}\"", TimeSpan.FromSeconds(shortTimeout));
                preferences.PrintPreferencesWindow.WaitForAvailable(shortTimeout);
                preferences.DeviceSettingsTabItem.Select(shortTimeout);
                preferences.InstallableOptionTreeItem.Select(shortTimeout);

                if (preferences.DuplexUnitfor2STreeItem.IsAvailable())
                {
                    preferences.DuplexUnitfor2STreeItem.Select(shortTimeout);
                }
                else
                {
                    preferences.DuplexUnitfor2SNTreeItem.Select(shortTimeout);
                }

                preferences.SelectListItem(pqmTask.Preference.Duplexer);
                preferences.OKButton1Button.Click(shortTimeout);

                ProcessUtil.Execute("cmd.exe", $"/c rundll32 printui.dll,PrintUIEntry /e /n \"{queueName}\"", TimeSpan.FromSeconds(shortTimeout));

                preferences.PrintPreferencesWindow.WaitForAvailable(shortTimeout);
                preferences.PrintingShortcutTabItem.Select(shortTimeout);


                preferences.SelectListItem(pqmTask.Preference.PaperSize);
                Thread.Sleep(_humanTimespan);
                preferences.SelectListItem(pqmTask.Preference.InputTray);
                Thread.Sleep(_humanTimespan);
                preferences.SelectListItem(pqmTask.Preference.PaperType);
                Thread.Sleep(_humanTimespan);
                preferences.SelectListItem(pqmTask.Preference.Orientation);
                Thread.Sleep(_humanTimespan);
                preferences.SelectListItem(pqmTask.Preference.DuplexValue);

                preferences.AdvancedTabItem.Select(shortTimeout);

                preferences.CopyCountmsctlsSpinner.SetValue(pqmTask.Preference.Copies);

                preferences.OKButton1Button.Click(shortTimeout);

                pqmTask.Status = Status.Passed;
            });

            //var tempScriptDirectory = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "TopCatScript"));
            //File.WriteAllBytes(Path.Combine(tempScriptDirectory.FullName, "CustomPrintSettings.tcx"),
            //    ScriptResource.CustomPrintSettings);
            //File.WriteAllBytes(Path.Combine(tempScriptDirectory.FullName, "printPreferences.tcc"),
            //    ScriptResource.printPreferences);

            //_configureScript = new TopCatScript
            //(
            //    Path.Combine(tempScriptDirectory.FullName, "CustomPrintSettings.tcx"),
            //    "CustomPrintSettings"
            //);

            //_configureScript.Properties.Add
            //(
            //    "QueueName",
            //    _defaultPrintQueue.FullName
            //);
            //_configureScript.Properties.Add
            //(
            //    "Copies",
            //    pqmTask.Preference.Copies.ToString(System.Globalization.CultureInfo.InvariantCulture)
            //);
            //_configureScript.Properties.Add
            //(
            //    "PaperSize",
            //    pqmTask.Preference.PaperSize
            //);
            //_configureScript.Properties.Add
            //(
            //    "PaperSource",
            //    pqmTask.Preference.InputTray
            //);
            //_configureScript.Properties.Add
            //(
            //    "Orientation",
            //    pqmTask.Preference.Orientation
            //);
            //_configureScript.Properties.Add
            //(
            //    "DuplexValue",
            //    pqmTask.Preference.DuplexValue
            //);
            //_configureScript.Properties.Add
            //(
            //    "Duplexer",
            //    pqmTask.Preference.Duplexer
            //);
            //_configureScript.Properties.Add
            //(
            //    "DriverModel",
            //    _localPrintQueueInfo.PrintDriver.DriverName
            //);
            //TopCatExecutionController tcExecutionController = new TopCatExecutionController(_configureScript);
            //tcExecutionController.InstallPrerequisites(GlobalSettings.Items["TopCatSetup"]);
            //tcExecutionController.ExecuteTopCatTest();

            //string resultFile = tcExecutionController.GetResultFilePath(GlobalSettings.Items["DomainAdminUserName"]);
            //if (!string.IsNullOrEmpty(resultFile))
            //{
            //    XDocument resultDoc = XDocument.Load(resultFile);
            //    var successTests = resultDoc.Descendants("SuccessfulTests").First().Descendants("test");
            //    pqmTask.Status = successTests.Any() ? Status.Passed : Status.Failed;
            //}
            //else
            //{
            //    pqmTask.Status = Status.Failed;
            //}


            var token = new LocalLockToken(_defaultPrintQueue.FullName, TimeSpan.FromMinutes(5), TimeSpan.FromMinutes(5));

            ExecutionServices.CriticalSection.Run(token, action);
        }