Ejemplo n.º 1
0
        private void InitializeDevice()
        {
            try
            {
                OnUpdateStatus(this, "Initializing device.");
                _device             = (JediOmniDevice)DeviceConstructor.Create(_deviceInfo);
                _preparationManager = new JediOmniPreparationManager(_device);

                _digitalSendExerciser = new DigitalSendExerciser(this, _device, _preparationManager);
                _ewsExerciser         = new EwsExerciserViaSeleniumWebDriver(this, _device);
                _printExerciser       = new PrintExerciser(this, _device);
                _snmpExerciser        = new SnmpExerciser(this, _device);
                _uiExerciser          = new UIExerciser(this, _device, _preparationManager);
                _webServicesExerciser = new WebServicesExerciser(this, _device);

                _preparationManager.InitializeDevice(true);
            }
            catch (Exception ex)
            {
                OnUpdateStatus(this, ex.ToString());
                OnUpdateStatus(this, "Cleaning up.");

                _device?.Dispose();

                // Log the error and re-throw.
                ExecutionServices.SystemTrace.LogError(ex);
                throw;
            }
        }
        private void PrepareDevice()
        {
            _preparationManager.InitializeDevice(_initMethod != InitiationMethod.DoNotSignIn);

            OnHomeScreen      = true;
            IsUnAuthenticated = true;
            IsAuthenticated   = false;
        }
Ejemplo n.º 3
0
        //public static void PUTCDM(string url)
        //{
        //    string final = $@"https://{url}/hp/network/ioConfig/v1/networkInterfaces/wired1/snmpv1v2Config";
        //    string jsonContent = @"{""snmpv1v2Enabled"": ""true"",""accessOption"": ""readWrite"",""readOnlyPublicAllowed"": ""true"",""readOnlyCommunityNameSet"": ""false"",""writeOnlyCommunitryNameSet"": ""false""}";
        //    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(final);
        //    request.Method = "PUT";
        //    request.ContentType = "access-control-allow-headers";
        //    request.Proxy = null;
        //    request.Credentials = new NetworkCredential("admin", "!QAZ2wsx");

        //    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        //    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
        //    UTF8Encoding encoding = new System.Text.UTF8Encoding();
        //    Byte[] byteArray = encoding.GetBytes(jsonContent);

        //    request.ContentLength = byteArray.Length;
        //    request.ContentType = @"application/json";

        //    using (Stream dataStream = request.GetRequestStream())
        //    {
        //        dataStream.Write(byteArray, 0, byteArray.Length);
        //    }
        //    long length = 0;
        //    try
        //    {
        //        using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
        //        {
        //            Stream receiveStream = response.GetResponseStream();
        //            length = response.ContentLength;
        //            Console.WriteLine(response.StatusCode);

        //        }
        //    }
        //    catch (WebException ex)
        //    {
        //        throw ex;
        //        // Log exception and throw as for GET example above
        //    }
        //}
        #endregion


        private PluginExecutionResult UpgradeFirmware(IDeviceInfo deviceInfo)
        {
            TimeSpan              waitTimeSpan = TimeSpan.FromSeconds(4);
            Pacekeeper            pacekeeper   = new Pacekeeper(TimeSpan.FromSeconds(7));
            PluginExecutionResult result       = new PluginExecutionResult(PluginResult.Passed);

            IDevice device     = DeviceConstructor.Create(deviceInfo);
            var     omniDevice = device as JediOmniDevice;

            _preparationManager = new JediOmniPreparationManager(omniDevice);

            if (omniDevice == null)
            {
                result = new PluginExecutionResult(PluginResult.Failed, "This plugin supports only Jedi Omni devices");
                throw new DeviceWorkflowException("This plugin supports only Jedi Omni devices");
            }

            device_textBox.InvokeIfRequired(x => x.Text          = device.Address);
            currentRevision_textBox.InvokeIfRequired(x => x.Text = device.GetDeviceInfo().FirmwareRevision);
            _activityExecutionDetailLog = new ActivityExecutionDetailLog(_executionData, "FirmwareFlashMethod", "USB");
            ExecutionServices.DataLogger.Submit(_activityExecutionDetailLog);
            //_activityExecutionDetailLog = new ActivityExecutionDetailLog(_executionData, "FirmwareFlashUpgrade", _activityData.IsDowngrade ? "false" : "true");
            //ExecutionServices.DataLogger.Submit(_activityExecutionDetailLog);

            UpdateProgressBar(0);

            _preparationManager.InitializeDevice(true);
            omniDevice.ControlPanel.ScrollPressWait("#hpid-supportTools-homescreen-button",
                                                    "#hpid-supporttools-app-screen", waitTimeSpan);
            pacekeeper.Pause();



            #region handle maintanance popup
            JediOmniPopupManager popupManager = new JediOmniPopupManager(omniDevice);
            bool maintananceWindowNotSolved   = false;
            int  maintananceretries           = 0;
            while (!maintananceWindowNotSolved && maintananceretries < 2)
            {
                if (omniDevice.ControlPanel.WaitForAvailable("#hpid-tree-node-listitem-maintenance", TimeSpan.FromSeconds(5)))
                {
                    Thread.Sleep(5);

                    omniDevice.ControlPanel.PressWait("#hpid-tree-node-listitem-maintenance", "#hpid-settings-app-menu-panel", waitTimeSpan);
                }

                if (omniDevice.ControlPanel.CheckState("#hpid-maintenancemode-failed-feedback-popup", OmniElementState.VisibleCompletely)) // TimeSpan.FromSeconds(4)))
                {
                    popupManager.HandleMaintananceUnavailablePopUp();
                    maintananceWindowNotSolved = true;
                }

                maintananceretries++;
            }

            if (maintananceWindowNotSolved)
            {
                if (omniDevice.ControlPanel.WaitForAvailable("#hpid-tree-node-listitem-maintenance", TimeSpan.FromSeconds(5)))
                {
                    omniDevice.ControlPanel.PressWait("#hpid-tree-node-listitem-maintenance", "#hpid-settings-app-menu-panel", waitTimeSpan);
                }
            }
            #endregion

            if (omniDevice.ControlPanel.WaitForState("#hpid-tree-node-listitem-usbfirmwareupgrade", OmniElementState.Exists, waitTimeSpan))
            {
                omniDevice.ControlPanel.ScrollPressWait("#hpid-tree-node-listitem-usbfirmwareupgrade", "#hpid-usb-firmware-upgrade-screen", waitTimeSpan);
            }
            //var items = omniDevice.ControlPanel.GetIds("div", OmniIdCollectionType.Children);
            //foreach (var item in items)
            //{
            //    ExecutionServices.SystemTrace.LogInfo(item.ToString());
            //}

            pacekeeper.Pause();
            if (omniDevice.ControlPanel.WaitForAvailable("#hpid-firmware-bundles-list", waitTimeSpan))
            {
                //Verify USB firmware?--Lets find out
                if (omniDevice.ControlPanel.CheckState(".hp-listitem-text:contains(_)", OmniElementState.Exists))
                {
                    omniDevice.ControlPanel.ScrollPress(".hp-listitem-text:contains(_)");
                }
                else
                {
                    result = new PluginExecutionResult(PluginResult.Skipped, "Specified firmware bundle not found on USB media");
                    // throw new DeviceWorkflowException("Specified firmware bundle not found on USB media");
                }

                if (omniDevice.ControlPanel.WaitForState("#hpid-setting-install-button", OmniElementState.Enabled,
                                                         waitTimeSpan))
                {
                    omniDevice.ControlPanel.Press("#hpid-setting-install-button");
                    pacekeeper.Pause();
                }
                else
                {
                    result = new PluginExecutionResult(PluginResult.Failed, "Unable to install firmware");
                    //throw new DeviceWorkflowException("Unable to install firmware");
                }

                bool   popUpFound    = false;
                var    popUpWaitTime = DateTime.Now + TimeSpan.FromSeconds(6);
                string buttonPress   = @"";
                while (DateTime.Now < popUpWaitTime)
                {
                    popUpFound = omniDevice.ControlPanel.WaitForState("#hpid-reinstall-button", OmniElementState.Enabled, TimeSpan.FromSeconds(.5));
                    if (popUpFound)
                    {
                        buttonPress = "#hpid-reinstall-button";
                        break;
                    }
                    popUpFound = omniDevice.ControlPanel.WaitForAvailable("#hpid-upgrade-message", TimeSpan.FromSeconds(.5));
                    if (popUpFound)
                    {
                        buttonPress = "#hpid-upgrade-button";
                        break;
                    }
                    popUpFound = omniDevice.ControlPanel.WaitForState("#hpid-rollback-button", OmniElementState.Enabled, TimeSpan.FromSeconds(.5));
                    if (popUpFound)
                    {
                        buttonPress = "#hpid-rollback-button";
                        break;
                    }
                }
                switch (buttonPress)
                {
                case "#hpid-reinstall-button":
                    return(new PluginExecutionResult(PluginResult.Skipped, "This version of firmware is already installed."));

                    //omniDevice.ControlPanel.Press("#hpid-reinstall-button");
                    //pacekeeper.Pause();
                    break;

                case "#hpid-upgrade-button":
                    if (omniDevice.ControlPanel.WaitForAvailable("#hpid-upgrade-button", waitTimeSpan))
                    {
                        omniDevice.ControlPanel.Press("#hpid-upgrade-button");
                        pacekeeper.Pause();
                    }
                    break;

                case "#hpid-rollback-button":
                    result = new PluginExecutionResult(PluginResult.Skipped, "Firmware rollback not officially supported, please check that you have the right firmware");
                    return(result);

                    break;

                default:
                    result = new PluginExecutionResult(PluginResult.Failed, "Failed to find upgrade button to press");
                    return(result);
                }


                _performanceLogger.RecordEvent(DeviceWorkflowMarker.FirmwareUpdateBegin);
                UpdateProgressBar(20);
                while (omniDevice.ControlPanel.WaitForState("#hpid-firmware-install-progress-popup", OmniElementState.VisibleCompletely, waitTimeSpan))
                {
                    //do nothing
                    Application.DoEvents();

                    //let's not spam the device with check messages
                    Thread.Sleep(waitTimeSpan);
                }
                if (omniDevice.ControlPanel.WaitForAvailable("#hpid-usbfirmwareupgrade-error-msg-popup",
                                                             waitTimeSpan))
                {
                    var errorMessage = omniDevice.ControlPanel.GetValue(".hp-popup-content", "textContent",
                                                                        OmniPropertyType.Property);
                    omniDevice.ControlPanel.Press("#hpid-usbfirmwareupgrade-error-popup-button-ok");
                    result = new PluginExecutionResult(PluginResult.Failed, errorMessage);
                    throw new DeviceWorkflowException(errorMessage);
                }
                //_performanceLogger.RecordEvent(DeviceWorkflowMarker.FirmwareUpdateEnd);
                UpdateProgressBar(100);
            }
            else
            {
                var upgradeMessage = omniDevice.ControlPanel.GetValue("#hpid-usb-firmware-upgrade-message", "innerText",
                                                                      OmniPropertyType.Property);
                result = new PluginExecutionResult(PluginResult.Failed, upgradeMessage);
//                throw new DeviceWorkflowException(upgradeMessage);
            }

            return(result);
        }
Ejemplo n.º 4
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);
        }