Example #1
0
        private static BrowserAgent GetUserAgent(string userAgent)
        {
            BrowserAgent agent = BrowserAgent.IE;

            if (userAgent == "IE7" || userAgent == "IE8" || userAgent == "IE9")
            {
                agent = BrowserAgent.IE;
            }
            else if (userAgent == "Firefox")
            {
                agent = BrowserAgent.Firefox;
            }
            else if (userAgent == "Chrome")
            {
                agent = BrowserAgent.Chrome;
            }
            else if (userAgent == "Opera")
            {
                agent = BrowserAgent.Opera;
            }
            else if (userAgent == "Safari")
            {
                agent = BrowserAgent.Safari;
            }
            return(agent);
        }
Example #2
0
        private static void SetUserAgent(HttpWebRequest request, BrowserAgent agent)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            request.UserAgent = _userAgents[agent];
        }
Example #3
0
 /// <summary>
 /// Executes the specified HTTP GET request as the specified browser agent.
 /// </summary>
 /// <param name="request">The <see cref="HttpWebRequest" />.</param>
 /// <param name="agent">The <see cref="BrowserAgent" />.</param>
 /// <returns>An <see cref="HttpWebResult" /> object representing the result of the request.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="request" /> is null.</exception>
 public static HttpWebResult Get(HttpWebRequest request, BrowserAgent agent)
 {
     SetUserAgent(request, agent);
     return(Get(request));
 }
Example #4
0
        /// <summary>
        /// Uploads a file using an HTTP POST request as the specified browser agent.
        /// </summary>
        /// <param name="request">The <see cref="HttpWebRequest" />.</param>
        /// <param name="file">The file to upload.</param>
        /// <param name="paramName">The parameter name.</param>
        /// <param name="formData">The form data.</param>
        /// <param name="agent">The <see cref="BrowserAgent" />.</param>
        /// <returns>An <see cref="HttpWebResult" /> object representing the result of the request.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="request" /> is null.</exception>
        public static HttpWebResult UploadFile(HttpWebRequest request, string file, string paramName, NameValueCollection formData, BrowserAgent agent)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            request.Method = "POST";
            request.ServicePoint.Expect100Continue = false;
            SetUserAgent(request, agent);
            SetFileUploadData(request, file, paramName, formData);
            return(Execute(request));
        }
Example #5
0
 /// <summary>
 /// Executes the specified HTTP POST request as the specified browser agent.
 /// </summary>
 /// <param name="request">The <see cref="HttpWebRequest" />.</param>
 /// <param name="data">The data payload for the POST request.</param>
 /// <param name="agent">The <see cref="BrowserAgent" />.</param>
 /// <returns>An <see cref="HttpWebResult" /> object representing the result of the request.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="request" /> is null.</exception>
 public static HttpWebResult Post(HttpWebRequest request, byte[] data, BrowserAgent agent)
 {
     SetUserAgent(request, agent);
     return(Post(request, data));
 }
Example #6
0
 /// <summary>
 /// Executes the specified HTTP PUT request as the specified browser agent.
 /// </summary>
 /// <param name="request">The <see cref="HttpWebRequest" />.</param>
 /// <param name="data">The data payload for the PUT request.</param>
 /// <param name="agent">The <see cref="BrowserAgent" />.</param>
 /// <returns>An <see cref="HttpWebResult" /> object representing the result of the request.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="request" /> is null.</exception>
 public static HttpWebResult Put(HttpWebRequest request, string data, BrowserAgent agent)
 {
     SetUserAgent(request, agent);
     return(Put(request, data));
 }
Example #7
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));
        }