Exemplo n.º 1
0
        private static AssetIdCollection GetAssetIds(AssetSelectionData selectionData)
        {
            AssetIdCollection result = new AssetIdCollection();

            using (AssetInventoryContext context = DbConnect.AssetInventoryContext())
            {
                foreach (string assetId in selectionData.SelectedAssets)
                {
                    result.Add(assetId);

                    //Check to see if the asset has badge boxes
                    BadgeBox badgeBox = context.BadgeBoxes.FirstOrDefault(n => n.PrinterId == assetId);
                    if (badgeBox != null)
                    {
                        TraceFactory.Logger.Debug($"Asset: {assetId} has associated BadgeBox: {badgeBox.BadgeBoxId}");
                        result.Add(badgeBox.BadgeBoxId);
                    }

                    //Check to see if the asset has cameras
                    Core.AssetInventory.Camera camera = context.Assets.OfType <Core.AssetInventory.Camera>().FirstOrDefault(c => c.PrinterId == assetId);
                    if (camera != null)
                    {
                        TraceFactory.Logger.Debug($"Asset: {assetId} has associated Camera: {camera.AssetId}");
                        result.Add(camera.AssetId);
                    }
                }
            }
            return(result);
        }
Exemplo n.º 2
0
        private bool IsActiveAsset(string assetId, AssetIdCollection inActiveAssetIds)
        {
            bool isActive = true;

            foreach (string id in inActiveAssetIds)
            {
                if (id.Equals(assetId))
                {
                    isActive = false;
                    break;
                }
            }
            return(isActive);
        }
        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;
        }