/// <summary> /// This method Adds objects to cache /// </summary> /// <returns>List of keys added to cache </returns> private static string[] AddDataIntoCache() { List <Product> products = LoadProductsFromDatabase(); CacheItem[] items = new CacheItem[products.Count]; string[] keys = new String[products.Count]; for (int i = 0; i < products.Count; i++) { keys[i] = products[i].Id.ToString(); CacheItem item = new CacheItem(products[i]); IDictionary <string, string> param = new Dictionary <string, string>(); param.Add("ProductID", products[i].Id.ToString()); param.Add("ConnectionString", _connectionString); CustomDependency customDependency = new CustomDependency(ConfigurationManager.AppSettings["ProviderName"], param); item.Dependency = new CacheDependency(customDependency); items[i] = item; } IDictionary <string, CacheItem> cacheItems = GetCacheItemDictionary(keys, items); _cache.AddBulk(cacheItems); // Print output on console Console.WriteLine("Items are added to Cache."); return(keys); }
private void startJob() { HttpClient httpClient = new HttpClient(); Uri uriResult; if (!Uri.TryCreate("_url", UriKind.Absolute, out uriResult)) { _url = "http://" + _url; } UrlCheckList urlCheckList = new UrlCheckList(); try { Task <HttpResponseMessage> response = httpClient.GetAsync(_url); urlCheckList.Id = 0; urlCheckList.CreateDate = DateTime.Now; urlCheckList.UrlId = Convert.ToInt32(_urlId); urlCheckList.StatusCode = response.Result.StatusCode.ToString(); if (!response.Result.IsSuccessStatusCode) { SendMail(); } } catch (Exception) { //Custom Error Handlen Yazılacak urlCheckList.StatusCode = "Domain Error"; } CustomDependency c = new CustomDependency(new UrlCheckListService(new EfUrlCheckListDal())); c.UrlCheckListSave(urlCheckList); }
public void Allow_to_use_custom_dependency_implementation() { using (var sut = new SutFactory <ComponentWithDependencies>()) { var customDependency = new CustomDependency(); sut.UseDependency <IDependency>(customDependency); var result = sut.Create(); result.Dependency.Should().Be(customDependency); } }
/// <summary> /// This method adds an instance of Produc in the cache with notification based Dependency. /// </summary> /// <param name="customer"> customer that is to be added. </param> private static void AddCustomerToCacheWithDependency(Customer customer) { string endPoint = ConfigurationManager.AppSettings["EndPoint"]; string authKey = ConfigurationManager.AppSettings["AuthKey"]; string monitoredCollection = ConfigurationManager.AppSettings["MonitoredCollection"]; string leaseCollection = ConfigurationManager.AppSettings["LeaseCollection"]; string databaseName = ConfigurationManager.AppSettings["DatabaseName"]; string providerName = ConfigurationManager.AppSettings["ProviderName"]; IDictionary <string, string> param = new Dictionary <string, string>(); param.Add("Key", customer.Id); param.Add("MonitoredCollectionName", monitoredCollection); param.Add("LeaseCollectionName", leaseCollection); CacheItem cacheItem = new CacheItem(customer); CustomDependency cosmosDbDependency = new CustomDependency(providerName, param); cacheItem.Dependency = cosmosDbDependency; // Inserting Loaded customer into cache with key: [item:1] _cache.Add(customer.Id, cacheItem); }