/// <summary> /// <para>Applies a previously registered action on a object. The contextCotainer object MUST contain any context objects required by the registered action.</para> /// <para>Registered actions on interfaces and base classes are also automaticaly applied in this order: Interface actions, Base Class (top to bottom) actions, Target type action.</para> /// </summary> /// <typeparam name="T">The target type</typeparam> /// <param name="item">The target instance</param> /// <param name="contextContainer">A context container created by LinqMapper.CreateContext() or null</param> /// <returns>The target instance</returns> public static T ApplyAfterMap <T>(T item, IObjectContext contextContainer = null) { if (item == null) { return(item); } contextContainer = contextContainer ?? LinqMapper.CreateContext(); var runtimeInfo = InternalCache.GetRuntimeInfo(typeof(T)); if (runtimeInfo != null) { //make sure to dispose tracker using (var tracker = new MaterializerTracker()) { if (Materializer.TreeTraversal == TreeTraversal.ChildrenFirst) { runtimeInfo.ApplyOn(item, contextContainer, tracker); } else { runtimeInfo.ApplyOnRootFirst(item, contextContainer, tracker); } } } return(item); }
private async void ChangeStatus(object obj) { var searchItem = obj as SearchItem; var result = await _apiClient .UpdateSearch( searchItem.Id.ToString(), searchItem.Title, searchItem.Description, searchItem.Url, searchItem.IsActive, (int)searchItem.AdSource, ApplicationSettings.GetUserId()); try { searchItem = JsonConvert.DeserializeObject <SearchItem>(result); if (searchItem?.Id > 0) { //var index = SearchItems.IndexOf(SearchItems.FirstOrDefault(si => si.Id == searchItem.Id)); //if (index < 0) // throw new Exception(); //SearchItems.RemoveAt(index); InternalCache.UpdateSearchItem(searchItem); } } catch (Exception ex) { MessagingCenter.Send <SearchSettingsViewModel, bool>(this, "SEARCH_EDIT_RESULT", false); } }
/// <inheritdoc /> public TMajor AddNew(FormKey formKey) { var ret = MajorRecordInstantiator <TMajor> .Activator(formKey, _release); InternalCache.Set(ret); return(ret); }
/// <summary> /// Adds the stecified item in the cache. /// </summary> /// <param name="id">The id of the stored item in the cache.</param> /// <param name="item">The item to cache.</param> protected void AddInCache(Identifier id, T item) { if (!InternalCache.ContainsKey(id)) { InternalCache.Add(id, item); } }
public static void Set <T>(string key, T value, TimeSpan slidingExpiration) { Check.Argument.IsNotNullOrEmpty(key, "key"); Check.Argument.IsNotNegativeOrZero(slidingExpiration, "absoluteExpiration"); InternalCache.Set(key, value, slidingExpiration); }
public async Task LoadSearchItems() { SearchItems.Clear(); var itemList = InternalCache.GetSearchList(); if (itemList?.Count > 0) { foreach (var item in itemList) { SearchItems.Add(new SearchItemDisplayModel(item)); } } else { itemList = await _apiClient.GetSearches(ApplicationSettings.GetUserId()); foreach (var item in itemList) { SearchItems.Add(new SearchItemDisplayModel(item)); InternalCache.AddSearchItem(item); } } SearchItems.ForEach(i => i.PropertyChanged += ItemPropertyChanged); }
/// <summary> /// Check whether we can send a CachedObjectUpdate to the client /// </summary> /// <param name="AgentID"></param> /// <param name="localID"></param> /// <param name="CurrentEntityCRC"></param> /// <returns></returns> public bool UseCachedObject(UUID AgentID, uint localID, uint CurrentEntityCRC) { lock (ObjectCacheAgents) { Dictionary <uint, uint> InternalCache; if (ObjectCacheAgents.TryGetValue(AgentID, out InternalCache)) { uint CurrentCachedCRC = 0; if (InternalCache.TryGetValue(localID, out CurrentCachedCRC)) { if (CurrentEntityCRC == CurrentCachedCRC) { //The client knows of the newest version return(true); } //else, update below } } else { InternalCache = new Dictionary <uint, uint>(); } InternalCache[localID] = CurrentEntityCRC; ObjectCacheAgents[AgentID] = InternalCache; return(false); } }
private async Task <CosmosContainerSettings> ResolveByNameAsync( string apiVersion, string resourceAddress, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); string resourceFullName = PathsHelper.GetCollectionPath(resourceAddress); InternalCache cache = this.GetCache(apiVersion); return(await cache.collectionInfoByName.GetAsync( resourceFullName, null, async() => { DateTime currentTime = DateTime.UtcNow; CosmosContainerSettings collection = await this.GetByNameAsync(apiVersion, resourceFullName, cancellationToken); cache.collectionInfoById.Set(collection.ResourceId, collection); cache.collectionInfoByNameLastRefreshTime.AddOrUpdate(resourceFullName, currentTime, (string currentKey, DateTime currentValue) => currentTime); cache.collectionInfoByIdLastRefreshTime.AddOrUpdate(collection.ResourceId, currentTime, (string currentKey, DateTime currentValue) => currentTime); return collection; }, cancellationToken)); }
private async void OnNewAdsArrived(NotificationCenter arg1) { int adIdFrom = 0; if (Ads?.Count > 0) { adIdFrom = Ads.Max(ad => ad.Id); } var latestAds = await _apiClient.GetAds(Convert.ToInt32(ApplicationSettings.GetUserId()), adIdFrom); if (latestAds != null & latestAds.Count > 0) { foreach (var item in latestAds) { if (Ads.Count >= ADS_LIST_MAX_SIZE) { Ads.RemoveAt(Ads.Count - 1); } Ads.Insert(0, item); InternalCache.InsertAd(0, item); } } }
/// <summary> /// Clears the cache /// </summary> public virtual void Clear() { lock (InternalCache) { InternalCache.Clear(); } }
/// <inheritdoc /> public TMajor AddNew() { var ret = MajorRecordInstantiator <TMajor> .Activator(SourceMod.GetNextFormKey(), _release); InternalCache.Set(ret); return(ret); }
private async Task RefreshAsync(DocumentServiceRequest request, CancellationToken cancellationToken) { System.Diagnostics.Debug.Assert(request.IsNameBased); InternalCache cache = this.GetCache(request.Headers[HttpConstants.HttpHeaders.Version]); string resourceFullName = PathsHelper.GetCollectionPath(request.ResourceAddress); if (request.RequestContext.ResolvedCollectionRid != null) { // Here we will issue backend call only if cache wasn't already refreshed (if whatever is there corresponds to presiously resolved collection rid). await cache.collectionInfoByName.GetAsync( resourceFullName, CosmosContainerSettings.CreateWithResourceId(request.RequestContext.ResolvedCollectionRid), async() => { DateTime currentTime = DateTime.UtcNow; CosmosContainerSettings collection = await this.GetByNameAsync(request.Headers[HttpConstants.HttpHeaders.Version], resourceFullName, cancellationToken); cache.collectionInfoById.Set(collection.ResourceId, collection); cache.collectionInfoByNameLastRefreshTime.AddOrUpdate(resourceFullName, currentTime, (string currentKey, DateTime currentValue) => currentTime); cache.collectionInfoByIdLastRefreshTime.AddOrUpdate(collection.ResourceId, currentTime, (string currentKey, DateTime currentValue) => currentTime); return(collection); }, cancellationToken); } else { // In case of ForceRefresh directive coming from client, there will be no ResolvedCollectionRid, so we // need to refresh unconditionally. this.Refresh(request.ResourceAddress, request.Headers[HttpConstants.HttpHeaders.Version]); } request.RequestContext.ResolvedCollectionRid = null; }
internal virtual async Task <ContainerProperties> ResolveByNameAsync( string apiVersion, string resourceAddress, bool forceRefesh, ITrace trace, IClientSideRequestStatistics clientSideRequestStatistics, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); string resourceFullName = PathsHelper.GetCollectionPath(resourceAddress); InternalCache cache = this.GetCache(apiVersion); if (forceRefesh) { cache.collectionInfoByName.TryRemoveIfCompleted(resourceFullName); } return(await cache.collectionInfoByName.GetAsync( resourceFullName, null, async() => { DateTime currentTime = DateTime.UtcNow; ContainerProperties collection = await this.GetByNameAsync(apiVersion, resourceFullName, trace, clientSideRequestStatistics, cancellationToken); cache.collectionInfoById.Set(collection.ResourceId, collection); cache.collectionInfoByNameLastRefreshTime.AddOrUpdate(resourceFullName, currentTime, (string currentKey, DateTime currentValue) => currentTime); cache.collectionInfoByIdLastRefreshTime.AddOrUpdate(collection.ResourceId, currentTime, (string currentKey, DateTime currentValue) => currentTime); return collection; }, cancellationToken)); }
private Task <ContainerProperties> ResolveByRidAsync( string apiVersion, string resourceId, ITrace trace, IClientSideRequestStatistics clientSideRequestStatistics, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); ResourceId resourceIdParsed = ResourceId.Parse(resourceId); string collectionResourceId = resourceIdParsed.DocumentCollectionId.ToString(); InternalCache cache = this.GetCache(apiVersion); return(cache.collectionInfoById.GetAsync( collectionResourceId, null, async() => { DateTime currentTime = DateTime.UtcNow; ContainerProperties collection = await this.GetByRidAsync(apiVersion, collectionResourceId, trace, clientSideRequestStatistics, cancellationToken); cache.collectionInfoByIdLastRefreshTime.AddOrUpdate(collectionResourceId, currentTime, (string currentKey, DateTime currentValue) => currentTime); return collection; }, cancellationToken)); }
public static void Set <T>(string key, T value, DateTime absoluteExpiration) { Check.Argument.IsNotNullOrEmpty(key, "key"); Check.Argument.IsNotInPast(absoluteExpiration, "absoluteExpiration"); InternalCache.Set(key, value, absoluteExpiration); }
/// <summary> /// Removes an item from the cache /// </summary> /// <param name="Key">Key associated with the item to remove</param> public virtual void Remove(KeyType Key) { if (Exists(Key)) { object TempItem = null; InternalCache.TryRemove(Key, out TempItem); } }
/// <summary> /// Gets an item from the cache /// </summary> /// <typeparam name="TValueType">Item type</typeparam> /// <param name="key">Key to search for</param> /// <returns>The item associated with the key</returns> public virtual TValueType Get <TValueType>(TKeyType key) { object tempItem; return(InternalCache.TryGetValue(key, out tempItem) ? tempItem.TryTo(default(TValueType)) : default(TValueType)); }
/// <summary> /// Removes an item from the cache /// </summary> /// <param name="key">Key associated with the item to remove</param> public virtual void Remove(TKeyType key) { if (Exists(key)) { object tempItem; InternalCache.TryRemove(key, out tempItem); } }
/// <inheritdoc /> public TMajor AddNew(string editorID) { var ret = MajorRecordInstantiator <TMajor> .Activator(SourceMod.GetNextFormKey(editorID), _release); ret.EditorID = editorID; InternalCache.Set(ret); return(ret); }
// // Shuts down the AppDomain // static void ShutdownAppDomain(object args) { queue_manager.Dispose(); // This will call Session_End if needed. InternalCache.InvokePrivateCallbacks(); // Kill our application. HttpApplicationFactory.Dispose(); ThreadPool.QueueUserWorkItem(new WaitCallback(DoUnload), null); }
private void FillAdList() { this.Ads.Clear(); foreach (var item in InternalCache.GetAds()) { this.Ads.Add(item); } }
public object Clear() { lock (this) { var _size = InternalCache.Count; InternalCache.Clear(); LastRefresh = DateTime.MinValue; return(_size); } }
/// <summary> /// This method is only used in client SDK in retry policy as it doesn't have request handy. /// </summary> public void Refresh(string resourceAddress, string apiVersion = null) { InternalCache cache = this.GetCache(apiVersion); if (PathsHelper.IsNameBased(resourceAddress)) { string resourceFullName = PathsHelper.GetCollectionPath(resourceAddress); cache.collectionInfoByName.TryRemoveIfCompleted(resourceFullName); } }
public virtual ClusteredList <ReaderResultSet> ExecuteReader(string query, IDictionary values, bool getData, int chunkSize, bool isInproc, OperationContext operationContext) { ReaderResultSet result = InternalCache.Local_ExecuteReader(query, values, getData, chunkSize, isInproc, operationContext); ClusteredList <ReaderResultSet> resultList = new ClusteredList <ReaderResultSet>(); if (result != null) { resultList.Add(result); } return(resultList); }
private async void Delete(object obj) { var searchItem = obj as SearchItem; var result = await _apiClient.DeleteSearch(ApplicationSettings.GetUserId(), searchItem.Id.ToString()); if (result == System.Net.HttpStatusCode.OK) { InternalCache.RemoveSearchItem(searchItem); SearchItems.Remove(SearchItems.FirstOrDefault(si => si.Id == searchItem.Id)); } }
/// <summary> /// Clears all Core caches /// </summary> /// <param name="forceClear">method want do nothing if cache option is KeepExistingCacheAlive. You can force clear caches anyway by giving true</param> public virtual void ClearCaches(bool forceClear) { if (forceClear || CacheOptions.ClearExistingCache == Settings.CacheOptions) { lock (_assembliesLock) { InternalCache.Clear(); InternalFactories.Clear(); _initalized = false; } } }
/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting /// unmanaged resources. /// </summary> public override void Dispose() { if (InternalCache is null) { return; } foreach (var Item in InternalCache.Values) { Item.Dispose(); } InternalCache.Clear(); InternalCache = null; }
/// <summary> /// Removes an item from the cache /// </summary> /// <param name="Key">Key associated with the item to remove</param> public virtual void Remove(KeyType Key) { if (Exists(Key)) { lock (InternalCache) { if (Exists(Key)) { InternalCache.Remove(Key); } } } }
/// <summary> /// Adds an item to the cache /// </summary> /// <param name="Key">Key</param> /// <param name="Value">Value</param> public virtual void Add(KeyType Key, object Value) { lock (InternalCache) { if (Exists(Key)) { InternalCache[Key].Value = Value; } else { InternalCache.Add(Key, new CacheItem <KeyType>(Key, Value)); } } }
// // Shuts down the AppDomain // static void ShutdownAppDomain() { queue_manager.Dispose(); // This will call Session_End if needed. InternalCache.InvokePrivateCallbacks(); // Kill our application. HttpApplicationFactory.Dispose(); ThreadPool.QueueUserWorkItem(delegate { try { DoUnload(); } catch { } }); }