Esempio n. 1
0
        private ICollection <Taxonomies> MapTaxonomies(string partType, MountingTypes packageType)
        {
            var taxonomies = new List <Taxonomies>();
            var taxonomy   = Taxonomies.None;

            if (!string.IsNullOrEmpty(partType))
            {
                if (Enum.TryParse <Taxonomies>(partType, true, out taxonomy))
                {
                    var addBaseType = true;
                    // also map all the alternates
                    var memberInfos         = typeof(Taxonomies).GetMember(taxonomy.ToString());
                    var enumValueMemberInfo = memberInfos.FirstOrDefault(m => m.DeclaringType == typeof(Taxonomies));
                    var valueAttributes     = enumValueMemberInfo.GetCustomAttributes(typeof(AlternatesAttribute), false);
                    var alternateIds        = ((AlternatesAttribute)valueAttributes[0]).Ids;
                    // taxonomies.AddRange(alternateIds);
                    switch (taxonomy)
                    {
                    case Taxonomies.Resistor:
                        if (packageType == MountingTypes.ThroughHole)
                        {
                            taxonomies.Add(Taxonomies.ThroughHoleResistor);
                            addBaseType = false;
                        }
                        if (packageType == MountingTypes.SurfaceMount)
                        {
                            taxonomies.Add(Taxonomies.SurfaceMountResistor);
                            addBaseType = false;
                        }
                        break;
                    }
                    if (addBaseType)
                    {
                        taxonomies.Add(taxonomy);
                    }
                }
            }

            return(taxonomies);
        }
Esempio n. 2
0
        private ICollection <ParametricFilter> MapParametricFilters(ICollection <string> keywords, MountingTypes packageType, ICollection <Taxonomies> taxonomies)
        {
            var filters       = new List <ParametricFilter>();
            var percent       = "";
            var power         = "";
            var resistance    = "";
            var capacitance   = "";
            var voltageRating = "";
            var currentRating = "";
            var inductance    = "";

            foreach (var keyword in keywords)
            {
                if (PercentageRegex.IsMatch(keyword))
                {
                    percent = keyword;
                }
                if (PowerRegex.IsMatch(keyword))
                {
                    power = keyword;
                }
                if (ResistanceRegex.IsMatch(keyword))
                {
                    resistance = keyword;
                }
                if (CapacitanceRegex.IsMatch(keyword))
                {
                    capacitance = keyword;
                }
                if (VoltageRegex.IsMatch(keyword))
                {
                    voltageRating = keyword;
                }
                if (CurrentRegex.IsMatch(keyword))
                {
                    currentRating = keyword;
                }
                if (InductanceRegex.IsMatch(keyword))
                {
                    inductance = keyword;
                }
            }
            // add tolerance parameter
            if (keywords.Contains("precision") || !string.IsNullOrEmpty(percent))
            {
                if (keywords.Contains("precision"))
                {
                    keywords.Remove("precision");
                }
                if (keywords.Contains(percent))
                {
                    keywords.Remove(percent);
                }
                else
                {
                    percent = "1%";
                }
                var filter = new ParametricFilter
                {
                    ParameterId = (int)Parametrics.Tolerance,
                    ValueId     = ((int)GetTolerance(percent)).ToString()
                };
                filters.Add(filter);
            }
            if (!string.IsNullOrEmpty(power))
            {
                keywords.Remove(power);
                var filter = new ParametricFilter
                {
                    ParameterId = (int)Parametrics.Power,
                    ValueId     = GetPower(power)
                };
                filters.Add(filter);
            }
            if (!string.IsNullOrEmpty(resistance))
            {
                keywords.Remove(resistance);
                var filter = new ParametricFilter
                {
                    ParameterId = (int)Parametrics.Resistance,
                    ValueId     = GetResistance(resistance)
                };
                filters.Add(filter);
            }
            if (!string.IsNullOrEmpty(capacitance))
            {
                keywords.Remove(capacitance);
                var filter = new ParametricFilter
                {
                    ParameterId = (int)Parametrics.Capacitance,
                    ValueId     = GetCapacitance(capacitance)
                };
                filters.Add(filter);
            }
            if (!string.IsNullOrEmpty(voltageRating))
            {
                keywords.Remove(voltageRating);
                var filter = new ParametricFilter
                {
                    ParameterId = (int)Parametrics.VoltageRating,
                    ValueId     = GetVoltageRating(voltageRating)
                };
                filters.Add(filter);
            }
            if (!string.IsNullOrEmpty(currentRating))
            {
                keywords.Remove(currentRating);
                var filter = new ParametricFilter
                {
                    ParameterId = (int)Parametrics.CurrentRating,
                    ValueId     = GetVoltageRating(currentRating)
                };
                filters.Add(filter);
            }
            if (!string.IsNullOrEmpty(inductance))
            {
                keywords.Remove(inductance);
                var filter = new ParametricFilter
                {
                    ParameterId = (int)Parametrics.Inductance,
                    ValueId     = GetInductance(inductance)
                };
                filters.Add(filter);
            }
            // dont add mounting type to resistors, they dont seem to be mapped
            if (!taxonomies.ContainsAny(new List <Taxonomies> {
                Taxonomies.Resistor, Taxonomies.SurfaceMountResistor, Taxonomies.ThroughHoleResistor
            }))
            {
                if (packageType != MountingTypes.None)
                {
                    filters.Add(new ParametricFilter
                    {
                        ParameterId = (int)Parametrics.MountingType,
                        ValueId     = ((int)packageType).ToString()
                    });
                }
            }
            return(filters);
        }