예제 #1
0
        internal void SetManufacturers(IEnumerable <KeyValuePair <string, string> > unorderedManufacturers, List <string> whitelist = null)
        {
            // Sort manufacturers by name
            List <KeyValuePair <string, string> > manufacturers = new List <KeyValuePair <string, string> >();
            KeyValuePair <string, string>         otherInfo     = new KeyValuePair <string, string>(null, null);

            foreach (var printer in unorderedManufacturers.OrderBy(k => k.Value))
            {
                if (printer.Value == "Other")
                {
                    otherInfo = printer;
                }
                else
                {
                    manufacturers.Add(printer);
                }
            }

            if (otherInfo.Key != null)
            {
                // add it at the end
                manufacturers.Add(otherInfo);
            }

            if (whitelist != null)
            {
                this.PrinterWhiteList = whitelist;
            }

            // Apply whitelist
            var whiteListedItems = manufacturers?.Where(keyValue => PrinterWhiteList.Contains(keyValue.Key));

            if (whiteListedItems == null ||
                whiteListedItems.Count() == 0)
            {
                // No whitelist means all items
                whiteListedItems = manufacturers;
            }

            var newItems = new List <KeyValuePair <string, string> >();

            // Apply manufacturer name mappings
            foreach (var keyValue in whiteListedItems)
            {
                string labelText = keyValue.Value;

                // Override the manufacturer name if a manufacturerNameMappings exists
                string mappedName = ManufacturerNameMappings.Where(m => m.NameOnDisk == keyValue.Key).FirstOrDefault()?.NameOnDisk;
                if (!string.IsNullOrEmpty(mappedName))
                {
                    labelText = mappedName;
                }

                newItems.Add(new KeyValuePair <string, string>(keyValue.Key, labelText));
            }

            AllOems = newItems;
        }
예제 #2
0
        internal void SetManufacturers(List <KeyValuePair <string, string> > manufacturers, List <string> whitelist = null)
        {
            if (whitelist != null)
            {
                this.PrinterWhiteList = whitelist;
            }

            // Apply whitelist
            var whiteListedItems = manufacturers?.Where(keyValue => PrinterWhiteList.Contains(keyValue.Key));

            if (whiteListedItems == null ||
                whiteListedItems.Count() == 0)
            {
                AllOems = new List <KeyValuePair <string, string> >(manufacturers);
                return;
            }

            var newItems = new List <KeyValuePair <string, string> >();

            // Apply manufacturer name mappings
            foreach (var keyValue in whiteListedItems)
            {
                string labelText = keyValue.Value;

                // Override the manufacturer name if a manufacturerNameMappings exists
                string mappedName = ManufacturerNameMappings.Where(m => m.NameOnDisk == keyValue.Key).FirstOrDefault()?.NameOnDisk;
                if (!string.IsNullOrEmpty(mappedName))
                {
                    labelText = mappedName;
                }

                newItems.Add(new KeyValuePair <string, string>(keyValue.Key, labelText));
            }

            AllOems = newItems;
        }