Example #1
0
        protected virtual string ConvertOperation(DataOperationType type)
        {
            var operation = "COUNT(*)";

            switch (type)
            {
            case DataOperationType.Average:
                operation = "AVG(ResultCount)";
                break;

            case DataOperationType.Sum:
                operation = "SUM(ResultCount)";
                break;

            case DataOperationType.Max:
                operation = "MAX(ResultCount)";
                break;

            case DataOperationType.Min:
                operation = "MIN(ResultCount)";
                break;
            }

            return(operation);
        }
Example #2
0
        private AuditEntryInputDto CreateAuditEntry(EntityEntry entityEntry)
        {
            var entity      = entityEntry.Entity;
            var type        = entity.GetType();
            var displayName = type.ToDescription(); //得到实体上特性
            DataOperationType changeType = DataOperationType.Add;

            switch (entityEntry.State)
            {
            case EntityState.Deleted:
                changeType = DataOperationType.Delete;
                break;

            case EntityState.Modified:
                changeType = DataOperationType.Update;
                break;

            case EntityState.Added:
                changeType = DataOperationType.Add;
                break;
            }
            AuditEntryInputDto auditEntryInput = new AuditEntryInputDto();

            auditEntryInput.KeyValues              = new Dictionary <string, object>();
            auditEntryInput.EntityAllName          = type.FullName;
            auditEntryInput.EntityDisplayName      = displayName;
            auditEntryInput.OperationType          = changeType;
            auditEntryInput.PropertysEntryInputDto = GetAuditPropertys(entityEntry);
            auditEntryInput.KeyValues              = new Dictionary <string, object>()
            {
                { "Id", GetEntityKey(entity) }
            };
            return(auditEntryInput);
        }
Example #3
0
 /// <summary>
 /// 切换数据操作类型的方法
 /// </summary>
 /// <param name="dataOperationType">数据操作类型枚举</param>
 public void SwitchDataOperationType(DataOperationType dataOperationType)
 {
     //设置数据操作类型
     if (SetDataOperationType != null)
     {
         SetDataOperationType(dataOperationType);
     }
 }
Example #4
0
        /// <summary>
        /// 插入操作历史
        /// </summary>
        /// <typeparam name="T">实体类型</typeparam>
        /// <param name="relatedId">相关ID</param>
        /// <param name="value">实体实例</param>
        /// <param name="dataOperationType">操作类型</param>
        /// <param name="user">操作人,为空时代表当前操作人</param>
        /// <param name="description">描述信息(可空)</param>
        /// <param name="transaction">数据库事务</param>
        /// <returns></returns>
        public int Insert <T>(string relatedId, T value, DataOperationType dataOperationType, Util.IUser user, string description = null, IDbTransaction transaction = null)
        {
            return(ProcessInsert(
                       () =>
            {
                OperateHistory item = new OperateHistory();
                if (user == null)
                {
                    Util.ICurrentUserService currentUserService = serviceProvider.GetRequiredService <Util.ICurrentUserService>();
                    user = currentUserService.GetCurrentUser();
                }
                if (user == null || string.IsNullOrEmpty(user.Id))
                {
                    throw new ArgumentNullException("user", "unable to insert operation history");
                }
                //如果操作人是商户用户则写入商户操作历史,否则写入系统操作历史
                if (user is Util.IMerchantUser)
                {
                    if (value == null)
                    {
                        throw new ArgumentNullException("value");
                    }

                    Util.IMerchantUser merchantUser = user as Util.IMerchantUser;
                    if (string.IsNullOrEmpty(merchantUser.MerchantId))
                    {
                        throw new ArgumentNullException("merchantId", "unable to insert operation history");
                    }

                    Type type = typeof(T);
                    item.RelatedId = relatedId;
                    item.AssemblyName = type.Assembly.FullName;
                    item.EntityType = type.FullName;
                    item.OperateTime = DateTime.Now;
                    item.Type = (int)dataOperationType;
                    item.Description = description;
                    item.UserId = merchantUser.Id;
                    item.MerchantId = merchantUser.MerchantId;
                    item.Value = Newtonsoft.Json.JsonConvert.SerializeObject(value);
                    return dal.Insert(item, transaction);
                }
                else
                {
                    return systemOperateHistoryManager.Insert(relatedId, value, dataOperationType, user: user);
                }
            },
                       (log) =>
            {
                log.Properties[nameof(value)] = value;
                log.Properties[nameof(user)] = user;
                log.Properties[nameof(relatedId)] = relatedId;
                log.Properties[nameof(dataOperationType)] = dataOperationType;
                log.Properties[nameof(description)] = description;
            }));
        }
Example #5
0
 /// <summary>
 /// config cache operation
 /// </summary>
 /// <param name="dataOperationType">Data operation type</param>
 /// <param name="cacheOperationConfiguration">Cache operation configuration</param>
 public static void ConfigureDataCacheOperation(DataOperationType dataOperationType, DataCacheOperationConfiguration cacheOperationConfiguration)
 {
     if (cacheOperationConfiguration == null)
     {
         return;
     }
     if (CacheOperationConfigurations == null)
     {
         CacheOperationConfigurations = new Dictionary <DataOperationType, DataCacheOperationConfiguration>();
     }
     CacheOperationConfigurations[dataOperationType] = cacheOperationConfiguration;
 }
Example #6
0
        /// <summary>
        /// 执行操作
        /// </summary>
        /// <typeparam name="TResult">返回类型</typeparam>
        /// <param name="dataOperationType">数据操作类型</param>
        /// <param name="func">执行的方法</param>
        /// <param name="action">添加日志参数的方法</param>
        /// <returns></returns>
        protected TResult Process <TResult>(DataOperationType dataOperationType, Func <TResult> func, Action <LogEventInfo> action = null)
        {
            LogEventInfo log = new LogEventInfo()
            {
                LoggerName = logger.Name
            };

            log.Properties["method"]            = "Process<TResult>(Func<TResult> func, IDictionary arguments, DataOperationType dataOperationType)";
            log.Properties["dataOperationType"] = dataOperationType;
            log.Properties["func.Target"]       = func.Target?.ToString();
            log.Properties["func.Method.Name"]  = func.Method.Name;
            action?.Invoke(log);
            try
            {
                TResult result = func();
                log.Level   = LogLevel.Debug;
                log.Message = "Process success.";
#if DEBUG
                log.Properties["returnValue"] = result;
#endif
                return(result);
            }
            catch (NoneRowModifiedException noneRowModifiedException)
            {
                log.Level     = LogLevel.Warn;
                log.Exception = noneRowModifiedException;
                log.Message   = noneRowModifiedException.Message;
                throw noneRowModifiedException;
            }
            catch (Exception e)
            {
                DataAccessException dataAccessException = new DataAccessException(e.Message, e);
                log.Level     = LogLevel.Warn;
                log.Exception = dataAccessException;
                log.Message   = dataAccessException.Message;
                throw dataAccessException;
            }
            finally
            {
                logger.Log(log);
            }
        }
Example #7
0
 /// <summary>
 /// 插入操作历史
 /// </summary>
 /// <typeparam name="T">实体类型</typeparam>
 /// <param name="relatedId">相关ID</param>
 /// <param name="value">实体实例</param>
 /// <param name="dataOperationType">操作类型</param>
 /// <param name="user">操作人,为空时代表当前操作人</param>
 /// <param name="description">描述信息(可空)</param>
 /// <param name="transaction">数据库事务</param>
 /// <returns></returns>
 public int Insert <T>(string relatedId, T value, DataOperationType dataOperationType, Util.IUser user = null, string description = null, IDbTransaction transaction = null)
 {
     return(ProcessInsert(
                () =>
     {
         OperateHistory item = new OperateHistory();
         if (user == null)
         {
             Util.ICurrentUserService currentUserService = serviceProvider.GetRequiredService <Util.ICurrentUserService>();
             user = currentUserService.GetCurrentUser();
             if (user == null || string.IsNullOrEmpty(user.Id))
             {
                 throw new ArgumentNullException("userId");
             }
         }
         if (value == null)
         {
             throw new ArgumentNullException("value");
         }
         Type type = typeof(T);
         item.RelatedId = relatedId;
         item.AssemblyName = type.Assembly.FullName;
         item.EntityType = type.FullName;
         item.OperateTime = DateTime.Now;
         item.Type = (int)dataOperationType;
         item.Description = description;
         item.UserId = user.Id;
         item.Value = Newtonsoft.Json.JsonConvert.SerializeObject(value);
         return dal.Insert(item, transaction);
     },
                (log) =>
     {
         log.Properties[nameof(value)] = value;
         log.Properties[nameof(user)] = user;
         log.Properties[nameof(relatedId)] = relatedId;
         log.Properties[nameof(dataOperationType)] = dataOperationType;
         log.Properties[nameof(description)] = description;
     }));
 }
Example #8
0
        public async Task AddOperationAsync <TEntity>(ITransaction transaction, DataOperationType operationType, string storeName, TEntity entity)
            where TEntity : IHavePartition <string, string>
        {
            var typedContext = (ReliableStateTransactionContext)transaction.GetContext(this);

            IReliableDictionary <string, TEntity> reliableDictionary = await GetDictionaryAsync <TEntity>(storeName);

            switch (operationType)
            {
            case DataOperationType.Upsert:
                await reliableDictionary.AddOrUpdateAsync(typedContext.ReliableTransaction, entity.Id, entity, (key, oldValue) => entity);

                break;

            case DataOperationType.Remove:
                await reliableDictionary.TryRemoveAsync(typedContext.ReliableTransaction, entity.Id);

                break;
            }

            typedContext.AddOperation(operationType, storeName, entity);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenIZ.Mobile.Core.Exceptions.LocalPersistenceException"/> class.
 /// </summary>
 /// <param name="operation">Operation.</param>
 /// <param name="data">Data.</param>
 /// <param name="causedBy">Caused by.</param>
 public LocalPersistenceException(DataOperationType operation, Object data, Exception causedBy) : base(null, causedBy)
 {
     this.DataObject = data;
     this.Operation  = operation;
 }
Example #10
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="dataOperationType"><see cref="DataOperationType"/>实例</param>
 public DataOperatingEventArgs(DataOperationType dataOperationType)
     : base(dataOperationType)
 {
 }
Example #11
0
 public void AddOperation(DataOperationType operationType, string storeName, IHavePartition <string, string> entity)
 {
     _operations.Add(new DataOperation(operationType, storeName, entity));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenIZ.Mobile.Core.Exceptions.LocalPersistenceException"/> class.
 /// </summary>
 /// <param name="operation">Operation.</param>
 /// <param name="data">Data.</param>
 public LocalPersistenceException(DataOperationType operation, Object data) : this(operation, data, null)
 {
 }
Example #13
0
 public Task AddOperationAsync <TEntity>(ITransaction context, DataOperationType upsert, string storeName, TEntity entity) where TEntity : IHavePartition <string, string>
 {
     throw new NotImplementedException();
 }
Example #14
0
            /// <summary>
            /// Get data operation cache configuration
            /// </summary>
            /// <param name="dataOperationType">Data operation type</param>
            /// <returns>Return Data cache operation configuration</returns>
            public static DataCacheOperationConfiguration GetDataCacheOperationConfiguration(DataOperationType dataOperationType)
            {
                DataCacheOperationConfiguration config = null;

                CacheOperationConfigurations?.TryGetValue(dataOperationType, out config);
                return(config);
            }
 public DataOperation(DataOperationType operationType, string storeName, IHavePartition <string, string> entity)
 {
     Type      = operationType;
     StoreName = storeName;
     Entity    = entity;
 }
Example #16
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="dataOperationType"><see cref="DataOperationType"/>实例</param>
 /// <param name="exception">异常实例</param>
 public DataOperateErrorEventArgs(DataOperationType dataOperationType, Exception exception)
     : base(dataOperationType)
 {
     this.exception = exception;
 }
 public ValidatorOption(DataOperationType operation, string field)
 {
     this.Operation = operation;
     this.Field     = field;
 }
Example #18
0
 public async Task AddOperationAsync <TEntity>(ITransaction transaction, DataOperationType operationType, string storeName, TEntity entity)
     where TEntity : IHavePartition <string, string>
 {
     transaction.GetContext(this).AddOperation(operationType, storeName, entity);
 }
Example #19
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="dataOperationType"><see cref="DataOperationType"/>实例</param>
 protected DataOperationEventArgs(DataOperationType dataOperationType)
 {
     this.dataOperationType = dataOperationType;
 }
Example #20
0
 public virtual Task AddOperationAsync <TEntity>(ITransaction transaction, DataOperationType operationType, string storeName, TEntity entity) where TEntity : IHavePartition <string, string>
 {
     return(_internal.AddOperationAsync(transaction, operationType, storeName, entity));
 }
Example #21
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="returnValue">返回值</param>
 /// <param name="dataOperationType"><see cref="DataOperationType"/>实例</param>
 public DataOperateSuccessEventArgs(DataOperationType dataOperationType, Object returnValue)
     : base(dataOperationType)
 {
     this.returnValue = returnValue;
 }