public void Initialize(PluginConfigurationData configuration, PluginEnvironment environment)
 {
     _certificateInstallerActivityData = configuration.GetMetadata <CertificateInstallerActivityData>();
     certificate_assetSelectionControl.Initialize(configuration.Assets, Framework.Assets.AssetAttributes.None);
     try
     {
         _certificateRepository = environment.PluginSettings["CertificationStore"];
     }
     catch (KeyNotFoundException)
     {
         MessageBox.Show("Certification Store path not defined. Please define the setting and try again.");
         return;
     }
     LoadUi();
 }
        public void Initialize(PluginEnvironment environment)
        {
            _certificateInstallerActivityData = new CertificateInstallerActivityData();

            try
            {
                _certificateRepository = environment.PluginSettings["CertificationStore"];
            }
            catch (KeyNotFoundException)
            {
                MessageBox.Show("Certification Store path not defined. Please define the setting and try again.");
                return;
            }

            LoadUi();
        }
Ejemplo n.º 3
0
        public PluginExecutionResult Execute(PluginExecutionData executionData)
        {
            _activityData = executionData.GetMetadata <CertificateInstallerActivityData>();

            PrintDeviceInfo printDeviceInfo = (PrintDeviceInfo)executionData.Assets.First();

            _device = DeviceConstructor.Create(printDeviceInfo);

            try
            {
                string authorization = string.Empty;

                _userAgent = GetUserAgent(_activityData.BrowserType);

                // Installs certificate on Client VM
                if (_activityData.ClientVMCA)
                {
                    ExecutionServices.SystemTrace.LogDebug($"Certificate Path { (object)_activityData.CACertificate}");
                    InstallVMCertificate(_activityData.CACertificate);
                }

                // Check for the printer availability
                if (!PingUntilTimeout(IPAddress.Parse(_device.Address), TimeSpan.FromMinutes(1)))
                {
                    string errorMessage = $"Ping failed with IP Address:{ (object)_device.Address}";
                    ExecutionServices.SystemTrace.LogDebug(errorMessage);
                    _device.Dispose();
                    return(new PluginExecutionResult(PluginResult.Failed, errorMessage));
                }

                if (!string.IsNullOrEmpty(_device.AdminPassword))
                {
                    string credentials    = $"admin:{_device.AdminPassword}";
                    byte[] plainTextBytes = System.Text.Encoding.UTF8.GetBytes(credentials);
                    authorization = "Basic " + Convert.ToBase64String(plainTextBytes);
                }

                // Enterprise Lock on device so that only one dispatcher can reserve at a time.
                // Action action = new Action(() =>
                {
                    //Installs CA certificate on the printer
                    if (_activityData.InstallPrinterCA)
                    {
                        ExecutionServices.CriticalSection.Run(new AssetLockToken(executionData.Assets.First(), new LockTimeoutData(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1))), () => InstallCertificate(authorization));
                    }

                    //Deletes CA certificate from the printer
                    if (_activityData.DeletePrinterCA)
                    {
                        ExecutionServices.CriticalSection.Run(new AssetLockToken(executionData.Assets.First(), new LockTimeoutData(TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1))), () => DeleteCertificate(authorization, _device.Address));
                    }
                }
            }
            catch (Exception exception)
            {
                var failureMessage = $"Activity failed on device {_device.Address} with exception {exception.Message}";
                _device.Dispose();
                return(new PluginExecutionResult(PluginResult.Failed, failureMessage));
            }

            _device.Dispose();
            return(new PluginExecutionResult(PluginResult.Passed));
        }