Ejemplo n.º 1
0
        /// <summary>
        /// Finds a collection of events with the given primary key value.
        /// </summary>
        /// <param name="id">Event ID (Primary Key).</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual async Task <IList <EventResult> > FindAllByIdAsync(int id, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            var list       = new List <EventResult>();
            var connection = Context.Database.Connection;

            try
            {
                await connection.OpenAsync(cancellationToken);

                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "Logging.GetEventsById";
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add(DbParameters.Value("Id", id));

                    using (var reader = await command.ExecuteReaderAsync(cancellationToken))
                    {
                        var mapper = new LoggingEventResultMapper(reader);
                        while (reader.Read())
                        {
                            list.Add(mapper.Translate());
                        }
                    }
                }
            }
            finally
            {
                connection.Close();
            }

            return(list);
        }
Ejemplo n.º 2
0
        //
        // IEventBulkOperations
        //

        /// <summary>
        /// Gets a group of primary keys of events with the given values.
        /// </summary>
        /// <param name="ownerId">Owner ID (Foreign Key)</param>
        /// <param name="categoryId">Category ID (Foreign Key)</param>
        /// <param name="projectId">Project ID (Foreign Key)</param>
        /// <param name="actionId">Action ID (Foreign Key)</param>
        /// <param name="pageId">Page ID (Foreign Key)</param>
        /// <param name="contactState">Contact state flag</param>
        /// <param name="dateFrom"></param>
        /// <param name="dateTo"></param>
        /// <param name="emails">A collection of contact emails.</param>
        /// <param name="clients">A collection of Client IDs.</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual async Task <IList <int> > GetIdsAsync(
            int userId,
            int?categoryId,
            DateTime?dateFrom,
            DateTime?dateTo,
            ObjectType?objectType,
            int?objectId,
            int?contactId,
            ObjectState?contactState,
            int?projectId,
            string customUri,
            IEnumerable <string> emails,
            IEnumerable <string> clients,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            return(await Context.Database.SqlQuery <int>(
                       "SELECT Id FROM Logging.GetEventIds(@UserId, @CategoryId, @DateFrom, @DateTo, @ObjectTypeId, @ObjectId, @ContactId, @ContactState, @ProjectId, @CustomUri, @Emails, @Clients)",
                       DbParameters.Value("UserId", userId),
                       DbParameters.Value("CategoryId", categoryId),
                       DbParameters.Value("DateFrom", dateFrom),
                       DbParameters.Value("DateTo", dateTo),
                       DbParameters.Value("ObjectTypeId", objectType),
                       DbParameters.Value("ObjectId", objectId),
                       DbParameters.Value("ContactId", contactId),
                       DbParameters.Value("ContactState", contactState),
                       DbParameters.Value("ProjectId", projectId),
                       DbParameters.Value("CustomUri", customUri),
                       DbParameters.EmailList("Emails", emails),
                       DbParameters.ClientList("Clients", clients))
                   .ToListAsync(cancellationToken));
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Sets the event that correlates to the given event.
 /// </summary>
 /// <param name="id">The Event ID (Primary Key).</param>
 /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
 /// <returns>
 /// A task that represents the asynchronous operation.
 /// </returns>
 public virtual Task SetCorrelationAsync(int id, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     return(Context.Database.ExecuteSqlCommandAsync(
                "Logging.SetEventCorrelation @Id",
                cancellationToken,
                DbParameters.Value("Id", id)));
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Moves the playlist item at the specified index to a new location in the database.
 /// </summary>
 /// <param name="id">The unique identifier from the data source for the playlist item.</param>
 /// <param name="sortOrderId">The new location of the playlist item in the database.</param>
 /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
 /// <returns>
 /// A task that represents the asynchronous operation.
 /// </returns>
 public Task MoveItemAsync(int id, int sortOrderId, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     return(_context.Database.ExecuteSqlCommandAsync(
                string.Format("{0}.MovePlaylistItem @Id, @SortOrderId", DbSchema.Media),
                cancellationToken,
                DbParameters.Value("Id", id),
                DbParameters.Value("SortOrderId", sortOrderId)));
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Marks events as read or unread.
 /// </summary>
 public virtual Task SetLastReadDateAsync(int userId, DateTime lastReadDate, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     return(Context.Database.ExecuteSqlCommandAsync(
                "Logging.SetEventLastReadDate @UserId, @LastReadDate",
                cancellationToken,
                DbParameters.Value("UserId", userId),
                DbParameters.Value("LastReadDate", lastReadDate)));
 }
Ejemplo n.º 6
0
 /// <summary>
 /// Finishes an event.
 /// </summary>
 /// <param name="id">The unique identifier for the HTTP request.</param>
 public virtual Task SetFinishDateAsync(int id, DateTime?finishDate, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     return(Context.Database.ExecuteSqlCommandAsync(
                "Logging.SetEventFinishDate @Id, @FinishDate",
                cancellationToken,
                DbParameters.Value("Id", id),
                DbParameters.Value("FinishDate", finishDate)));
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Sets the given contact for all the events.
        /// </summary>
        /// <param name="anonymId">The Anonymous User ID to identify the event(s).</param>
        /// <param name="contactId">The Contact ID (Foreign Key) to associate with the event(s).</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual Task BulkSetContactsAsync(Guid anonymId, int contactId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            return(Context.Database.ExecuteSqlCommandAsync(
                       "Logging.SetEventContacts @AnonymId, @ContactId",
                       cancellationToken,
                       DbParameters.Value("AnonymId", anonymId),
                       DbParameters.Value("ContactId", contactId)));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// Gets the number of unread web events.
 /// </summary>
 /// <param name="ownerId">The unqiue identifier of the <see cref="IdentityUser" />.</param>
 /// <returns>
 /// The number of unread web events.
 /// </returns>
 public virtual Task <int> GetUnreadCountAsync(int ownerId, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     return(Context.Database.SqlQuery <int>(
                "DECLARE @ReturnValue int;" +
                "EXEC @ReturnValue = Logging.GetUnreadEventCount @OwnerId;" +
                "SELECT @ReturnValue",
                DbParameters.Value("OwnerId", ownerId))
            .FirstAsync(cancellationToken));
 }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets the given category for a group of events.
        /// </summary>
        /// <param name="userId">The User ID (Foreign Key).</param>
        /// <param name="eventIds">A collection of primary keys of events.</param>
        /// <param name="categoryId">The Category ID (Foreign Key).</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual Task BulkSetCategoriesAsync(int userId, IEnumerable <int> eventIds, int?categoryId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            return(Context.Database.ExecuteSqlCommandAsync(
                       "Logging.SetEventCategories @UserId, @EventIds, @CategoryId",
                       cancellationToken,
                       DbParameters.Value("UserId", userId),
                       DbParameters.IdList("EventIds", eventIds),
                       DbParameters.Value("CategoryId", categoryId)));
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Deletes all <see cref="AccessRuleItem" />s from the specified <paramref name="item" />.
        /// </summary>
        /// <param name="objectType">The type of the shared object to be found.</param>
        /// <param name="objectId">The primary key for the shared object to be found.</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual async Task <ValidationResult> RemoveAccessRulesAsync(AccessObjectType objectType, int objectId, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            await Context.Database.ExecuteSqlCommandAsync(
                $"{DbSchema.Security}.DeleteAccessRules @ObjectTypeId, @ObjectId",
                cancellationToken,
                DbParameters.Value("ObjectTypeId", objectType),
                DbParameters.Value("ObjectId", objectId));

            return(ValidationResult.Success);
        }
Ejemplo n.º 11
0
 /// <summary>
 /// Deletes a group of events.
 /// </summary>
 /// <param name="userId">The User ID (Foreign Key).</param>
 /// <param name="eventIds">A collection of primary keys of events.</param>
 /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
 /// <returns>
 /// A task that represents the asynchronous operation.
 /// </returns>
 public virtual Task BulkDeleteAsync(int userId, IEnumerable <int> eventIds, CancellationToken cancellationToken)
 {
     cancellationToken.ThrowIfCancellationRequested();
     ThrowIfDisposed();
     if (eventIds == null)
     {
         throw new ArgumentNullException("eventIds");
     }
     return(Context.Database.ExecuteSqlCommandAsync(
                "Logging.DeleteEvents @UserId, @EventIds",
                cancellationToken,
                DbParameters.Value("UserId", userId),
                DbParameters.IdList("EventIds", eventIds)));
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Filters a sequences of items based on predicates.
 /// </summary>
 public static DbSqlQuery <ProjectAction> QueryById(this DbSet <ProjectAction> query, int id)
 {
     return(query.SqlQuery("Project.GetActionById @Id", DbParameters.Value("Id", id)));
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Finds a collection of events with the given values
        /// </summary>
        /// <param name="ownerId">Owner ID (Foreign Key)</param>
        /// <param name="categoryId">Category ID (Foreign Key)</param>
        /// <param name="projectId">Project ID (Foreign Key)</param>
        /// <param name="actionId">Action ID (Foreign Key)</param>
        /// <param name="pageId">Page ID (Foreign Key)</param>
        /// <param name="contactState">Contact state flag</param>
        /// <param name="dateFrom"></param>
        /// <param name="dateTo"></param>
        /// <param name="emails">A collection of contact emails.</param>
        /// <param name="clients">A collection of Client IDs.</param>
        /// <param name="pageIndex">The index of the page of results to return. Use 1 to indicate the first page.</param>
        /// <param name="pageSize">The size of the page of results to return. <paramref name="pageIndex" /> is non-zero-based.</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual async Task <ListResult <EventResult> > FindAllAsync(
            int userId,
            int?categoryId,
            DateTime?dateFrom,
            DateTime?dateTo,
            ObjectType?objectType,
            int?objectId,
            int?contactId,
            ObjectState?contactState,
            int?projectId,
            string customUri,
            IEnumerable <string> emails,
            IEnumerable <string> clients,
            int pageIndex,
            int pageSize,
            CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();

            var listBuilder = ImmutableArray.CreateBuilder <EventResult>();
            var total       = 0;
            var connection  = Context.Database.Connection;

            try
            {
                await connection.OpenAsync(cancellationToken);

                // This solution has a considerable effect on performance avoiding EF Code First
                // object materialization. Log queries are performance critical. Do not be lazy :-)
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = "Logging.GetEvents";
                    command.CommandType = CommandType.StoredProcedure;

                    command.Parameters.Add(DbParameters.Value("UserId", userId));
                    command.Parameters.Add(DbParameters.Value("CategoryId", categoryId));
                    command.Parameters.Add(DbParameters.Value("DateFrom", dateFrom));
                    command.Parameters.Add(DbParameters.Value("DateTo", dateTo));
                    command.Parameters.Add(DbParameters.Value("ObjectTypeId", objectType));
                    command.Parameters.Add(DbParameters.Value("ObjectId", objectId));
                    command.Parameters.Add(DbParameters.Value("ContactId", contactId));
                    command.Parameters.Add(DbParameters.Value("ContactStateId", contactState));
                    command.Parameters.Add(DbParameters.Value("ProjectId", projectId));
                    command.Parameters.Add(DbParameters.Value("CustomUri", customUri));
                    command.Parameters.Add(DbParameters.EmailList("Emails", emails));
                    command.Parameters.Add(DbParameters.ClientList("Clients", clients));
                    command.Parameters.Add(DbParameters.Value("PageIndex", pageIndex));
                    command.Parameters.Add(DbParameters.Value("PageSize", pageSize));
                    command.Parameters.Add(DbParameters.Value("TotalItemCount", 50000));

                    using (var reader = await command.ExecuteReaderAsync(cancellationToken))
                    {
                        var mapper = new LoggingEventResultMapper(reader);

                        // Read the first record to get the total number of events before paging is applied.
                        // This stored procedure uses an optimized CTE query, however, a side effect of
                        // this solution is that the total number of records is presented in each row.
                        if (!reader.Read() || (total = mapper.GetTotal()) <= 0)
                        {
                            return(ListResult <EventResult> .Empty);
                        }
                        do
                        {
                            listBuilder.Add(mapper.Translate());
                        }while (reader.Read());
                    }
                }
            }
            finally
            {
                connection.Close();
            }
            return(ListResult.Create(listBuilder.ToImmutable(), total));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Deletes a site.
        /// </summary>
        /// <param name="file">The file to delete.</param>
        /// <param name="cancellationToken">A token to observe while waiting for the task to complete.</param>
        /// <returns>
        /// A task that represents the asynchronous operation.
        /// </returns>
        public virtual async Task <ValidationResult> DeleteAsync(FileItem file, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            await Context.Database.ExecuteSqlCommandAsync("Drive.DeleteFile @Id", cancellationToken, DbParameters.Value("Id", file.Id));

            return(ValidationResult.Success);
        }