private static BadgeBoxInfo GetBadgeBoxInfo(AssetInfoCollection availableAssets, string deviceId, string deviceAddress) { ExecutionServices.SystemTrace.LogInfo($"Total number of assets: {availableAssets.Count}"); BadgeBoxInfo badgeBoxAsset = null; if (availableAssets.OfType <BadgeBoxInfo>().Count() > 0) { badgeBoxAsset = availableAssets.OfType <BadgeBoxInfo>().Where(n => n.PrinterId == deviceId).FirstOrDefault(); } if (badgeBoxAsset == null) { throw new ArgumentException($"No Badge Box is associated with device {deviceId}, {deviceAddress}."); } ExecutionServices.SystemTrace.LogInfo($"Printer ID of badge box: {badgeBoxAsset.PrinterId}"); return(badgeBoxAsset); }
protected override AssetInfoCollection ApplySelectionFilter(AssetInfoCollection selectableAssets) { return(new AssetInfoCollection(selectableAssets.OfType <VirtualPrinterInfo>().ToList <AssetInfo>())); }
private void ReadFirmwareDump(string[] bundleFiles) { string[] separator = { Environment.NewLine }; //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); //Get .bdl files from directory //Extract data //populate datagridview //refresh _data.FWBundleInfo.Clear(); AssetIdCollection assetIds = assetSelectionControl.AssetSelectionData.SelectedAssets; AssetInfoCollection assets = Framework.ConfigurationServices.AssetInventory.GetAssets(assetIds); var col = assets.OfType <PrintDeviceInfo>(); Dictionary <string, ModelFileMap> nameModel = new Dictionary <string, ModelFileMap>(); string endpoint = "fim"; string urn = "urn:hp:imaging:con:service:fim:FIMService"; foreach (var printer in col) { SetDefaultPassword(printer.Address, printer.AdminPassword); ///Get way of finding the product family if (!nameModel.ContainsKey(printer.AssetId)) { ModelFileMap map = new ModelFileMap(); JediDevice device = new JediDevice(printer.Address, printer.AdminPassword); WebServiceTicket tic = device.WebServices.GetDeviceTicket(endpoint, urn); var ident = tic.FindElements("AssetIdentifier").First().Value; map.ProductFamily = ident;// "6D6670-0055";// Bugatti"696D66-0015"; nameModel.Add(printer.AssetId, map); } } //_data.AssetMapping = nameModel; foreach (string firmwareFile in bundleFiles) { FirmwareData fwData = new FirmwareData(); FileInfo fInfo = new FileInfo(firmwareFile); var fileSize = fInfo.Length / (1024 * 1024); var fileSizeMb = (int)((fileSize / 50.0) * 6); fwData.FlashTimeOutPeriod = (int)TimeSpan.FromMinutes(fileSizeMb).TotalMilliseconds; var result = ProcessUtil.Execute(dumpUtilityFileName, $"-o {tempDumpDirectory.FullName} \"{firmwareFile}\""); var outputLines = result.StandardOutput.Split(separator, StringSplitOptions.None); var revision = outputLines.FirstOrDefault(x => x.Contains("Version")); if (string.IsNullOrEmpty(revision)) { MessageBox.Show( $@"An error occurred while reading firmware revision information. Please check the firmware file {firmwareFile} and try again. Read Aborted", @"Firmware File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } 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)) { MessageBox.Show( @"An error occurred while reading firmware version information. Please check the firmware file again and try", @"Firmware File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } 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)) { MessageBox.Show( @"An error occurred while reading firmware Name information. Please check the firmware file again and try", @"Firmware File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } 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 (nameModel.Where(x => x.Value.ProductFamily == pfamily).Count() == 0) { MessageBox.Show( $@"Failed to match the firmware bundle to an existing device. Please check the firmware files and selected assets and try again. Model: {name}", @"Firmware File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } else { var devs = nameModel.Where(x => x.Value.ProductFamily == pfamily).Select(x => x.Key); foreach (var dev in devs) { nameModel[dev].FirmwareFile = firmwareFile; } } _data.FWBundleInfo.Add(fwData); } if (nameModel.Where(x => x.Value.FirmwareFile == string.Empty).Count() > 0) { string devices = nameModel.Where(x => x.Value.FirmwareFile == string.Empty).Select(x => x.Key).Aggregate((current, next) => current + ", " + next); MessageBox.Show( $@"Failed to match the following devices with firmware: {devices}. Please check the firmware files and selected assets and try again.", @"Firmware File Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } _data.AssetMapping = nameModel; }