Exemple #1
0
        private string CreateDeviceList(PrintDeviceInfo deviceInfo)
        {
            string activityUrn        = "urn:hp:imaging:con:service:systemconfiguration:SystemConfigurationService";
            string endpoint           = "systemconfiguration";
            string deviceListFileName = string.Empty;

            var jediDevice = new JediDevice(deviceInfo.Address, deviceInfo.AdminPassword);

            var systemConfigurationTicket = jediDevice.WebServices.GetDeviceTicket(endpoint, activityUrn);

            var deviceListDoc = XDocument.Parse(Properties.Resources.DeviceList);

            deviceListDoc.Element("DeviceList")?.Element("Name")?.SetValue($"DL#{DateTime.Now:HHmmdd}");

            var deviceGuid    = Guid.NewGuid();
            var deviceElement = deviceListDoc.Element("DeviceList")?.Element("Devices")?.Elements("Device")
                                .FirstOrDefault();

            if (deviceElement != null)
            {
                deviceElement.Attribute("guid")?.SetValue(deviceGuid);
                deviceElement.Attribute("deviceId")?
                .SetValue(
                    $"{systemConfigurationTicket.FindElement("MakeAndModel").Value}#{systemConfigurationTicket.FindElement("SerialNumber").Value}");
                deviceElement.Attribute("ipAddress")?.SetValue(deviceInfo.Address);

                //we need to enter hashed password here, so let's do that later
                string hashedPassword = EncryptStringByAes(deviceInfo.AdminPassword, SaltString, BoundaryAeshk);
                deviceElement.Element("Password")?.SetValue($"{hashedPassword}");
                deviceElement.Element("Model")?.SetValue(systemConfigurationTicket.FindElement("MakeAndModel").Value);

                deviceElement.Element("Hostname")?.SetValue(HostName(jediDevice));
                deviceElement.Element("FactoryDefaultHostname")?.SetValue(HostName(jediDevice));

                deviceElement.Element("MacAddress")?.SetValue(MacId(jediDevice));
                deviceElement.Element("FwVersion")?.SetValue(jediDevice.GetDeviceInfo().FirmwareRevision);
                var      fwDateTimeString = jediDevice.GetDeviceInfo().FirmwareDateCode;
                string   format           = "yyyyMMdd";
                DateTime fwDateTime       = DateTime.ParseExact(fwDateTimeString, format, CultureInfo.InvariantCulture);
                deviceElement.Element("FwDate")?.SetValue(fwDateTime.ToString("s"));
                deviceElement.Element("Ram")?.SetValue(systemConfigurationTicket.FindElement("MemoryInstalled").Value);
                deviceElement.Element("SerialNumber")?.SetValue(systemConfigurationTicket.FindElement("SerialNumber").Value);
            }

            string scheduledTaskFolder = $@"\\{_serverInfo.Address}\c$\Program Files (x86)\HP\Embedded Capture Installer\scheduledTaskFiles";

            scheduledTaskFolder = Path.Combine(scheduledTaskFolder, _sessionId);
            UserImpersonator.Execute(() => deviceListFileName = CreateRemoteXmlFile(scheduledTaskFolder, "deviceList.xml", deviceListDoc), new NetworkCredential(_credential.UserName, _credential.Password, _credential.Domain));

            return(deviceListFileName);
        }
Exemple #2
0
        public void WaitForReady()
        {
            TimeSpan waitBetweenChecks = TimeSpan.FromSeconds(5);

            OnUpdateStatus("Waiting for device to come to ready...");

            PowerState[] rejectedPowerStates = new PowerState[] { PowerState.Off, PowerState.None };
            OnUpdateStatus($"  Waiting for device to return a responsive power state...");
            int  powerCheckCount = 0;
            bool success         =
                Wait.ForTrue(
                    () =>
            {
                var state = _device.PowerManagement.GetPowerState();
                OnUpdateStatus($"    Device Power State: {state}");
                bool ok = !rejectedPowerStates.Contains(state);
                if (ok)
                {
                    ++powerCheckCount;
                }
                return(ok);
            }
                    , TimeSpan.FromSeconds(240)
                    , waitBetweenChecks);

            if (!success)
            {
                throw new DeviceInvalidOperationException($"Device did not come to an acceptable power state. ({_device.Address})");
            }

            DeviceStatus[] acceptedDeviceStatus = new DeviceStatus[] { DeviceStatus.Running, DeviceStatus.Warning };
            OnUpdateStatus($"  Waiting for device status reflecting readiness...");
            success =
                Wait.ForTrue(
                    () =>
            {
                var state = _device.GetDeviceStatus();
                OnUpdateStatus($"    Device Status: {state}");
                return(acceptedDeviceStatus.Contains(state));
            }
                    , TimeSpan.FromSeconds(240)
                    , waitBetweenChecks);

            if (!success)
            {
                throw new DeviceInvalidOperationException($"Device did not return an acceptable status. ({_device.Address})");
            }

            OnUpdateStatus($"  Waiting for device web services and OXP services to come online...");
            const int     MaxCreateCreateDeviceAttempts = 10;
            int           createDeviceAttempts          = 0;
            const int     ConsecutiveSuccessfulDeviceInfoCallsRequired = 2;
            int           consecutiveSuccessfulDeviceInfoCalls         = 0;
            StringBuilder statusMessages = new StringBuilder();

            do
            {
                JediDevice tempDevice = null;
                try
                {
                    using (tempDevice = (JediDevice)DeviceConstructor.Create(_deviceInfo))
                    {
                        var deviceInfo = tempDevice.GetDeviceInfo();
                        if (++consecutiveSuccessfulDeviceInfoCalls >= ConsecutiveSuccessfulDeviceInfoCallsRequired)
                        {
                            string message = $"Device is ready. (FirmwareRevision {deviceInfo.FirmwareRevision}; FirmwareDateCode: {deviceInfo.FirmwareDateCode})";
                            OnUpdateStatus($"    {message}");
                            break;
                        }
                        else
                        {
                            string message = $"Device is responding. (ModelName {deviceInfo.ModelName}; ModelNumber: {deviceInfo.ModelNumber}; SerialNumber: {deviceInfo.SerialNumber})";
                            OnUpdateStatus($"    {message}");
                            statusMessages.AppendLine(message);
                            waitBetweenChecks = TimeSpan.FromSeconds(3);
                        }
                    }
                }
                catch (InvalidCastException castX)
                {
                    // Might encounter exception: Unable to cast object of type 'HP.DeviceAutomation.Phoenix.PhoenixDevice' to type 'HP.DeviceAutomation.Jedi.JediDevice'.
                    // Device is still initializing operate a different web service which looks like a Phoenix device.
                    OnUpdateStatus($"    Device is still initializing and hosting a rudimentary EWS landing page on a Phoenix-y web server. ({castX.Message})");
                    statusMessages.AppendLine(castX.ToString());
                }
                catch (DeviceCommunicationException comX)
                {
                    // HP.DeviceAutomation.DeviceCommunicationException: OXP UI Configuration service could not be found at 15.86.229.141
                    // HP.DeviceAutomation.DeviceCommunicationException: OXP UI Configuration service at 15.86.229.141 did not respond.
                    OnUpdateStatus($"    Device OXP services not yet ready. ({comX.Message})");
                    statusMessages.AppendLine(comX.ToString());
                }
                catch (Exception x)
                {
                    OnUpdateStatus($"    {x.Message}");
                    statusMessages.AppendLine(x.ToString());
                }

                Thread.Sleep(waitBetweenChecks);
            } while (++createDeviceAttempts <= MaxCreateCreateDeviceAttempts);

            if (createDeviceAttempts >= MaxCreateCreateDeviceAttempts)
            {
                OnUpdateStatus(statusMessages.ToString());
                throw new DeviceInvalidOperationException($"Device web services and/or OXP services did not respond as expected after {MaxCreateCreateDeviceAttempts} attempts.");
            }
        }
Exemple #3
0
        /// <summary>
        /// Uses Jedi Firmware Utility to validate we have a well contructed firmware file that is valid for a specified device
        /// </summary>
        /// <param name="assetId"></param>
        /// <returns></returns>
        public PluginExecutionResult ValidateFirmwareBundles(string assetId, string password, string address)
        {
            //if (!_activityData.ValidateFWBundles)
            //{
            //    return new PluginExecutionResult(PluginResult.Passed);
            //}

            string[] separator = { Environment.NewLine };
            UpdateStatus("Validating Firmware bundle for the selected asset");
            //extract the file;
            var tempDumpDirectory   = Directory.CreateDirectory(Path.Combine(Path.GetTempPath(), "Dump"));
            var dumpUtilityFileName = Path.Combine(tempDumpDirectory.FullName, "FimDumpUtility.exe");

            File.WriteAllBytes(dumpUtilityFileName, ResourceDump.FimDumpUtility);

            if (!Directory.Exists(_activityData.FimBundlesLocation))
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Failed to find FW bundle directory"));
            }

            string[] files = Directory.GetFiles(_activityData.FimBundlesLocation, "*.bdl");

            if (files.Length == 0)
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Unable to find .bdl files in the directory"));;
            }


            string firmwareFile = _activityData.AssetMapping[assetId].FirmwareFile;

            FirmwareData fwData = new FirmwareData();

            string fwFileName = Path.Combine(tempDumpDirectory.FullName, Path.GetFileName(firmwareFile));

            File.Copy(firmwareFile, fwFileName, true);



            var result      = ProcessUtil.Execute(dumpUtilityFileName, $"-o {tempDumpDirectory.FullName} \"{fwFileName}\"");
            var outputLines = result.StandardOutput.Split(separator, StringSplitOptions.None);

            var revision = outputLines.FirstOrDefault(x => x.Contains("Version"));

            if (string.IsNullOrEmpty(revision))
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Failed to find FW bundle revision"));;
            }
            revision = revision.Substring(revision.IndexOf(':') + 1).Trim();
            fwData.FirmwareRevision = revision.Split(' ').First();

            var version = outputLines.FirstOrDefault(x => x.Contains("Description"))?.Trim();

            if (string.IsNullOrEmpty(version))
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Failed to find FW bundle version"));
            }
            version = version.Substring(version.IndexOf(':') + 1);
            fwData.FWBundleVersion = version;

            var dateCode = revision.Substring(revision.IndexOf('(') + 1, revision.LastIndexOf(')') - (revision.IndexOf('(') + 1));

            fwData.FirmwareDateCode = dateCode;

            var name = outputLines.FirstOrDefault(x => x.Contains("Name"));

            if (string.IsNullOrEmpty(name))
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Failed to find FW bundle name"));
            }
            name = name.Substring(name.IndexOf(':') + 1).Trim();
            fwData.FWModelName = name;
            var pFamily = outputLines.FirstOrDefault(x => x.Contains("Identifier"));

            pFamily = pFamily.Substring(pFamily.IndexOf(':') + 1).Trim();
            fwData.ProductFamily = pFamily;

            if (_activityData.ValidateFWBundles)
            {
                if (!_activityData.FWBundleInfo.Any(
                        x => x.ProductFamily == fwData.ProductFamily &&
                        x.FWModelName == fwData.FWModelName &&
                        x.FWBundleVersion == fwData.FWBundleVersion &&
                        x.FirmwareRevision == fwData.FirmwareRevision &&
                        x.FirmwareDateCode == fwData.FirmwareDateCode))
                {
                    return(new PluginExecutionResult(PluginResult.Failed, "Failed to find FW bundle match"));
                }
            }
            else
            {
                JediDevice dev  = new JediDevice(address, password);
                var        temp = dev.GetDeviceInfo();

                if (fwData.FirmwareRevision == temp.FirmwareRevision)
                {
                    return(new PluginExecutionResult(PluginResult.Skipped, "Firmware on device is the same as the bundle"));
                }
            }

            ///Check to see that the FW is still tied to a device.
            if (_activityData.AssetMapping.Where(x => x.Value.ProductFamily == pFamily).Count() == 0)
            {
                return(new PluginExecutionResult(PluginResult.Failed, "Unable to match a device to a FW bundle"));
            }

            _activityData.AssetMapping.Where(x => x.Value.ProductFamily == pFamily).First().Value.FirmwareFile = fwFileName;

            UpdateStatus($"Validated firmware for device");
            return(new PluginExecutionResult(PluginResult.Passed));
        }