Пример #1
0
        private void RetrieveAndPersistAllLanguagesForThisVin(string vin)
        {
            List <string> requiredNativeLangCodes = new List <string>();

            foreach (SupportedLanguage value in
                     Enum.GetValues(typeof(SupportedLanguage)))
            {
                CharacteristicsLanguageMapper mapper =
                    new CharacteristicsLanguageMapper(
                        VinChecker.GetManufacturer(vin));
                string nativeLangValue = mapper.GetSpecificCode(value);
                if (!requiredNativeLangCodes.Contains(nativeLangValue))
                {
                    requiredNativeLangCodes.Add(nativeLangValue);
                }
            }
            foreach (string code in requiredNativeLangCodes)
            {
                IVendorCharacteristicsProvider provider =
                    VendorCharacteristicsProviderFactory.Create(
                        VinChecker.GetManufacturer(vin));
                VehicleCharacteristics chars = provider.GetByVin(vin, code);
                PersistVehicleCharacteristics(chars);
            }
        }
Пример #2
0
        public VehicleCharacteristics GetVehicleCharacteristicsForVin(
            string vin, SupportedLanguage preferredLanguage)
        {
            CharacteristicsLanguageMapper mapper =
                new CharacteristicsLanguageMapper(
                    VinChecker.GetManufacturer(vin));
            string langCode = mapper.GetSpecificCode(preferredLanguage);

            // 1. check our database
            VehicleCharacteristics charsFromDatabase =
                GetExactMatchFromDatabase(vin, langCode);

            if (charsFromDatabase != null)
            {
                return(charsFromDatabase);
            }

            // 2. Do we have anything at all for this vin?
            bool haveAnything = DoWeHaveAnythingForThisVin(vin);

            if (haveAnything)
            {
                RetrieveAndPersistAllLangsWeDoNotHaveYetForThisVin(vin);
            }
            else
            {
                RetrieveAndPersistAllLanguagesForThisVin(vin);
            }

            // 3. Get best match
            return(GetBestMatchFromOurDatabase(vin, langCode));
        }
Пример #3
0
        private void RetrieveAndPersistAllLangsWeDoNotHaveYetForThisVin(string vin)
        {
            IList <SupportedLanguage> langsWeLackForThisVin =
                GetLangsWeDoNotHaveForVin(vin);

            foreach (SupportedLanguage language in langsWeLackForThisVin)
            {
                IVendorCharacteristicsProvider provider =
                    VendorCharacteristicsProviderFactory.Create(
                        VinChecker.GetManufacturer(vin));
                CharacteristicsLanguageMapper mapper =
                    new CharacteristicsLanguageMapper(VinChecker.GetManufacturer(vin));
                VehicleCharacteristics chars = provider.GetByVin(vin,
                                                                 mapper.GetSpecificCode(language));
                PersistVehicleCharacteristics(chars);
            }
        }
Пример #4
0
 private List <SupportedLanguage> GetLangsWeDoNotHaveForVin(string vin)
 {
     using (VTSDatabase database = new VTSDatabase())
     {
         List <SupportedLanguage> result = new List <SupportedLanguage>();
         foreach (SupportedLanguage value in
                  Enum.GetValues(typeof(SupportedLanguage)))
         {
             CharacteristicsLanguageMapper mapper =
                 new CharacteristicsLanguageMapper(VinChecker.GetManufacturer(vin));
             string langValue = mapper.GetSpecificCode(value);
             if (!database.VehicleCharacteristics.Any(vc =>
                                                      vc.Vin == vin && vc.Language == langValue))
             {
                 if (!result.Contains(value))
                 {
                     result.Add(value);
                 }
             }
         }
         return(result);
     }
 }