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); }
/// <summary> /// Gets a collection of <see cref="BadgeBoxInfo" /> objects that are associated with one of the specified assets. /// </summary> /// <param name="assets">The assets.</param> /// <returns>A collection of <see cref="BadgeBoxInfo" /> objects.</returns> /// <exception cref="ArgumentNullException"><paramref name="assets" /> is null.</exception> public IEnumerable <BadgeBoxInfo> GetBadgeBoxes(IEnumerable <AssetInfo> assets) { if (assets == null) { throw new ArgumentNullException(nameof(assets)); } Dictionary <string, List <BadgeInfo> > badges = new Dictionary <string, List <BadgeInfo> >(); DatabaseQuery(Resources.SelectBadges, record => { BadgeInfo badge = new BadgeInfo ( record["BadgeId"] as string, record["UserName"] as string, (byte)record["Index"], record["Description"] as string ); string badgeBoxId = record["BadgeBoxId"] as string; if (!badges.ContainsKey(badgeBoxId)) { badges.Add(badgeBoxId, new List <BadgeInfo>()); } badges[badgeBoxId].Add(badge); }); List <BadgeBoxInfo> badgeBoxes = new List <BadgeBoxInfo>(); DatabaseQuery(Resources.SelectBadgeBoxes, record => { string badgeBoxId = record["BadgeBoxId"] as string; BadgeBoxInfo badgeBox = new BadgeBoxInfo ( badgeBoxId, AssetAttributes.None, "BadgeBox", record["IPAddress"] as string, record["PrinterId"] as string, badges.ContainsKey(badgeBoxId) ? badges[badgeBoxId] : new List <BadgeInfo>() ); badgeBoxes.Add(badgeBox); }); return(badgeBoxes.Where(n => assets.Select(m => m.AssetId).Contains(n.PrinterId))); }
/// <summary> /// Adds the specified badge box to the inventory. /// </summary> /// <param name="badgeBox">The badge box to add to the inventory.</param> public void AddBadgeBox(BadgeBoxInfo badgeBox) => _badgeBoxes.Add(badgeBox);
/// <summary> /// Removes the specified badge box from the inventory. /// </summary> /// <param name="badgeBox">The badge box to remove from the inventory.</param> public void RemoveBadgeBox(BadgeBoxInfo badgeBox) => _badgeBoxes.Remove(badgeBox);
/// <summary> /// Initializes a new instance of the <see cref="AuthenticationCredential"/> class. /// Handles setting of <see cref="BadgeBoxInfo" />. /// </summary> /// <param name="pluginExecutionData">The plugin execution data.</param> /// <param name="deviceId">The device identifier.</param> /// <param name="deviceAddress">The device address.</param> /// <exception cref="System.ArgumentException">No badge box associated with the specified device.</exception> public AuthenticationCredential(PluginExecutionData pluginExecutionData, string deviceId, string deviceAddress) : this(pluginExecutionData.Credential) { _badgeBoxInfo = GetBadgeBoxInfo(pluginExecutionData.Assets, deviceId, deviceAddress); }