Ejemplo n.º 1
0
 /// <summary>
 /// Gets the count of items that would be returned by the query
 /// </summary>
 /// <param name="query">
 /// The query.
 /// </param>
 /// <returns>
 /// The <see cref="int"/>.
 /// </returns>
 internal override int Count(IQuery <IAuditLog> query)
 {
     using (var repository = RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork()))
     {
         return(repository.Count(query));
     }
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an audit record and saves it to the database
        /// </summary>
        /// <param name="entityKey">
        /// The entity key.
        /// </param>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="extendedData">
        /// The extended data.
        /// </param>
        /// <param name="isError">
        /// Designates whether or not this is an error log record
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IAuditLog"/>.
        /// </returns>
        public IAuditLog CreateAuditLogWithKey(Guid?entityKey, Guid?entityTfKey, string message, ExtendedDataCollection extendedData, bool isError = false, bool raiseEvents = true)
        {
            var auditLog = new AuditLog()
            {
                EntityKey    = entityKey,
                EntityTfKey  = entityTfKey,
                Message      = message,
                ExtendedData = extendedData,
                IsError      = isError
            };

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <IAuditLog>(auditLog), this))
                {
                    auditLog.WasCancelled = true;
                    return(auditLog);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateAuditLogRepository(uow))
                {
                    repository.AddOrUpdate(auditLog);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <IAuditLog>(auditLog), this);

            return(auditLog);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves a collection of <see cref="IAuditLog"/>
        /// </summary>
        /// <param name="auditLogs">
        /// The collection of <see cref="IAuditLog"/>s to be saved
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        public void Save(IEnumerable <IAuditLog> auditLogs, bool raiseEvents = true)
        {
            var auditLogsArray = auditLogs as IAuditLog[] ?? auditLogs.ToArray();

            if (raiseEvents)
            {
                Saving.RaiseEvent(new SaveEventArgs <IAuditLog>(auditLogsArray), this);
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateAuditLogRepository(uow))
                {
                    foreach (var auditLog in auditLogsArray)
                    {
                        repository.AddOrUpdate(auditLog);
                    }

                    uow.Commit();
                }
            }

            Saved.RaiseEvent(new SaveEventArgs <IAuditLog>(auditLogsArray), this);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Gets an <see cref="IAuditLog"/> by it's key
 /// </summary>
 /// <param name="key">
 /// The key.
 /// </param>
 /// <returns>
 /// The <see cref="IAuditLog"/>.
 /// </returns>
 public override IAuditLog GetByKey(Guid key)
 {
     using (var repository = RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork()))
     {
         return(repository.Get(key));
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Saves a collection of <see cref="INote"/>
        /// </summary>
        /// <param name="notes">
        /// The collection of <see cref="INote"/>s to be saved
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        public void Save(IEnumerable <INote> notes, bool raiseEvents = true)
        {
            var notesArray = notes as INote[] ?? notes.ToArray();

            if (raiseEvents)
            {
                Saving.RaiseEvent(new SaveEventArgs <INote>(notesArray), this);
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateNoteRepository(uow))
                {
                    foreach (var note in notesArray)
                    {
                        repository.AddOrUpdate(note);
                    }

                    uow.Commit();
                }
            }

            Saved.RaiseEvent(new SaveEventArgs <INote>(notesArray), this);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a note and saves it to the database
        /// </summary>
        /// <param name="entityKey">
        /// The entity key.
        /// </param>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="message">
        /// The message.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="INote"/>.
        /// </returns>
        public INote CreateNoteWithKey(Guid entityKey, Guid entityTfKey, string message, bool raiseEvents = true)
        {
            var note = CreateNote(entityKey, entityTfKey, message, raiseEvents);

            if (raiseEvents)
            {
                if (Creating.IsRaisedEventCancelled(new Events.NewEventArgs <INote>(note), this))
                {
                    ((Note)note).WasCancelled = true;
                    return(note);
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateNoteRepository(uow))
                {
                    repository.AddOrUpdate(note);
                    uow.Commit();
                }
            }

            Created.RaiseEvent(new Events.NewEventArgs <INote>(note), this);

            return(note);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AuditLogService"/> class.
        /// </summary>
        /// <param name="provider">
        /// The <see cref="IDatabaseUnitOfWorkProvider"/>
        /// </param>
        /// <param name="repositoryFactory">
        /// The <see cref="RepositoryFactory"/>
        /// </param>
        public AuditLogService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory)
        {
            Mandate.ParameterNotNull(provider, "provider");
            Mandate.ParameterNotNull(repositoryFactory, "repositoryFactory");

            _uowProvider       = provider;
            _repositoryFactory = repositoryFactory;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Gets a <see cref="Page{IAuditLog}"/>
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="Page{TEntity}"/>.
        /// </returns>
        public override Page <IAuditLog> GetPage(long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Descending)
        {
            var query = Persistence.Querying.Query <IAuditLog> .Builder.Where(x => x.Key != Guid.Empty);

            using (var repository = RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork()))
            {
                return(repository.GetPage(page, itemsPerPage, query, ValidateSortByField(sortBy), sortDirection));
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets a collection of <see cref="IAuditLog"/> for an entity type
        /// </summary>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="Page{IAuditLog}"/>.
        /// </returns>
        public Page <IAuditLog> GetAuditLogsByEntityTfKey(Guid entityTfKey, long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Descending)
        {
            using (var repository = RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork()))
            {
                var query = Persistence.Querying.Query <IAuditLog> .Builder.Where(x => x.EntityTfKey == entityTfKey);

                return(repository.GetPage(page, itemsPerPage, query, ValidateSortByField(sortBy), sortDirection));
            }
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Gets a collection of <see cref="IAuditLog"/> for a particular entity
        /// </summary>
        /// <param name="entityKey">
        /// The entity key.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IAuditLog}"/>.
        /// </returns>
        public IEnumerable <IAuditLog> GetAuditLogsByEntityKey(Guid entityKey)
        {
            using (var repository = RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork()))
            {
                var query = Persistence.Querying.Query <IAuditLog> .Builder.Where(x => x.EntityKey == entityKey);

                return(repository.GetByQuery(query));
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// The get paged keys.
        /// </summary>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="Page{Guid}"/>.
        /// </returns>
        internal override Page <Guid> GetPagedKeys(long page, long itemsPerPage, string sortBy = "", SortDirection sortDirection = SortDirection.Descending)
        {
            var query = Persistence.Querying.Query <IAuditLog> .Builder.Where(x => x.Key != Guid.Empty);

            return(GetPagedKeys(
                       RepositoryFactory.CreateAuditLogRepository(UowProvider.GetUnitOfWork()),
                       query,
                       page,
                       itemsPerPage,
                       ValidateSortByField(sortBy),
                       sortDirection));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Deletes a <see cref="IAuditLog"/>
        /// </summary>
        /// <param name="auditLog">
        /// The <see cref="IAuditLog"/> to be deleted
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        public void Delete(IAuditLog auditLog, bool raiseEvents = true)
        {
            if (raiseEvents)
            {
                if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IAuditLog>(auditLog), this))
                {
                    ((AuditLog)auditLog).WasCancelled = true;
                    return;
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateAuditLogRepository(uow))
                {
                    repository.Delete(auditLog);
                    uow.Commit();
                }
            }

            Deleted.RaiseEvent(new DeleteEventArgs <IAuditLog>(auditLog), this);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Deletes a <see cref="INote"/>
        /// </summary>
        /// <param name="note">
        /// The <see cref="INote"/> to be deleted
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        public void Delete(INote note, bool raiseEvents = true)
        {
            if (raiseEvents)
            {
                if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <INote>(note), this))
                {
                    ((Note)note).WasCancelled = true;
                    return;
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateNoteRepository(uow))
                {
                    repository.Delete(note);
                    uow.Commit();
                }
            }

            Deleted.RaiseEvent(new DeleteEventArgs <INote>(note), this);
        }
Ejemplo n.º 14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AuditLogService"/> class.
 /// </summary>
 /// <param name="provider">
 /// The provider.
 /// </param>
 /// <param name="repositoryFactory">
 /// The repository factory.
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 /// <param name="eventMessagesFactory">
 /// The event messages factory.
 /// </param>
 public AuditLogService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory)
     : base(provider, repositoryFactory, logger, eventMessagesFactory)
 {
 }
Ejemplo n.º 15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AuditLogService"/> class.
 /// </summary>
 /// <param name="provider">
 /// The <see cref="IDatabaseUnitOfWorkProvider"/>
 /// </param>
 /// <param name="repositoryFactory">
 /// The <see cref="RepositoryFactory"/>
 /// </param>
 /// <param name="logger">
 /// The logger.
 /// </param>
 public AuditLogService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger)
     : this(provider, repositoryFactory, logger, new TransientMessageFactory())
 {
 }