Exemple #1
0
        public CarInfo GetCarInfo(string vin)
        {
            CarInfo ret = null;

            if (mWmiLookup != null)
            {
                string key = vin.Substring(0, 3);
                if (mWmiLookup.ContainsKey(key))
                {
                    ret = mWmiLookup[key];
                }
                else
                {
                    key = vin.Substring(0, 2);
                    if (mWmiLookup.ContainsKey(key))
                    {
                        ret = mWmiLookup[key];
                    }
                }
            }
            if (ret == null)
            {
                ret = new CarInfo
                {
                    CarType = CarType.Unknown,
                    Make    = "Unknown",
                    Model   = "Unknown"
                };
            }

            if (mMakeLookup != null)
            {
                MakeMap map = null;
                if (mMakeMaps.ContainsKey(vin.Substring(0, 3)))
                {
                    map = mMakeMaps[vin.Substring(0, 3)];
                }
                else if (mMakeLookup.ContainsKey(vin.Substring(0, 2)))
                {
                    map = mMakeMaps[vin.Substring(0, 2)];
                }
                if (map != null)
                {
                    ExpandCarInfo(ret, map, vin);
                }
            }

            if (string.IsNullOrEmpty(ret.Model))
            {
                ret.Model = "Unknown";
            }
            if (string.IsNullOrEmpty(ret.Make))
            {
                ret.Make = "Unknown";
            }
            return(ret);
        }
Exemple #2
0
 private void ExpandCarInfo(CarInfo info, MakeMap map, string vin)
 {
     for (int i = map.MaxLength; i >= 1; i--)
     {
         string part = vin.Substring(map.StartDigit - 1, i);
         if (map.Map.ContainsKey(part))
         {
             if (map.Map[part].CarType != CarType.Unknown)
             {
                 info.CarType = map.Map[part].CarType;
             }
             if (!string.IsNullOrEmpty(map.Map[part].Model))
             {
                 info.Model = map.Map[part].Model;
             }
             return;
         }
     }
 }