/// <summary> /// Initializes a new instance of the <see cref="AssetSelectionForm" /> class. /// </summary> /// <param name="assetAttributes">The attributes of the assets to be displayed.</param> /// <param name="allowMultipleSelection">if set to <c>true</c> allow multiple assets to be selected.</param> public AssetSelectionForm(AssetAttributes assetAttributes, bool allowMultipleSelection) : this(allowMultipleSelection) { AssetInfoCollection assetList = ConfigurationServices.AssetInventory.GetAssets(assetAttributes); _assetList = new BindingList <AssetInfo>(assetList.ToList()); assets_GridView.DataSource = _assetList; }
PluginExecutionData IPluginFrameworkSimulator.CreateExecutionData(PluginConfigurationData configurationData) { if (configurationData == null) { throw new ArgumentNullException(nameof(configurationData)); } PluginExecutionContext executionContext = new PluginExecutionContext { ActivityExecutionId = SequentialGuid.NewGuid(), SessionId = SessionId, UserName = UserName, UserPassword = UserPassword }; // Retrieve all selected assets, then add any badge boxes associated with those assets var selectedAssets = PluginConfigurationTransformer.GetExecutionAssets(configurationData, _assetInventory); var badgeBoxes = _assetInventory.GetBadgeBoxes(selectedAssets); AssetInfoCollection executionAssets = new AssetInfoCollection(selectedAssets.Union(badgeBoxes).ToList()); return(new PluginExecutionData ( configurationData.GetMetadata(), configurationData.MetadataVersion, executionAssets, PluginConfigurationTransformer.GetExecutionDocuments(configurationData, _documentLibrary), PluginConfigurationTransformer.GetExecutionServers(configurationData, _assetInventory), PluginConfigurationTransformer.GetExecutionPrintQueues(configurationData, _assetInventory), (this as IPluginFrameworkSimulator).Environment, executionContext, new PluginRetrySettingDictionary(RetrySettings) )); }
PluginExecutionData IPluginFrameworkSimulator.CreateExecutionData(PluginConfigurationData configurationData) { if (configurationData == null) { throw new ArgumentNullException(nameof(configurationData)); } PluginExecutionContext executionContext = new PluginExecutionContext { ActivityExecutionId = SequentialGuid.NewGuid(), SessionId = SessionId, UserName = UserName, UserPassword = UserPassword }; // Retrieve all selected assets, then add any badge boxes associated with those assets var selectedAssets = PluginConfigurationTransformer.GetExecutionAssets(configurationData, _assetInventory); var badgeBoxes = _assetInventory.GetBadgeBoxes(selectedAssets); AssetInfoCollection executionAssets = new AssetInfoCollection(selectedAssets.Union(badgeBoxes).ToList()); // Set job media mode if (PaperlessMode != JobMediaMode.Unknown) { foreach (DeviceInfo deviceInfo in selectedAssets.Where(n => n.Attributes.HasFlag(AssetAttributes.Printer))) { using (var device = DeviceConstructor.Create(deviceInfo)) { try { DeviceSettingsManagerFactory.Create(device).SetJobMediaMode(PaperlessMode); } catch { //Did not set paperless mode. Ignore error. System.Diagnostics.Debug.WriteLine($"Error setting paperless mode. {executionAssets.ToString()}"); } } } } return(new PluginExecutionData ( configurationData.GetMetadata(), configurationData.MetadataVersion, executionAssets, PluginConfigurationTransformer.GetExecutionDocuments(configurationData, _documentLibrary), PluginConfigurationTransformer.GetExecutionServers(configurationData, _assetInventory), PluginConfigurationTransformer.GetExecutionPrintQueues(configurationData, _assetInventory), (this as IPluginFrameworkSimulator).Environment, executionContext, new PluginRetrySettingDictionary(RetrySettings), new ExternalCredentialInfoCollection(_assetInventory.GetExternalCredentials(executionContext.UserName)) )); }
/// <summary> /// Initializes a new instance of the <see cref="AssetSelectionForm" /> class. /// </summary> /// <param name="assetAttributes">The attributes of the assets to be displayed.</param> /// <param name="assetFilter">A function to apply that acts as an additional filter to the displayed assets.</param> /// <param name="allowMultipleSelection">if set to <c>true</c> allow multiple assets to be selected.</param> /// <exception cref="ArgumentNullException"><paramref name="assetFilter" /> is null.</exception> public AssetSelectionForm(AssetAttributes assetAttributes, Func <AssetInfoCollection, AssetInfoCollection> assetFilter, bool allowMultipleSelection) : this(allowMultipleSelection) { if (assetFilter == null) { throw new ArgumentNullException(nameof(assetFilter)); } AssetInfoCollection assetList = ConfigurationServices.AssetInventory.GetAssets(assetAttributes); AssetInfoCollection filteredAssetList = assetFilter(assetList); _assetList = new BindingList <AssetInfo>(filteredAssetList.ToList()); assets_GridView.DataSource = _assetList; }
/// <summary> /// Initializes a new instance of the <see cref="PluginExecutionData" /> class. /// </summary> /// <param name="metadata">An <see cref="XElement" /> containing plugin-specific XML metadata.</param> /// <param name="metadataVersion">The plugin-defined schema version of the XML metadata.</param> /// <param name="assets">The assets available for this plugin execution.</param> /// <param name="documents">The documents available for this plugin execution.</param> /// <param name="servers">The servers available for this plugin execution.</param> /// <param name="printQueues">The print queues available for this plugin execution.</param> /// <param name="environment">Information about the plugin execution environment.</param> /// <param name="context">Contextual/environmental information about this plugin execution.</param> /// <param name="retrySettings">Retry configuration for this plugin execution.</param> /// <param name="externalCredentials">External credentials used by this plugin execution.</param> /// <exception cref="ArgumentNullException"><paramref name="metadata" /> is null.</exception> public PluginExecutionData(XElement metadata, string metadataVersion, AssetInfoCollection assets, DocumentCollection documents, ServerInfoCollection servers, PrintQueueInfoCollection printQueues, PluginEnvironment environment, PluginExecutionContext context, PluginRetrySettingDictionary retrySettings, ExternalCredentialInfoCollection externalCredentials) : base(metadata, metadataVersion) { _assets = assets; _documents = documents; _servers = servers; _printQueues = printQueues; _environment = environment; _context = context; _credential = new Lazy <NetworkCredential>(CreateCredential); _retrySettings = retrySettings; _externalCredentials = externalCredentials; }
public void Initialize(PluginConfigurationData configuration, PluginEnvironment environment) { _activityData = configuration.GetMetadata <ePrintAdminActivityData>(); _selectedAssetList = ConfigurationServices.AssetInventory.GetAssets(configuration.Assets.SelectedAssets); if (_selectedAssetList != null && _selectedAssetList.Any()) { deviceId_TextBox.Text = _selectedAssetList.First().AssetId; } _selectedServer = configuration.Servers.SelectedServers.FirstOrDefault(); ePrintServer_ComboBox.Initialize(_selectedServer, "ePrint"); adminUser_textBox.Text = _activityData.ePrintAdminUser; adminPassword_textBox.Text = _activityData.ePrintAdminPassword; tasks_dataGridView.DataSource = _activityData.ePrintAdminTasks; }
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); }
private void quickEntry_ToolStripButton_Click(object sender, EventArgs e) { bool changeMade = false; var currentAssetIds = _assetRows.Select(n => n.AssetId); using (AssetQuickEntryForm form = new AssetQuickEntryForm(currentAssetIds)) { if (form.ShowDialog(this) == DialogResult.OK) { // Determine which assets were added and which were removed List <string> addedAssetIds = form.EnteredAssetIds.Where(n => !currentAssetIds.Contains(n)).ToList(); List <string> removedAssetIds = currentAssetIds.Where(n => !form.EnteredAssetIds.Contains(n)).ToList(); changeMade = addedAssetIds.Any() || removedAssetIds.Any(); // Retrieve asset information for all added assets that meet the attribute requirements AssetInfoCollection assetsWithAttribute = ConfigurationServices.AssetInventory.GetAssets(_assetAttributes); AssetInfoCollection filteredAssets = ApplySelectionFilter(assetsWithAttribute); AssetInfoCollection requestedAssets = ConfigurationServices.AssetInventory.GetAssets(addedAssetIds); var allowedAssets = requestedAssets.Where(n => filteredAssets.Any(m => m.AssetId == n.AssetId)); // Add new assets and remove old ones allowedAssets.ToList().ForEach(n => _assetRows.Add(new AssetSelectionRow(n))); _assetRows.Where(n => removedAssetIds.Contains(n.AssetId)).ToList().ForEach(n => _assetRows.Remove(n)); // Show a dialog box if there are any that could not be added var notAdded = addedAssetIds.Where(n => !_assetRows.Any(m => m.AssetId == n)); if (notAdded.Any()) { MessageBox.Show($"The following asset(s) could not be added, either because they were not found " + $"or do not have the capabilities required for this activity:{Environment.NewLine}" + string.Join(Environment.NewLine, notAdded), "Devices Not Added", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } asset_GridView.Refresh(); if (changeMade) { OnSelectionChanged(); OnDisplayedAssetsChanged(); } }
/// <summary> /// Initializes the asset selection control for selecting assets with the specified attributes /// and adds the specified assets to the grid. /// </summary> /// <param name="data">The asset selection data.</param> /// <param name="attributes">The attributes of assets that can be selected.</param> /// <exception cref="ArgumentNullException"><paramref name="data" /> is null.</exception> public void Initialize(AssetSelectionData data, AssetAttributes attributes) { if (data == null) { throw new ArgumentNullException(nameof(data)); } _assetAttributes = attributes; _assetRows.Clear(); var allAssetIds = data.SelectedAssets.Union(data.InactiveAssets); AssetInfoCollection assets = ConfigurationServices.AssetInventory.GetAssets(allAssetIds); foreach (AssetInfo asset in assets) { _assetRows.Add(new AssetSelectionRow(asset, data.SelectedAssets.Contains(asset.AssetId))); } asset_GridView.Refresh(); OnDisplayedAssetsChanged(); }
private void selectDevice_Button_Click(object sender, EventArgs e) { try { using (AssetSelectionForm printerSelectionForm = new AssetSelectionForm(AssetAttributes.Printer, deviceId_TextBox.Text, true)) { printerSelectionForm.ShowDialog(this); if (printerSelectionForm.DialogResult == DialogResult.OK) { _selectedAssetList = printerSelectionForm.SelectedAssets; if (_selectedAssetList != null) { deviceId_TextBox.Text = _selectedAssetList.First().AssetId; } } } } catch (InvalidOperationException ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK); } }
/// <summary> /// Initializes a new instance of the <see cref="PluginExecutionData" /> class. /// </summary> /// <param name="metadata">An <see cref="XElement" /> containing plugin-specific XML metadata.</param> /// <param name="metadataVersion">The plugin-defined schema version of the XML metadata.</param> /// <param name="assets">The assets available for this plugin execution.</param> /// <param name="documents">The documents available for this plugin execution.</param> /// <param name="servers">The servers available for this plugin execution.</param> /// <param name="printQueues">The print queues available for this plugin execution.</param> /// <param name="environment">Information about the plugin execution environment.</param> /// <param name="context">Contextual/environmental information about this plugin execution.</param> /// <param name="retrySettings">Retry configuration for this plugin execution.</param> /// <exception cref="ArgumentNullException"><paramref name="metadata" /> is null.</exception> public PluginExecutionData(XElement metadata, string metadataVersion, AssetInfoCollection assets, DocumentCollection documents, ServerInfoCollection servers, PrintQueueInfoCollection printQueues, PluginEnvironment environment, PluginExecutionContext context, PluginRetrySettingDictionary retrySettings) : this(metadata, metadataVersion, assets, documents, servers, printQueues, environment, context, retrySettings, new ExternalCredentialInfoCollection(new List <ExternalCredentialInfo>())) { }
/// <summary> /// Applies additional filtering to assets that can be selected using this control. /// Can be overridden by inheriting classes to customize behavior. /// </summary> /// <param name="selectableAssets">The assets selectable based on the standard filter behavior.</param> /// <returns>The filtered list of assets after custom modifications are applied.</returns> protected virtual AssetInfoCollection ApplySelectionFilter(AssetInfoCollection selectableAssets) { // By default, perform no extra filtering. return(selectableAssets); }
/// <summary> /// Called when there is a change in the displayed assets in this control. /// Can be overridden by inheriting classes to customize behavior. /// </summary> /// <param name="displayedAssets">The displayed assets.</param> protected virtual void OnDisplayedAssetsChanged(AssetInfoCollection displayedAssets) { // Nothing to do here; provided for child classes to override if desired }
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; }
private void OnDisplayedAssetsChanged() { AssetInfoCollection displayedAssets = new AssetInfoCollection(_assetRows.Select(n => n.Asset).ToList()); OnDisplayedAssetsChanged(displayedAssets); }
/// <summary> /// Called when there is a change in the displayed assets in this control. /// Can be overridden by inheriting classes to customize behavior. /// </summary> /// <param name="displayedAssets">The displayed assets.</param> protected override void OnDisplayedAssetsChanged(AssetInfoCollection displayedAssets) { // Only display the simulator configuration options if at least one simulator is selected. simulatorConfiguration_LinkLabel.Visible = displayedAssets.Any(n => n is DeviceSimulatorInfo); }