public InventoryController( [ServiceDependency] ILcboInventoryService lcboService, [ServiceDependency] ILcboStoresService lcboStoresService, [CreateNew] IDomainContext domainContext ) { this.lcboService = lcboService; this.lcboStoresService = lcboStoresService; this.logWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>(); this.traceManager = new TraceManager(this.logWriter); this.domainContext = domainContext; }
public AdminController( [CreateNew] IUnitOfWork unitOfWork, [ServiceDependency] ILcboProductsService lcboProductsService, [ServiceDependency] ILcboStoresService lcboStoresService, [CreateNew] IFastDomainContext domainContext ) { this.unitOfWork = unitOfWork; this.logWriter = EnterpriseLibraryContainer.Current.GetInstance<LogWriter>(); this.traceManager = new TraceManager(this.logWriter); this.lcboProductsService = lcboProductsService; this.lcboStoresService = lcboStoresService; this.domainContext = domainContext; }
private static void Main(string[] args) { Stopwatch getProductsStopwatch = new Stopwatch(); getProductsStopwatch.Start(); //lcboStoresService = new LcboStoresServiceAgent(new TestPageRetrieverFactory()); lcboStoresService = new LcboStoresServiceAgent(new LivePageRetrieverFactory()); unitOfWork = new SqlUnitOfWork(); var storesInDb = unitOfWork.Stores.FindAll(); Dictionary<int, Store> dbStoreDictionary = new Dictionary<int, Store>(); int storesInDbCount = 0; foreach (Store store in storesInDb) { storesInDbCount++; dbStoreDictionary.Add(store.Id, store); } Console.WriteLine(String.Format("Found {0} stores in the DB", storesInDbCount)); var lcboStores = lcboStoresService.GetAllStores(); Dictionary<int, LcboStoreInformation> lcboStoresDictionary = new Dictionary<int, LcboStoreInformation>(); List<int> lcboStoreIds = new List<int>(); foreach (LcboStoreInformation lcboStore in lcboStores) { lcboStoresDictionary.Add(lcboStore.StoreNumber, lcboStore); lcboStoreIds.Add(lcboStore.StoreNumber); } lcboStoreIds.Sort(); //Console.WriteLine("LCBO ctore numbers are:"); //foreach (int lcboStoreId in lcboStoreIds) //{ // Console.WriteLine(lcboStoreId); //} // Figure out changed stores and update them in the unitOfWork int newStoreCount = 0; foreach (int lcboStoreId in lcboStoresDictionary.Keys) { LcboStoreInformation lcboStore = lcboStoresDictionary[lcboStoreId]; if (dbStoreDictionary.ContainsKey(lcboStoreId)) { Store dbStore = dbStoreDictionary[lcboStoreId]; dbStore.Address = lcboStore.AddressLine; dbStore.City = lcboStore.City; dbStore.Latitude = lcboStore.Latitude; dbStore.Longitude = lcboStore.Longitude; } else { Store newDbStore = new Store() { Address = lcboStore.AddressLine, City = lcboStore.City, Id = lcboStore.StoreNumber, Latitude = lcboStore.Latitude, Longitude = lcboStore.Longitude }; newStoreCount++; unitOfWork.Stores.Add(newDbStore); } } unitOfWork.Commit(); getProductsStopwatch.Stop(); Console.WriteLine(String.Format("Found {0} stores on the LCBO website", lcboStores.Count)); Console.WriteLine(String.Format("Found {0} new stores on the LCBO website", newStoreCount)); Console.WriteLine(String.Format("Elapsed time in seconds: {0:0.00}", getProductsStopwatch.ElapsedMilliseconds / 1000.00)); }