Ejemplo n.º 1
0
        public virtual async Task Update(List <StoredNotification <long> > items)
        {
            List <StoredNotificationLong> mappedList = items
                                                       .Select(_mapper.Map <StoredNotificationLong>)
                                                       .ToList();

            using (Repository repository = new Repository(_dbContextFactory.GetDbContext()))
            {
                string tvpName = TableValuedParameters.GetFullTVPName(_connectionSettings.Schema
                                                                      , TableValuedParameters.STORED_NOTIFICATION_TYPE);

                MergeCommand <StoredNotificationLong> merge = repository.MergeTVP(mappedList, tvpName);
                merge.Source
                .IncludeProperty(x => x.StoredNotificationId)
                .IncludeProperty(x => x.SubscriberId)
                .IncludeProperty(x => x.CategoryId)
                .IncludeProperty(x => x.TopicId)
                .IncludeProperty(x => x.CreateDateUtc)
                .IncludeProperty(x => x.MessageSubject)
                .IncludeProperty(x => x.MessageBody);
                merge.Compare
                .IncludeProperty(p => p.StoredNotificationId);
                merge.UpdateMatched
                .ExcludeProperty(p => p.StoredNotificationId);
                int changes = await merge.ExecuteAsync(MergeType.Update).ConfigureAwait(false);
            }
        }
Ejemplo n.º 2
0
        protected virtual SqlParameter ToUpdateSubscriberType(List <SignalDispatch <long> > items)
        {
            IEnumerable <UpdateSubscriberParameter> groupedItems = items
                                                                   .Where(p => p.ReceiverSubscriberId != null)
                                                                   .GroupBy(p => new { p.ReceiverSubscriberId, p.DeliveryType, p.CategoryId, p.TopicId })
                                                                   .Select(p => new UpdateSubscriberParameter
            {
                SubscriberId = p.First().ReceiverSubscriberId.Value,
                DeliveryType = p.First().DeliveryType,
                CategoryId   = p.First().CategoryId.Value,
                TopicId      = p.First().TopicId,
                SendCount    = p.Count()
            });

            DataTable dataTable = groupedItems.ToDataTable(new List <string>()
            {
                nameof(SubscriberDeliveryTypeSettingsLong.SubscriberId),
                nameof(SubscriberDeliveryTypeSettingsLong.SendCount),
                nameof(SubscriberDeliveryTypeSettingsLong.DeliveryType),
                nameof(SubscriberTopicSettingsLong.CategoryId),
                nameof(SubscriberTopicSettingsLong.TopicId),
            });

            SqlParameter param = new SqlParameter(
                TableValuedParameters.UPDATE_SUBSCRIBERS_PARAMETER_NAME, dataTable);

            param.SqlDbType = SqlDbType.Structured;
            param.TypeName  = TableValuedParameters.GetFullTVPName(_connectionSettings.Schema, TableValuedParameters.SUBSCRIBER_TYPE);

            return(param);
        }
        public virtual async Task UpdateSendResults(List <SignalEvent <long> > items)
        {
            List <SignalEventLong> mappedList = items
                                                .Select(_mapper.Map <SignalEventLong>)
                                                .ToList();

            string tvpName = TableValuedParameters.GetFullTVPName(_connectionSettings.Schema, TableValuedParameters.EVENT_UPDATE_TYPE);

            using (Repository repository = new Repository(_dbContextFactory.GetDbContext()))
            {
                MergeCommand <SignalEventLong> update = repository.MergeTVP(mappedList, tvpName);

                update.Source.IncludeProperty(p => p.SignalEventId)
                .IncludeProperty(p => p.FailedAttempts)
                .IncludeProperty(p => p.EventSettingsId)
                .IncludeProperty(p => p.SubscriberIdRangeFrom)
                .IncludeProperty(p => p.SubscriberIdRangeTo)
                .IncludeProperty(p => p.SubscriberIdFromDeliveryTypesHandledSerialized);

                update.Compare.IncludeProperty(p => p.SignalEventId);

                update.UpdateMatched
                .IncludeProperty(p => p.FailedAttempts)
                .IncludeProperty(p => p.EventSettingsId)
                .IncludeProperty(p => p.SubscriberIdRangeFrom)
                .IncludeProperty(p => p.SubscriberIdRangeTo)
                .IncludeProperty(p => p.SubscriberIdFromDeliveryTypesHandledSerialized);

                int changes = await update.ExecuteAsync(MergeType.Update)
                              .ConfigureAwait(false);
            }
        }
Ejemplo n.º 4
0
        public virtual async Task UpsertIsEnabled(List <SubscriberTopicSettingsLong> items)
        {
            List <long> disabledTopics = items
                                         .Where(x => x.IsEnabled == false)
                                         .Select(x => x.SubscriberTopicSettingsId)
                                         .ToList();
            List <SubscriberTopicSettingsLong> enabledTopics = items
                                                               .Where(x => x.IsEnabled)
                                                               .ToList();

            using (Repository repository = new Repository(_dbContextFactory.GetDbContext()))
                using (IDbContextTransaction ts = repository.Context.Database.BeginTransaction())
                {
                    SqlTransaction sqlTransaction = (SqlTransaction)ts.GetDbTransaction();
                    if (disabledTopics.Count > 0)
                    {
                        int changes = await repository.DeleteManyAsync <SubscriberTopicSettingsLong>(
                            x => disabledTopics.Contains(x.SubscriberTopicSettingsId))
                                      .ConfigureAwait(false);
                    }

                    if (enabledTopics.Count > 0)
                    {
                        string tvpName = TableValuedParameters.GetFullTVPName(_connectionSettings.Schema
                                                                              , TableValuedParameters.SUBSCRIBER_TOPIC_SETTINGS_TYPE);
                        MergeCommand <SubscriberTopicSettingsLong> merge = repository.MergeTVP(enabledTopics, tvpName, sqlTransaction);
                        merge.Source
                        .IncludeProperty(p => p.TopicId)
                        .IncludeProperty(p => p.CategoryId)
                        .IncludeProperty(p => p.DeliveryType)
                        .IncludeProperty(p => p.SubscriberId)
                        .IncludeProperty(p => p.AddDateUtc)
                        .IncludeProperty(p => p.IsEnabled);
                        merge.Compare
                        .IncludeProperty(p => p.SubscriberId)
                        .IncludeProperty(p => p.TopicId)
                        .IncludeProperty(p => p.CategoryId)
                        .IncludeProperty(p => p.DeliveryType);
                        merge.UpdateMatched
                        .IncludeProperty(p => p.IsEnabled);
                        merge.Insert
                        .IncludeProperty(p => p.TopicId)
                        .IncludeProperty(p => p.CategoryId)
                        .IncludeProperty(p => p.DeliveryType)
                        .IncludeProperty(p => p.SubscriberId)
                        .IncludeProperty(p => p.AddDateUtc)
                        .IncludeProperty(p => p.IsEnabled)
                        .IncludeDefaultValue(p => p.SendCount)
                        .IncludeDefaultValue(p => p.IsDeleted);
                        int changes = await merge.ExecuteAsync(MergeType.Upsert).ConfigureAwait(false);
                    }

                    ts.Commit();
                }
        }
Ejemplo n.º 5
0
        public virtual async Task UpsertIsEnabled(List <SubscriberCategorySettingsLong> items)
        {
            List <long> disabledCategories = items
                                             .Where(x => x.IsEnabled == false)
                                             .Select(x => x.SubscriberCategorySettingsId)
                                             .ToList();
            List <SubscriberCategorySettingsLong> enabledCategories = items
                                                                      .Where(x => x.IsEnabled)
                                                                      .ToList();

            using (Repository repository = new Repository(_dbContextFactory.GetDbContext()))
            {
                if (disabledCategories.Count > 0)
                {
                    int changes = await repository.DeleteManyAsync <SubscriberCategorySettingsLong>(
                        x => disabledCategories.Contains(x.SubscriberCategorySettingsId))
                                  .ConfigureAwait(false);
                }

                if (enabledCategories.Count > 0)
                {
                    string tvpName = TableValuedParameters.GetFullTVPName(_connectionSettings.Schema
                                                                          , TableValuedParameters.SUBSCRIBER_CATEGORY_SETTINGS_TYPE);
                    MergeCommand <SubscriberCategorySettingsLong> merge = repository.MergeTVP(enabledCategories, tvpName);

                    merge.Source
                    .IncludeProperty(p => p.SubscriberId)
                    .IncludeProperty(p => p.DeliveryType)
                    .IncludeProperty(p => p.CategoryId)
                    .IncludeProperty(p => p.LastSendDateUtc)
                    .IncludeProperty(p => p.SendCount)
                    .IncludeProperty(p => p.IsEnabled);
                    merge.Compare
                    .IncludeProperty(p => p.SubscriberId)
                    .IncludeProperty(p => p.CategoryId)
                    .IncludeProperty(p => p.DeliveryType);
                    merge.UpdateMatched
                    .IncludeProperty(p => p.IsEnabled);
                    merge.Insert
                    .IncludeProperty(p => p.SubscriberId)
                    .IncludeProperty(p => p.DeliveryType)
                    .IncludeProperty(p => p.CategoryId)
                    .IncludeProperty(p => p.LastSendDateUtc)
                    .IncludeProperty(p => p.SendCount)
                    .IncludeProperty(p => p.IsEnabled);

                    int changes = await merge.ExecuteAsync(MergeType.Upsert)
                                  .ConfigureAwait(false);
                }
            }
        }
Ejemplo n.º 6
0
        //update
        public virtual async Task UpdateIsEnabled(List <SubscriberTopicSettingsLong> items)
        {
            using (Repository repository = new Repository(_dbContextFactory.GetDbContext()))
            {
                string tvpName = TableValuedParameters.GetFullTVPName(_connectionSettings.Schema, TableValuedParameters.SUBSCRIBER_TOPIC_SETTINGS_TYPE_IS_ENABLED);
                MergeCommand <SubscriberTopicSettingsLong> merge = repository.MergeTVP(items, tvpName);
                merge.Source
                .IncludeProperty(p => p.SubscriberTopicSettingsId)
                .IncludeProperty(p => p.IsEnabled);
                merge.Compare
                .IncludeProperty(p => p.SubscriberTopicSettingsId);
                merge.UpdateMatched
                .IncludeProperty(p => p.IsEnabled);

                int changes = await merge.ExecuteAsync(MergeType.Update)
                              .ConfigureAwait(false);
            }
        }
Ejemplo n.º 7
0
        protected virtual string CreateDeliveryTypeUpdateQuery(UpdateParameters parameters, DbContext context)
        {
            string tvpName = TableValuedParameters.GetFullTVPName(_connectionSettings.Schema, TableValuedParameters.SUBSCRIBER_TYPE);
            var    merge   = new MergeCommand <SubscriberDeliveryTypeSettingsLong>(context, null, tvpName, TableValuedParameters.UPDATE_SUBSCRIBERS_PARAMETER_NAME);

            merge.Compare
            .IncludeProperty(p => p.SubscriberId)
            .IncludeProperty(p => p.DeliveryType);

            merge.UpdateMatched.ExcludeAllByDefault = true;

            if (parameters.UpdateDeliveryTypeSendCount)
            {
                merge.UpdateMatched.Assign(t => t.SendCount, (t, s) => t.SendCount + s.SendCount);
            }

            if (parameters.UpdateDeliveryTypeLastSendDateUtc)
            {
                merge.UpdateMatched.Assign(t => t.LastSendDateUtc, (t, s) => DateTime.UtcNow);
            }

            return(merge.ConstructCommandTVP(MergeType.Update));
        }
Ejemplo n.º 8
0
        protected virtual string CreateTopicUpdateQuery(UpdateParameters parameters, DbContext context)
        {
            string tvpName = TableValuedParameters.GetFullTVPName(_connectionSettings.Schema, TableValuedParameters.SUBSCRIBER_TYPE);
            var    merge   = new MergeCommand <SubscriberTopicSettingsLong>(context, null, tvpName, TableValuedParameters.UPDATE_SUBSCRIBERS_PARAMETER_NAME);

            merge.Compare.IncludeProperty(p => p.SubscriberId)
            .IncludeProperty(p => p.CategoryId)
            .IncludeProperty(p => p.TopicId);

            merge.UpdateMatched.ExcludeAllByDefault = true;

            if (parameters.UpdateTopicSendCount)
            {
                merge.UpdateMatched.Assign(t => t.SendCount, (t, s) => t.SendCount + s.SendCount);
            }

            if (parameters.UpdateTopicLastSendDateUtc)
            {
                merge.UpdateMatched.Assign(t => t.LastSendDateUtc, (t, s) => DateTime.UtcNow);
            }

            if (parameters.CreateTopicIfNotExist)
            {
                merge.Insert
                .ExcludeProperty(t => t.SubscriberTopicSettingsId)
                .IncludeValue(t => t.AddDateUtc, DateTime.UtcNow)
                .IncludeValue(t => t.IsEnabled, true)
                .IncludeValue(t => t.LastSendDateUtc, DateTime.UtcNow)
                .IncludeValue(t => t.IsDeleted, false);
            }

            MergeType mergeType = parameters.CreateTopicIfNotExist
                ? MergeType.Upsert
                : MergeType.Update;

            return(merge.ConstructCommandTVP(mergeType));
        }