コード例 #1
0
        /// <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);
        }
コード例 #2
0
        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);
            }
        }
コード例 #3
0
ファイル: AGroup.cs プロジェクト: Deigue/Mutagen
        /// <inheritdoc />
        public TMajor AddNew(FormKey formKey)
        {
            var ret = MajorRecordInstantiator <TMajor> .Activator(formKey, _release);

            InternalCache.Set(ret);
            return(ret);
        }
コード例 #4
0
 /// <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);
     }
 }
コード例 #5
0
ファイル: Cache.cs プロジェクト: wxlevel/petstore-ddd-csharp
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
 /// <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);
     }
 }
コード例 #8
0
        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));
        }
コード例 #9
0
        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);
                }
            }
        }
コード例 #10
0
 /// <summary>
 /// Clears the cache
 /// </summary>
 public virtual void Clear()
 {
     lock (InternalCache)
     {
         InternalCache.Clear();
     }
 }
コード例 #11
0
ファイル: AGroup.cs プロジェクト: Deigue/Mutagen
        /// <inheritdoc />
        public TMajor AddNew()
        {
            var ret = MajorRecordInstantiator <TMajor> .Activator(SourceMod.GetNextFormKey(), _release);

            InternalCache.Set(ret);
            return(ret);
        }
コード例 #12
0
        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;
        }
コード例 #13
0
        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));
        }
コード例 #14
0
        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));
        }
コード例 #15
0
ファイル: Cache.cs プロジェクト: wxlevel/petstore-ddd-csharp
        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);
        }
コード例 #16
0
 /// <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);
     }
 }
コード例 #17
0
        /// <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));
        }
コード例 #18
0
 /// <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);
     }
 }
コード例 #19
0
ファイル: AGroup.cs プロジェクト: Deigue/Mutagen
        /// <inheritdoc />
        public TMajor AddNew(string editorID)
        {
            var ret = MajorRecordInstantiator <TMajor> .Activator(SourceMod.GetNextFormKey(editorID), _release);

            ret.EditorID = editorID;
            InternalCache.Set(ret);
            return(ret);
        }
コード例 #20
0
ファイル: HttpRuntime.cs プロジェクト: raj581/Marvin
 //
 // 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);
 }
コード例 #21
0
        private void FillAdList()
        {
            this.Ads.Clear();

            foreach (var item in InternalCache.GetAds())
            {
                this.Ads.Add(item);
            }
        }
コード例 #22
0
ファイル: CacheService.cs プロジェクト: Qorpent/qorpent.sys
 public object Clear()
 {
     lock (this) {
         var _size = InternalCache.Count;
         InternalCache.Clear();
         LastRefresh = DateTime.MinValue;
         return(_size);
     }
 }
コード例 #23
0
        /// <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);
            }
        }
コード例 #24
0
ファイル: CacheBase.cs プロジェクト: usamabintariq/NCache
        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);
        }
コード例 #25
0
        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));
            }
        }
コード例 #26
0
ファイル: Core.cs プロジェクト: tinmanjk/NetOffice
 /// <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;
         }
     }
 }
コード例 #27
0
ファイル: InMemoryCache.cs プロジェクト: JaCraig/DragonHoard
 /// <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;
 }
コード例 #28
0
 /// <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);
             }
         }
     }
 }
コード例 #29
0
 /// <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));
         }
     }
 }
コード例 #30
0
 //
 // 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 {
         }
     });
 }