コード例 #1
0
        internal void Exercise(DirtyDeviceActivityData activityData)
        {
            for (int seed1 = 0; seed1 <= 2; seed1++)
            {
                for (int seed2 = 0; seed2 < 40; seed2++)
                {
                    string seed = $"{seed1}.{seed2}"; // HP devices only seem to respond to the following seeds but we will try them all: 1.0, 1.2, 1.3

                    try
                    {
                        _device.Snmp.Walk(seed);
                    }
                    catch (Exception x)
                    {
                        string message = $"Snmp walk failed with seed {seed}.";
                        _owner.OnUpdateStatus(this, message + "  ({x.ToString()})");
                        throw new SnmpException(message, x);
                    }
                }
            }
        }
コード例 #2
0
        public void Exercise(DirtyDeviceActivityData activityData, int jobCountGoal)
        {
            for (int jobCount = 0; jobCount < jobCountGoal; jobCount++)
            {
                var progressMessage = $"{jobCount + 1,3}/{jobCountGoal}";
                var helloBytes      = Encoding.ASCII.GetBytes($"Hello world! (print job {progressMessage})" + Environment.NewLine);

                try
                {
                    using (var tcpClient = new TcpClient(_device.Address, 9100))
                        using (var stream = tcpClient.GetStream())
                        {
                            stream.Write(helloBytes, 0, helloBytes.Length);
                        }
                }
                catch (Exception)
                {
                    _owner.OnUpdateStatus(this, $"Exception sending print job {progressMessage}");
                    throw;
                }
                Thread.Sleep(1000);
            }
        }
コード例 #3
0
        internal void Exercise(DirtyDeviceActivityData activityData)
        {
            const string AppButtonFilter = "-homescreen-button";

            var controls = _controlPanel.GetIds("div", OmniIdCollectionType.Children).Where(id => id.EndsWith(AppButtonFilter)).ToArray();

            _owner.OnUpdateStatus(this, $"Found {controls.Length} app buttons...");

            for (int controlIndex = 0; controlIndex < controls.Length; controlIndex++)
            {
                string controlSelector = "#" + controls[controlIndex];

                string innerText = _controlPanel.GetValue(controlSelector, "innerText", OmniPropertyType.Property).Trim();

                _controlPanel.ScrollToItem(controlSelector);

                if (_controlPanel.WaitForState(controlSelector, OmniElementState.Useable, TimeSpan.FromSeconds(10)))
                {
                    _owner.OnUpdateStatus(this, $"  Pressing {innerText} ({controlIndex + 1:##}/{controls.Length:##})");
                    _controlPanel.Press(controlSelector);
                }
                else
                {
                    _owner.OnUpdateStatus(this, $"  Skipping {innerText}.  App is not available currently. ({controlIndex + 1:##}/{controls.Length:##})");
                    continue;
                }
                System.Threading.Thread.Sleep(5000);

                try
                {
                    _preparationManager.Reset();
                }
                catch (Exception x)
                {
                    _owner.OnUpdateStatus(this, x.ToString());
                    _owner.OnUpdateStatus(this, $"  Pressing 'Home' button did not exit {innerText}.  Consider filing a bug report against the app.");
                    _owner.OnUpdateStatus(this, $"  Attempting to return to home screen by waiting for timeout.");
                    UnauthenticateByTimeout();
                }
            }
        }
コード例 #4
0
        internal void Exercise(DirtyDeviceActivityData activityData, AssetAttributes deviceAttributes)
        {
            WebServiceTicket webTicket;

            var callList = new[]
            {
                new
                {
                    EndPoint = "device",
                    Uri      = "urn:hp:imaging:con:service:device:DeviceService",
                    GetOrSet = "get",
                },
            }.ToList();

            if (deviceAttributes.HasFlag(AssetAttributes.Scanner))
            {
                callList = new[]
                {
                    new
                    {
                        EndPoint = "device",
                        Uri      = "urn:hp:imaging:con:service:device:DeviceService",
                        GetOrSet = "get",
                    },
                    new
                    {
                        EndPoint = "email",
                        Uri      = "urn:hp:imaging:con:service:email:EmailService",
                        GetOrSet = "get;set",
                    },
                    new
                    {
                        EndPoint = "copy",
                        Uri      = "urn:hp:imaging:con:service:copy:CopyService",
                        GetOrSet = "get;set",
                    },
                }.ToList();
            }

            foreach (var call in callList)
            {
                for (var attempt = 1; attempt <= MaxRetryCount; attempt++)
                {
                    try
                    {
                        _owner.OnUpdateStatus(this, $"  Performing web service GET.  (EndPoint: {call.EndPoint}; Uri: {call.Uri})");
                        webTicket = GetUrn(call.EndPoint, call.Uri);
                        _owner.OnUpdateStatus(this, $"    Device response was {webTicket.ToString().Length} characters.");
                    }
                    catch (Exception x)
                    {
                        _owner.OnUpdateStatus(this, $"  Could not perform web service GET.  (Device: {_device.Address}; EndPoint: {call.EndPoint}; Uri: {call.Uri}; Error: {x.Message})");
                        if (attempt >= MaxRetryCount)
                        {
                            throw;
                        }
                        _owner.OnUpdateStatus(this, $"  Will attempt {MaxRetryCount - attempt} more times.");
                        // Cannot proceed to set that which we did not successfully get.
                        continue;
                    }

                    if (call.GetOrSet.Contains("set"))
                    {
                        try
                        {
                            _owner.OnUpdateStatus(this, $"  Performing web service SET.  (EndPoint: {call.EndPoint}; Uri: {call.Uri})");
                            SetUrn(call.EndPoint, call.Uri, webTicket);
                            // If we got this far successfully, we are done.  We do not need to retry.
                            break;
                        }
                        catch (Exception x)
                        {
                            _owner.OnUpdateStatus(this, $"  Could not perform web service SET.  (Device: {_device.Address}; EndPoint: {call.EndPoint}; Uri: {call.Uri}; Error: {x.Message})");
                            if (attempt >= MaxRetryCount)
                            {
                                throw;
                            }
                            _owner.OnUpdateStatus(this, $"  Will attempt {MaxRetryCount - attempt} more times.");
                        }
                    }
                    else
                    {
                        // If we got this far successfully, we are done.  We do not need to retry.
                        break;
                    }
                }
            }
        }
コード例 #5
0
        /// <summary>
        /// Initializes the browser and attempts to login.
        /// </summary>
        /// <param name="browser">The IE Browser instance to use.</param>
        public void EwsInit(InternetExplorerDriver browser)
        {
            _owner.OnUpdateStatus(this, "Navigating to the devices EWS Homepage");
            browser.Navigate().GoToUrl(_device.Address);

            if (ElementExists(By.Id("overridelink"), browser))
            {
                _owner.OnUpdateStatus(this, "Clicking the link to get past the security warning.");
                browser.FindElement(By.Id("overridelink")).Click();
            }

            By loginLinkLocator = By.Id("EwsLogin");

            if (ElementExists(loginLinkLocator, browser))
            {
                _owner.OnUpdateStatus(this, "Clicking the EWS Login link");
                browser.FindElement(loginLinkLocator).Click();

                if (ElementExists(By.Id("PinDropDown"), browser))
                {
                    _owner.OnUpdateStatus(this, "Typing in the password");
                    browser.FindElement(By.Id("PasswordTextBox")).SendKeys(_device.AdminPassword);
                }
                else
                {
                    _owner.OnUpdateStatus(this, "Typing in the username and password.");
                    browser.FindElement(By.Id("UserNameTextBox")).SendKeys("admin");
                    browser.FindElement(By.Id("PasswordTextBox")).SendKeys(_device.AdminPassword);
                }

                _owner.OnUpdateStatus(this, "Logging into the device.");
                browser.FindElement(By.Id("signInOk")).Click();
            }
            else
            {
                throw new EwsAutomationException("No password has been set on the device.  Please set the admin password on the device.");
            }
        }
コード例 #6
0
        internal void Exercise(DirtyDeviceActivityData activityData, NetworkCredential userCredential, PluginEnvironment environment)
        {
            _activityData   = activityData;
            _userCredential = userCredential;

            string localMachineName    = NetUtil.GetFQDN();
            string fileShareServerName = $"{activityData.DigitalSend.OutputFolder.ServerHostName}.{environment.UserDnsDomain}";
            var    externalFacingProtocolSpecificPath = activityData.DigitalSend.OutputFolder.MonitorLocation;
            var    correspondingSharePath             = $@"\\{fileShareServerName}\{externalFacingProtocolSpecificPath.Replace("/", @"\")}";

            EndpointPath fileSharePath = new EndpointPath(
                DestinationType.NetworkFolder,
                fileShareServerName,
                null,
                externalFacingProtocolSpecificPath,
                correspondingSharePath);

            EndpointPath ftpPath = new EndpointPath(
                DestinationType.Ftp,
                localMachineName,
                null,
                externalFacingProtocolSpecificPath,
                correspondingSharePath);

            EndpointPath httpPath = new EndpointPath(
                DestinationType.Http,
                localMachineName,
                EndpointManager.HttpPort,
                externalFacingProtocolSpecificPath,
                correspondingSharePath);

            var pathManager = new PathManager(fileSharePath, ftpPath, httpPath);

            _endpointManager = new EndpointManager(pathManager, environment);
            _endpointManager.UpdateStatus += (s, e) => _owner.OnUpdateStatus(s, e.StatusMessage);

            // eschew "all inspectable pages are in use" exception
            foreach (var protocol in new[] { DestinationType.Ftp, DestinationType.Http, DestinationType.NetworkFolder })
            {
                for (var attempt = 1; attempt <= MaxRetryCount; attempt++)
                {
                    _owner.OnUpdateStatus(this, $"");
                    _preparationManager.InitializeDevice(true);
                    try
                    {
                        ExecuteScanToDestination(protocol);
                        // If we got this far successfully, we are done.  We do not need to retry.
                        break;
                    }
                    catch (Exception x)
                    {
                        _owner.OnUpdateStatus(this, $"  Digital send failed.  (Device: {_deviceDat.Address}; Protocol: {protocol}; Error: {x.Message})");
                        if (attempt >= MaxRetryCount)
                        {
                            throw;
                        }
                        _owner.OnUpdateStatus(this, $"  Will attempt {MaxRetryCount - attempt} more times.");
                    }
                }
            }
            _owner.OnUpdateStatus(this, string.Empty);
            _preparationManager.InitializeDevice(true);
        }