/// <summary>
        /// Adds one audit entry to auditInfo entities.
        /// </summary>
        /// <param name="affectedEntityName">Name of the affected entity.</param>
        /// <param name="actionType">Type of the action.</param>
        /// <param name="actionData">The action data.</param>
        private void AddAuditEntryToList(string affectedEntityName, AuditType actionType, string actionData)
        {
            // create a new audit unit
            AuditInfoEntity auditInfo = ConstructAuditInfo(affectedEntityName, actionType, actionData);

            // adds for further DB persist
            AddAuditEntryToList(auditInfo);
        }
Beispiel #2
0
        /// <summary>Creates a new, empty AuditInfoEntity object.</summary>
        /// <returns>A new, empty AuditInfoEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new AuditInfoEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewAuditInfo
            // __LLBLGENPRO_USER_CODE_REGION_END
            return(toReturn);
        }
        public async Task <IResultModel> Add(AuditInfoEntity info)
        {
            if (info == null)
            {
                return(ResultModel.Failed());
            }

            var result = await _repository.AddAsync(info);

            return(ResultModel.Result(result));
        }
Beispiel #4
0
        public async Task <IResultModel> Add(AuditInfoEntity info)
        {
            if (info == null)
            {
                return(ResultModel.Failed());
            }

            int result = await _repository.InsertAsync(info);

            return(ResultModel.Success(result));
        }
Beispiel #5
0
        /// <summary>
        /// Constructs the audit info.
        /// </summary>
        /// <param name="affectedEntityName">Name of the affected entity.</param>
        /// <param name="actionType">Type of the action.</param>
        /// <param name="actionData">The action data.</param>
        /// <returns></returns>
        private AuditInfoEntity ConstructAuditInfo(string affectedEntityName, AuditType actionType, string actionData)
        {
            // create a new audit unit
            AuditInfoEntity auditInfo = new AuditInfoEntity();

            auditInfo.AffectedEntityName = affectedEntityName;
            auditInfo.ActionDateTime     = DateTime.Now;
            auditInfo.AuditActionTypeId  = (int)actionType;
            auditInfo.UserId             = GetCurrentUserID();
            auditInfo.ActionData         = actionData;

            return(auditInfo);
        }
Beispiel #6
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (_filterToUse != null)
     {
         using (DataAccessAdapter adapter = new DataAccessAdapter())
         {
             AuditInfoEntity instance = (AuditInfoEntity)adapter.FetchNewEntity(new AuditInfoEntityFactory(), new RelationPredicateBucket(_filterToUse));
             if (instance != null)
             {
             }
         }
     }
 }
Beispiel #7
0
        private AuditInfoEntity CreateAuditInfo(ActionExecutingContext context)
        {
            try
            {
                var routeValues = context.ActionDescriptor.RouteValues;
                var auditInfo   = new AuditInfoEntity
                {
                    AccountId     = _loginInfo.AccountId,
                    AccountName   = _loginInfo.AccountName,
                    Area          = routeValues["area"] ?? "",
                    Controller    = routeValues["controller"],
                    Action        = routeValues["action"],
                    Parameters    = JsonSerializer.Serialize(context.ActionArguments),
                    Platform      = _loginInfo.Platform,
                    IP            = _loginInfo.IP,
                    ExecutionTime = DateTime.Now
                };

                //获取模块的名称
                if (auditInfo.Area.NotNull())
                {
                    auditInfo.Module = _moduleCollection.FirstOrDefault(m => m.Code.EqualsIgnoreCase(auditInfo.Area))?.Name;
                }

                var controllerDescriptor = _mvcHelper.GetAllController().FirstOrDefault(m => m.Area.NotNull() && m.Area.EqualsIgnoreCase(auditInfo.Area) && m.Name.EqualsIgnoreCase(auditInfo.Controller));
                if (controllerDescriptor != null)
                {
                    auditInfo.ControllerDesc = controllerDescriptor.Description;

                    var actionDescription = _mvcHelper.GetAllAction().FirstOrDefault(m => m.Controller == controllerDescriptor && m.Name.EqualsIgnoreCase(auditInfo.Action));
                    if (actionDescription != null)
                    {
                        auditInfo.ActionDesc = actionDescription.Description;
                    }
                }

                //记录浏览器UA
                if (_loginInfo.Platform == Platform.Web)
                {
                    auditInfo.BrowserInfo = context.HttpContext.Request.Headers["User-Agent"];
                }

                return(auditInfo);
            }
            catch (Exception ex)
            {
                _logger.LogError("审计日志创建异常:{@ex}", ex);
            }

            return(null);
        }
Beispiel #8
0
        /// <summary>
        /// Audits the successful delete of an entity from the database
        /// </summary>
        /// <param name="entity">The entity which was deleted.</param>
        /// <remarks>As the entity passed in was deleted succesfully, reading values from the
        /// passed in entity is only possible in this routine. After this call, the
        /// state of the entity will be reset to Deleted again and reading the fields
        /// will result in an exception. It's also recommended not to reference
        /// the passed in entity in any audit entity you might want to persist as the entity doesn't
        /// exist anymore in the database.</remarks>
        public override void AuditDeleteOfEntity(IEntityCore entity)
        {
            // Create a new audit unit
            // Don't use OrderAuditInfo because the entity will be deleted
            // so wont be a valid reference to it.
            AuditInfoEntity auditInfo = new AuditInfoEntity();

            auditInfo.AffectedEntityName = entity.LLBLGenProEntityName;
            auditInfo.ActionDateTime     = DateTime.Now;
            auditInfo.AuditActionTypeId  = (int)AuditType.DeleteOfEntity;
            auditInfo.UserId             = GetCurrentUserID();
            auditInfo.ActionData         = GetPrimaryKeyValueFromOrderEntity(entity).ToString();

            // adds for further DB persist
            _orderAuditInfoEntities.Add(auditInfo);
        }
Beispiel #9
0
        /// <summary>
        /// Audits the succesful direct update of entities in the database.
        /// </summary>
        /// <param name="entity">The entity with the changed values which is used to produce the update
        /// query.</param>
        /// <param name="filter">The filter to filter out the entities to update. Can be null and can be an
        /// IPredicateExpression.</param>
        /// <param name="relations">The relations to use with the filter. Can be null.</param>
        /// <param name="numberOfEntitiesUpdated">The number of entities updated.</param>
        public override void AuditDirectUpdateOfEntities(IEntityCore entity, IPredicate filter,
                                                         IRelationCollection relations, int numberOfEntitiesUpdated)
        {
            // avoid to audit into AuditInfoEntity (this would create an overflow effect). This is necessary if this auditor is injected into
            // all entities, thus also in the AuditInfoEntity
            if (entity is AuditInfoEntity)
            {
                return;
            }

            // get filter's queryText
            string strFilter = filter.ToQueryText();

            // construct parameters info
            string strParameters = string.Empty;

            foreach (IDataParameter param in filter.Parameters)
            {
                strParameters += (param.ParameterName + "=" + param.Value.ToString() + ". ");
            }

            // construct update-new-values info of the direct update
            string updatedFields = string.Empty;

            for (int i = 0; i < entity.Fields.Count; i++)
            {
                if (entity.Fields.GetIsChanged(i))
                {
                    object value = entity.Fields.GetCurrentValue(i);
                    if (value == null)
                    {
                        value = "<null>";
                    }
                    updatedFields += (entity.Fields.GetFieldInfo(i).Name + "=" + value.ToString() + ". ");
                }
            }

            // construc audit info entity
            AuditInfoEntity auditInfo = ConstructAuditInfo(
                entity.LLBLGenProEntityName,
                AuditType.DirectUpdateOfEntities,
                string.Format("updatedFields: {0}  updateFilter: {1}.  filterParameters: {2}", updatedFields, strFilter, strParameters));

            // add to auditinfo-to-save list
            AddAuditEntryToList(auditInfo);
        }
Beispiel #10
0
    /// <summary>
    /// Eventhandler for the PerformWork event on the _AuditInfoDS datasourcecontrol
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void _AuditInfoDS_PerformWork(object sender, PerformWorkEventArgs2 e)
    {
        // as we're using a formview, there's just 1 entity in the UoW.
        AuditInfoEntity           entityToProcess  = null;
        List <UnitOfWorkElement2> elementsToInsert = e.Uow.GetEntityElementsToInsert();

        if (elementsToInsert.Count > 0)
        {
            // it's an insert operation. grab the entity so we can determine the PK later on.
            entityToProcess = (AuditInfoEntity)elementsToInsert[0].Entity;
        }
        using (DataAccessAdapter adapter = new DataAccessAdapter())
        {
            e.Uow.Commit(adapter, true);
        }
        if (entityToProcess != null)
        {
            // store the PK values so a redirect can use these.
            _pkValuesAfterInsert = "&AuditInfoId=" + entityToProcess.AuditInfoId;
        }
    }
Beispiel #11
0
        private AuditInfoEntity CreateAuditInfo(ActionExecutingContext context)
        {
            var routeValues = context.ActionDescriptor.RouteValues;
            var auditInfo   = new AuditInfoEntity
            {
                AccountId     = _loginInfo.AccountId,
                Area          = routeValues["area"] ?? "",
                Controller    = routeValues["controller"],
                Action        = routeValues["action"],
                Parameters    = JsonConvert.SerializeObject(context.ActionArguments),
                Platform      = _loginInfo.Platform,
                IP            = _loginInfo.IP,
                ExecutionTime = DateTime.Now
            };

            var controllerDescriptor = _mvcHelper.GetAllController().FirstOrDefault(m =>
                                                                                    m.Area.EqualsIgnoreCase(auditInfo.Area) && m.Name.EqualsIgnoreCase(auditInfo.Controller));

            if (controllerDescriptor != null)
            {
                auditInfo.ControllerDesc = controllerDescriptor.Description;

                var actionDescription = _mvcHelper.GetAllAction().FirstOrDefault(m =>
                                                                                 m.Controller == controllerDescriptor && m.Name.EqualsIgnoreCase(auditInfo.Action));
                if (actionDescription != null)
                {
                    auditInfo.ActionDesc = actionDescription.Description;
                }
            }

            //记录浏览器UA
            if (_loginInfo.Platform == Platform.Web)
            {
                auditInfo.BrowserInfo = context.HttpContext.Request.Headers["User-Agent"];
            }

            return(auditInfo);
        }
Beispiel #12
0
        /// <summary>
        /// Audits the successful delete of an entity from the database
        /// </summary>
        /// <param name="entity">The entity which was deleted.</param>
        /// <remarks>As the entity passed in was deleted succesfully, reading values from the
        /// passed in entity is only possible in this routine. After this call, the
        /// state of the entity will be reset to Deleted again and reading the fields
        /// will result in an exception. It's also recommended not to reference
        /// the passed in entity in any audit entity you might want to persist as the entity doesn't
        /// exist anymore in the database.</remarks>
        public override void AuditDeleteOfEntity(IEntityCore entity)
        {
            // avoid to audit into AuditInfoEntity (this would create an overflow effect). This is necessary if this auditor is injected into
            // all entities, thus also in the AuditInfoEntity
            if (entity is AuditInfoEntity)
            {
                return;
            }

            // Create a new audit unit
            // Don't use OrderAuditInfo because the entity will be deleted
            // so wont be a valid reference to it.
            AuditInfoEntity auditInfo = new AuditInfoEntity();

            auditInfo.AffectedEntityName = entity.LLBLGenProEntityName;
            auditInfo.ActionDateTime     = DateTime.Now;
            auditInfo.AuditActionTypeId  = (int)AuditType.DeleteOfEntity;
            auditInfo.UserId             = GetCurrentUserID();
            auditInfo.ActionData         = GetPrimaryKeyValueFromOrderEntity(entity).ToString();

            // adds for further DB persist
            _orderAuditInfoEntities.Add(auditInfo);
        }
Beispiel #13
0
        private AuditInfoEntity CreateAuditInfo(ActionExecutingContext context)
        {
            var routeValues = context.ActionDescriptor.RouteValues;
            var auditInfo   = new AuditInfoEntity
            {
                AccountId     = _loginInfo.AccountId,
                Area          = routeValues["area"],
                Controller    = routeValues["controller"],
                Action        = routeValues["action"],
                Parameters    = JsonConvert.SerializeObject(context.ActionArguments),
                Platform      = _loginInfo.Platform,
                IP            = _loginInfo.IP,
                ExecutionTime = DateTime.Now
            };

            //记录浏览器UA
            if (_loginInfo.Platform == Platform.Web)
            {
                auditInfo.BrowserInfo = context.HttpContext.Request.Headers["User-Agent"];
            }

            return(auditInfo);
        }
        /// <summary>
        /// Saves data from changed fields in JSON.
        /// Enables to track entity history.
        /// </summary>
        private void AuditInfo(IEntity2 entity, AuditInfoActionTypeEnum auditInfoActionTypeEnum)
        {
            AuditInfoEntity auditInfo = new AuditInfoEntity();

            auditInfo.ActionDateTime        = DateTime.Now;
            auditInfo.AuditInfoActionTypeId = (long)auditInfoActionTypeEnum;
            auditInfo.EntityId = (long)(EntityEnum)Enum.Parse(typeof(EntityEnum), entity.LLBLGenProEntityName.Replace("Entity", ""));
            auditInfo.UserId   = this.UserId.Value;

            System.Collections.Generic.Dictionary <string, object> fieldsDictionary = new System.Collections.Generic.Dictionary <string, object>();

            foreach (IEntityField2 field in entity.Fields)
            {
                string concurrencyFieldName = ConfigurationManager.AppSettings["ConcurrencyFieldName"];
                // Saves all fields if is not update.
                // If it is update, saves only changed fileds.
                if (field.IsPrimaryKey)
                {
                    // primary key is saved in separately
                    auditInfo.PrimaryKeyValue = (long)field.CurrentValue;
                }
                else if (AuditInfoActionTypeEnum.Delete == auditInfoActionTypeEnum)
                {
                    // nothing, you can recreate entity from other audit infos for this entity
                }
                else if ((auditInfoActionTypeEnum != AuditInfoActionTypeEnum.Update || field.IsChanged) &&
                         !field.IsPrimaryKey &&
                         field.Name != concurrencyFieldName)
                {
                    fieldsDictionary.Add(field.Name, field.CurrentValue);
                }
            }

            auditInfo.JsonData = Newtonsoft.Json.JsonConvert.SerializeObject(fieldsDictionary);

            this.SaveEntity(auditInfo, false, false);
        }
Beispiel #15
0
 /// <summary>
 /// Adds one audit entry to auditInfo entities.
 /// </summary>
 /// <param name="auditInfo">The audit info.</param>
 private void AddAuditEntryToList(AuditInfoEntity auditInfo)
 {
     // adds for further DB persist
     _auditInfoEntities.Add(auditInfo);
 }
 /// <summary>
 /// Direct persists the audit info. This method is used by methods that don't belong to a transaction
 /// like AuditLoadOfEntity, AuditDirectDeleteOfEntities and AuditDirectUpdateOfEntites
 /// </summary>
 /// <param name="auditInfo">The audit info.</param>
 private void DirectPersistAuditInfo(AuditInfoEntity auditInfo)
 {
     auditInfo.Save();
 }