コード例 #1
0
 /// <summary>
 /// Called before a remove database command execute
 /// </summary>
 /// <typeparam name="T">Data type</typeparam>
 /// <param name="removeByQueryContext">Remove by query context</param>
 /// <returns>Return policy result</returns>
 public virtual StartingResult OnRemoveByQueryStarting <T>(RemoveByQueryContext <T> removeByQueryContext) where T : BaseEntity <T>, new()
 {
     if (removeByQueryContext == null)
     {
         return(StartingResult.Success($"Parameter:{nameof(removeByQueryContext)} is null"));
     }
     try
     {
         RemoveCacheData(removeByQueryContext.Datas);
     }
     catch (Exception ex)
     {
         return(DataCacheBehavior.GetStartingResult(DataCacheOperation.RemoveData, ex));
     }
     return(StartingResult.Success());
 }
コード例 #2
0
        /// <summary>
        /// Called before a update database command execute
        /// </summary>
        /// <typeparam name="T">Data type</typeparam>
        /// <param name="updateAllContext">Update all context</param>
        /// <returns>Return policy result</returns>
        public virtual StartingResult OnUpdateAllStarting <T>(UpdateAllContext <T> updateAllContext) where T : BaseEntity <T>, new()
        {
            if (updateAllContext == null)
            {
                return(StartingResult.Success($"Parameter:{nameof(updateAllContext)} is null"));
            }
            var entityType = typeof(T);

            try
            {
                RemoveCacheDataByType(entityType);
            }
            catch (Exception ex)
            {
                return(DataCacheBehavior.GetStartingResult(DataCacheOperation.RemoveData, ex));
            }
            return(StartingResult.Success());
        }
コード例 #3
0
 /// <summary>
 /// Called before a database command execute
 /// </summary>
 /// <param name="addDataContext">Add data context</param>
 /// <returns>Return the policy result</returns>
 public virtual StartingResult OnAddStarting <T>(AddDataContext <T> addDataContext) where T : BaseEntity <T>, new()
 {
     if (addDataContext == null)
     {
         return(StartingResult.Success($"Parameter:{nameof(addDataContext)} is null"));
     }
     try
     {
         AddCacheData(new QueryDataCallbackContext <T>()
         {
             Datas = addDataContext.Datas,
             Query = addDataContext.DatabaseCommand?.Query
         });
     }
     catch (Exception ex)
     {
         return(DataCacheBehavior.GetStartingResult(DataCacheOperation.AddData, ex));
     }
     return(StartingResult.Success());
 }
コード例 #4
0
        /// <summary>
        /// Called before a update database command execute
        /// </summary>
        /// <typeparam name="T">Data type</typeparam>
        /// <param name="updateByQueryContext">Update by query context</param>
        /// <returns>Return policy result</returns>
        public virtual StartingResult OnUpdateByQueryStarting <T>(UpdateByQueryContext <T> updateByQueryContext) where T : BaseEntity <T>, new()
        {
            if (updateByQueryContext == null)
            {
                return(StartingResult.Success($"Parameter:{nameof(updateByQueryContext)} is null"));
            }
            if (updateByQueryContext.GetDatasProxy == null)
            {
                return(StartingResult.Success($"Parameter:{nameof(UpdateByQueryContext<T>.GetDatasProxy)} is null"));
            }
            var datas = updateByQueryContext.GetDatasProxy(updateByQueryContext.Query);

            try
            {
                RemoveCacheData(datas);
            }
            catch (Exception ex)
            {
                return(DataCacheBehavior.GetStartingResult(DataCacheOperation.RemoveData, ex));
            }
            return(StartingResult.Success());
        }