public ProviderGroup ExecuteItem(bool useCache = true) { ProviderGroup cacheResult = null; if (useCache && CacheHelper.TryGetResult <ProviderGroup>(this.Id.ToString(), out cacheResult)) { return(cacheResult); } using (DataContext dataContext = DataContext.CreateForMessage(this)) { ProviderGroup result = dataContext .ProviderGroupSet .Include("PetCollection.Breed") .Include("OwnerCollection.SchedulerEventCollection.SkuCategory") .Include("BreedCollection") .Where(x => x.Id == this.Id).SingleOrDefault(); // Step 1. Add to cache by Id CacheHelper.CacheResult <ProviderGroup>(this.Id.ToString(), result, slidingExpiration: new TimeSpan(0, 20, 0), cachedItemRemovedCallback: (key, value, reason) => { Logger.Info($"CacheItemRemovedCallback({reason.ToString()}): [{typeof(Provider).FullName}]({key})"); if (reason != CacheItemRemovedReason.Underused) { GetProviderGroup providerGroup = value as GetProviderGroup; if (providerGroup != null) { new GetProviderGroup() { Id = providerGroup.Id }.ExecuteItem(false); } } }); return(result); } }
public Pet ExecuteItem(bool useCache = true) { ProviderGroup cacheResult = null; if (useCache && CacheHelper.TryGetResult <ProviderGroup>(this.ProviderGroupId.ToString(), out cacheResult)) { Pet cacheItem = cacheResult.PetCollection.Where(x => x.Id == this.Id).SingleOrDefault(); if (cacheItem != null) { Logger.Info($"Returned [{typeof(Pet)}]({cacheItem.Id}) from cache graph."); return(cacheItem); } } using (DataContext dataContext = DataContext.CreateForMessage(this)) { return(dataContext.PetSet .Include("Owner.PetCollection.Breed") .Where(x => x.Id == this.Id && x.ProviderGroupId == this.ProviderGroupId) .SingleOrDefault()); } }
public Owner ExecuteItem(bool useCache = true) { ProviderGroup cacheResult = null; if (useCache && CacheHelper.TryGetResult <ProviderGroup>(this.ProviderGroupId.ToString(), out cacheResult)) { Owner cacheItem = cacheResult.OwnerCollection.Where(x => x.Id == this.Id).SingleOrDefault(); if (cacheItem != null) { CacheHelper.Log($"Returned [{typeof(Owner)}]({cacheItem.Id}) from cache graph."); return(cacheItem); } } using (DataContext context = DataContext.CreateForMessage(this)) { return(context .OwnerSet .Include("PetCollection") .Include("SchedulerEventCollection.SkuCategory") // NOTE: that this should be in a separate call (as owners belong to provider groups, while events belong to provders) .Where(x => x.Id == this.Id && x.ProviderGroupId == this.ProviderGroupId) .SingleOrDefault()); } }
public ProviderLauncher(ProviderGroup group, int instanceCounter) { instanceUUID = Guid.Parse(String.Format("00000000-0000-0000-000{0}-0000000000{1:D2}", (int)group, instanceCounter)); instanceIconPath = String.Format(@"{0}\Images\InfProvider{1}{2}.png", Environment.CurrentDirectory, group, instanceCounter); }