コード例 #1
0
 public void Save(MemberSubscriptionCollection subscriptions, IList <MemberSubscription> existingSubscriptions)
 {
     foreach (var memberSubscription in subscriptions.Subscriptions)
     {
         this.Save(memberSubscription);
     }
 }
コード例 #2
0
 public void Delete(MemberSubscriptionCollection subscriptions)
 {
     foreach (var subscription in subscriptions.Subscriptions)
     {
         this.Delete(subscription);
     }
 }
コード例 #3
0
        private void ProcessSubscriptions(response memberSubscriptions, string vkMemberId, VkGroup group)
        {
            IList <MemberSubscription> newSubscriptions = new List <MemberSubscription>();
            long memberId = long.Parse(vkMemberId);

            MemberSubscriptionCollection oldSubscriptions = this.memberRepository.GetSubscriptions(group.Id, memberId);

            if (memberSubscriptions.group != null && memberSubscriptions.group.Length > 0)
            {
                newSubscriptions = this.GetNewSubscriptionList(group.Id, memberId, memberSubscriptions.group);
            }

            this.log.DebugFormat("Old subscriptions: {0}", this.GetDebugString(oldSubscriptions.Subscriptions));
            this.log.DebugFormat("New subscriptions: {0}", this.GetDebugString(newSubscriptions));
            IDictionary <int, MemberSubscription> oldSubscriptionHash = oldSubscriptions.Subscriptions.Distinct(new MemberSubscriptionEqualityComparer()).ToDictionary(x => x.SubscribedVkGroupId);
            IDictionary <int, MemberSubscription> newSubscriptionHash = newSubscriptions.Distinct(new MemberSubscriptionEqualityComparer()).ToDictionary(x => x.SubscribedVkGroupId);

            IList <MemberSubscription> toInsert = newSubscriptions.Where(newS => !oldSubscriptionHash.ContainsKey(newS.SubscribedVkGroupId)).ToList();
            IList <MemberSubscription> toDelete = oldSubscriptions.Subscriptions.Where(old => !newSubscriptionHash.ContainsKey(old.SubscribedVkGroupId)).ToList();
            IList <MemberSubscription> same     = newSubscriptions.Where(newS => oldSubscriptionHash.ContainsKey(newS.SubscribedVkGroupId)).ToList();

            this.log.DebugFormat("Records to insert: {0}", this.GetDebugString(toInsert));
            this.log.DebugFormat("Records to delete: {0}", this.GetDebugString(toDelete));
            this.log.DebugFormat("Same records: {0}", this.GetDebugString(same));

            // here need to update titles of the groups
            this.memberRepository.Delete(new MemberSubscriptionCollection(group.Id, memberId, toDelete));
            this.memberRepository.Save(new MemberSubscriptionCollection(group.Id, memberId, toInsert), same);

            this.log.DebugFormat("Subscription for MemberId={0} are processed. {1} subscription(s) inserted and {2} subscription(s) deleted", vkMemberId, toInsert.Count, toDelete.Count);
        }
コード例 #4
0
        private IEnumerable <IVkEntity> GetSubscriptions(int vkGroupId)
        {
            using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
            {
                IEnumerable <MemberSubscription> subscriptions = dataGateway.Connection.Query <MemberSubscription, VkGroupReference, MemberSubscription>(
                    @"select ms.vkmemberid, ms.vkgroupid, ms.subscribedvkgroupid, vkr.vkgroupid, vkr.namegroup, vkr.screenname, vkr.photo from membersubscriptions ms inner join vkgroupreference vkr on (ms.subscribedvkgroupid = vkr.vkgroupid) where ms.vkgroupid = @VkGroupId",
                    (subscription, groupReference) =>
                {
                    subscription.SubscribedVkGroup = groupReference;
                    return(subscription);
                },
                    new { vkGroupId },
                    splitOn: "vkr.vkgroupid").ToList();
                IDictionary <long, MemberSubscriptionCollection> collections = new Dictionary <long, MemberSubscriptionCollection>();

                foreach (var subscription in subscriptions)
                {
                    if (!collections.ContainsKey(subscription.VkMemberId))
                    {
                        var currentCollection = new MemberSubscriptionCollection(vkGroupId, subscription.VkMemberId);
                        currentCollection.Subscriptions.Add(subscription);
                        collections.Add(subscription.VkMemberId, currentCollection);
                    }
                    else
                    {
                        collections[subscription.VkMemberId].Subscriptions.Add(subscription);
                    }
                }

                return(collections.Values);
            }
        }
コード例 #5
0
 public void Delete(MemberSubscriptionCollection subscriptions)
 {
     try
     {
         this.subscriptionRepository.Delete(subscriptions);
         this.cachingStrategy.RemoveItem(subscriptions, this.GetSubscriptionKey);
     }
     catch (DbException exc)
     {
         ExceptionHandler.HandleSaveException(exc, subscriptions, "subscriptions");
     }
 }
コード例 #6
0
        public MemberSubscriptionCollection GetSubscriptions(int vkGroupId, long vkMemberId)
        {
            using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
            {
                var query         = @"select ms.vkmemberid, ms.vkgroupid, ms.subscribedvkgroupid, vkr.vkgroupid, vkr.namegroup, vkr.screenname, vkr.photo from membersubscriptions ms inner join vkgroupreference vkr on (ms.subscribedvkgroupid = vkr.vkgroupid) where ms.vkgroupid = @VkGroupId and ms.vkmemberid = @VkMemberId";
                var subscriptions = dataGateway.Connection.Query <MemberSubscription, VkGroupReference, MemberSubscription>(
                    query,
                    (subscription, groupReference) =>
                {
                    subscription.SubscribedVkGroup = groupReference;
                    return(subscription);
                },
                    new { vkGroupId, vkMemberId },
                    splitOn: "vkr.vkgroupid").ToList();
                var collection = new MemberSubscriptionCollection(vkGroupId, vkMemberId, subscriptions);

                return(collection);
            }
        }
コード例 #7
0
        public void Save(MemberSubscriptionCollection subscriptions, IList <MemberSubscription> existingSubscriptions)
        {
            try
            {
                this.subscriptionRepository.Save(subscriptions);

                if (existingSubscriptions != null)
                {
                    foreach (var existingSubscription in existingSubscriptions)
                    {
                        subscriptions.Subscriptions.Add(existingSubscription);
                    }
                }

                this.cachingStrategy.StoreItem(subscriptions, this.GetSubscriptionKey);
            }
            catch (DbException exc)
            {
                ExceptionHandler.HandleSaveException(exc, subscriptions, "subscriptions");
            }
        }