Beispiel #1
0
        private string RecognizeVehicleModel()
        {
            IVehicleModelRecognizer recognizer = VehicleModelRecognizerFactory.
                                                 Create(VinChecker.GetManufacturer(vin));

            return(recognizer.Recognize(characteristics));
        }
        public VehicleCharacteristics Get()
        {
            Manufacturer?manufacturer = VinChecker.GetManufacturer(vin);

            if (manufacturer == null)
            {
                return(null);
            }
            ManufacturerWebConnectorFactory factory =
                new ManufacturerWebConnectorFactory(DefaultLang);
            IManufacturerWebConnector connector =
                factory.GetConnector(manufacturer.Value);
            VehicleCharacteristics result;

            try
            {
                connector.Connect();
                result = connector.Retrieve(vin);
                connector.Disconnect();
            }
            catch (Exception)
            {
                // TODO : Message about xception
                return(null);
            }
            return(result);
        }
Beispiel #3
0
        private int RecognizeProductionYear()
        {
            IVehicleProductionYearRecognizer rec =
                VehicleProductionYearRecognizerFactory.Create(VinChecker.GetManufacturer(vin));

            return(rec.Recognize(characteristics));
        }
Beispiel #4
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);
            }
        }
Beispiel #5
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));
        }
Beispiel #6
0
        public EngineRecognizerFactory(
            string vin,
            VehicleCharacteristics characteristics)
        {
            Manufacturer?man1 = VinChecker.GetManufacturer(vin);

            if (man1 == null)
            {
                throw new Exception("Manufacturer not recognized");
            }
            man = man1.Value;
            this.characteristics = characteristics;
        }
Beispiel #7
0
 private bool IsVinKnownAndValid(string vinToCheck)
 {
     if (String.IsNullOrWhiteSpace(vinToCheck) ||
         vinToCheck.Length != 17)
     {
         return(false);
     }
     try
     {
         VinChecker.GetManufacturer(vinToCheck);
     }
     catch (NotSupportedException)
     {
         return(false);
     }
     return(true);
 }
Beispiel #8
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);
            }
        }
Beispiel #9
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);
     }
 }