コード例 #1
0
 public IList <VkGroup> GetGroups()
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <VkGroup>().ToList());
     }
 }
コード例 #2
0
 public IList <Administrator> GetAdminstrators(int id)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <Administrator>().Where(a => a.VkGroupId == id).ToList());
     }
 }
コード例 #3
0
        public int SaveGroupProcessingHistoryItem(VkGroupProcessingHistoryItem item)
        {
            if (!item.IsTransient())
            {
                return(0);
            }

            using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
            {
                item.Id = dataGateway.Connection.Query <int>(@"insert into vkgroupprocessinghistory(vkgroupid, feedtype, fetchingdate, fetchingserver, fetchingprocess, processingdate, processingserver, processingprocess) values (@VkGroupId, @FeedType, @FetchingDate, @FetchingServer, @FetchingProcess, @ProcessingDate, @ProcessingServer, @ProcessingProcess) RETURNING id", item).First();

                var state = dataGateway.Connection.Query <VkGroupProcessingState>("select * from vkgroupprocessingstate where vkgroupid = @vkGroupId and feedtype = @feedType", new { vkGroupId = item.VkGroupId, feedType = (int)item.FeedType }).FirstOrDefault() ?? new VkGroupProcessingState();
                state.FeedType          = item.FeedType;
                state.VkGroupId         = item.VkGroupId;
                state.FetchingDate      = item.FetchingDate;
                state.FetchingProcess   = item.FetchingProcess;
                state.FetchingServer    = item.FetchingServer;
                state.ProcessingDate    = item.ProcessingDate;
                state.ProcessingProcess = item.ProcessingProcess;
                state.ProcessingServer  = item.ProcessingServer;
                state.Version++;

                if (state.IsTransient())
                {
                    item.Id = dataGateway.Connection.Query <int>(@"insert into vkgroupprocessingstate(version, vkgroupid, feedtype, fetchingdate, fetchingserver, fetchingprocess, processingdate, processingserver, processingprocess) values (@Version, @VkGroupId, @FeedType, @FetchingDate, @FetchingServer, @FetchingProcess, @ProcessingDate, @ProcessingServer, @ProcessingProcess) RETURNING id", state).First();
                }
                else
                {
                    dataGateway.Connection.Execute(@"update vkgroupprocessingstate set version = @Version, vkgroupid = @VkGroupId, feedtype = @FeedType, fetchingdate = @FetchingDate, fetchingserver = @FetchingServer, fetchingprocess = @FetchingProcess, processingdate = @ProcessingDate, processingserver = @ProcessingServer, processingprocess = @ProcessingProcess where id = @Id", state);
                }

                return(state.Version);
            }
        }
コード例 #4
0
 public VkGroup GetGroupById(int id)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <VkGroup>().SingleOrDefault(g => g.Id == id));
     }
 }
コード例 #5
0
 public void DeleteAllConcurrents(int projectId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         dataGateway.Connection.Execute("delete from projectconcurrent where projectid1 = @projectId", new { projectId });
     }
 }
コード例 #6
0
 public IList <Topic> GetTopicsByVkGroupId(int vkGroupId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <Topic>().Where(p => p.VkGroupId == vkGroupId).ToList());
     }
 }
コード例 #7
0
ファイル: RawDataProvider.cs プロジェクト: Ishitori/Palantir
        public IList <Member> GetMembers(int vkGroupId)
        {
            using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
            {
                const string QueryMember    = @"select id, vkgroupid, name, gender, maritalstatus, cityid, countryid, education, vkmemberid, status, birthday, birthmonth, birthyear from member where vkgroupid = @vkgroupid;";
                const string QueryInterests = @"select * from memberinterest where vkgroupid = @vkgroupid";

                var members = dataGateway.Connection.Query <Member, BirthDate, Member>(
                    QueryMember,
                    (member, birthdate) => { member.BirthDate = birthdate; return(member); },
                    new { vkgroupid = vkGroupId },
                    splitOn: "birthday").ToList();
                var interests = dataGateway.Connection.Query <MemberInterest>(QueryInterests, new { vkgroupid = vkGroupId }).ToList();

                var membersDictionary = members.ToDictionary(m => m.VkMemberId);

                foreach (var interest in interests)
                {
                    if (membersDictionary.ContainsKey(interest.VkMemberId))
                    {
                        membersDictionary[interest.VkMemberId].Interests.Add(interest);
                    }
                }

                return(members);
            }
        }
コード例 #8
0
 public IList <Project> GetByAccountId(int accountId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <Project>().Where(p => p.AccountId == accountId).ToList());
     }
 }
コード例 #9
0
        public Member GetMember(int groupId, string memberId)
        {
            using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
            {
                const string QueryMember    = @"select id, vkgroupid, name, gender, maritalstatus, cityid, countryid, education, vkmemberid, status, birthday, birthmonth, birthyear from member where vkgroupid = @vkgroupid and vkmemberid = @vkmemberid;";
                const string QueryInterests = @"select * from memberinterest where vkgroupid = @vkgroupid and vkmemberid = @vkmemberid";

                var result = dataGateway.Connection.Query <Member, BirthDate, Member>(
                    QueryMember,
                    (member, birthdate) => { member.BirthDate = birthdate; return(member); },
                    new { vkgroupid = groupId, vkmemberid = long.Parse(memberId) },
                    splitOn: "birthday").FirstOrDefault();

                if (result == null)
                {
                    return(null);
                }

                var interests = dataGateway.Connection.Query <MemberInterest>(QueryInterests, new { vkgroupid = groupId, vkmemberid = long.Parse(memberId) }).ToList();

                foreach (var interest in interests)
                {
                    result.Interests.Add(interest);
                }

                return(result);
            }
        }
コード例 #10
0
        public void SaveMember(Member member)
        {
            if (!member.IsTransient())
            {
                return;
            }

            using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
            {
                member.Id = dataGateway.Connection.Query <int>(@"insert into member(vkgroupid, name, gender, maritalstatus, birthday, birthmonth, birthyear, cityid, countryid, education, vkmemberid, status, isdeleted) values (@VkGroupId, @Name, @Gender, @MaritalStatus, @BirthDay, @BirthMonth, @BirthYear, @CityId, @CountryId, @Education, @VkMemberId, @Status, @IsDeleted) RETURNING id", this.Flatten(member)).First();

                if (member.Interests != null && member.Interests.Count > 0)
                {
                    foreach (var interest in member.Interests)
                    {
                        this.InsertInterest(interest, dataGateway);
                    }
                }

                var update = new MemberUpdate
                {
                    VkMemberId  = member.VkMemberId,
                    VkGroupId   = member.VkGroupId,
                    CreatedDate = DateTime.UtcNow,
                    IsNew       = true
                };

                update.Id = dataGateway.Connection.Query <int>(@"INSERT INTO memberupdate(vkgroupid, vkmemberid, createddate, isnew) VALUES (@vkGroupId, @vkMemberId, @createdDate, @isNew) RETURNING id", update).First();
            }
        }
コード例 #11
0
ファイル: VideoRepository.cs プロジェクト: Ishitori/Palantir
 public VideoComment GetVideoCommentByVkGroupId(int vkGroupId, string vkId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <VideoComment>().SingleOrDefault(vc => vc.VkGroupId == vkGroupId && vc.VkId == vkId));
     }
 }
コード例 #12
0
ファイル: UserRepository.cs プロジェクト: Ishitori/Palantir
 public void Update(API.User user)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         dataGateway.UpdateEntity(user);
     }
 }
コード例 #13
0
ファイル: UserRepository.cs プロジェクト: Ishitori/Palantir
 public IList <API.User> GetUsers(int accountId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <API.User>().Where(u => u.Account.Id == accountId).ToList());
     }
 }
コード例 #14
0
ファイル: UserRepository.cs プロジェクト: Ishitori/Palantir
 public IList <API.User> GetUsers()
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <API.User>().ToList());
     }
 }
コード例 #15
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);
            }
        }
コード例 #16
0
 public IEnumerable <Project> GetAll()
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <Project>());
     }
 }
コード例 #17
0
 public Topic GetTopic(int vkGroupId, string vkId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <Topic>().SingleOrDefault(p => p.VkGroupId == vkGroupId && p.VkId == vkId));
     }
 }
コード例 #18
0
 public void Update(Project project)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         dataGateway.UpdateEntity(project);
     }
 }
コード例 #19
0
        public double GetInteractionRate(int projectId, DateRange dateRange)
        {
            var vkGroup      = this.projectRepository.GetVkGroup(projectId);
            var creationDate = this.groupRepository.GetGroupCreationDate(vkGroup.Id);

            if (!creationDate.HasValue)
            {
                return(0);
            }

            using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
            {
                string query = dateRange.IsSpecified
                    ? @"select count(*)::int as PostsCount, sum(likescount)::int as LikesCount, sum(commentscount)::int as CommentsCount from post where vkgroupid = @vkgroupid"
                    : @"select count(*)::int as PostsCount, sum(likescount)::int as LikesCount, sum(commentscount)::int as CommentsCount from post where vkgroupid = @vkgroupid and posteddate >= @from and posteddate <= @to";

                string memberCountQuery = @"select count(*)::int from member where vkgroupid = @vkgroupid";

                dynamic stat        = dataGateway.Connection.Query <dynamic>(query, new { vkgroupid = vkGroup.Id, from = dateRange.From, to = dateRange.To }).SingleOrDefault();
                int     memberCount = dataGateway.Connection.Query <int>(memberCountQuery, new { vkgroupid = vkGroup.Id }).SingleOrDefault();

                return(stat.postscount > 0 && memberCount > 0
                    ? (stat.likescount + stat.commentscount) / (double)stat.postscount
                    : 0);
            }
        }
コード例 #20
0
 public IList <PostComment> GetPostCommentsByVkGroupId(int vkGroupId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <PostComment>().Where(p => p.VkGroupId == vkGroupId).ToList());
     }
 }
コード例 #21
0
 public PostComment GetPostComment(int vkGroupId, string vkId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <PostComment>().SingleOrDefault(p => p.VkGroupId == vkGroupId && p.VkId == vkId));
     }
 }
コード例 #22
0
ファイル: UserRepository.cs プロジェクト: Ishitori/Palantir
 public API.User GetUserById(int userId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <API.User>().FirstOrDefault(u => u.Id == userId));
     }
 }
コード例 #23
0
 public IList <string> GetGroupAlbumIds(int vkGroupId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.Connection.Query <string>("select albumid from photo where vkgroupid = @VkGroupId group by albumid", new { VkGroupId = vkGroupId }).ToList());
     }
 }
コード例 #24
0
ファイル: DataService.cs プロジェクト: w1r2p1/Nautilus
        /// <summary>
        /// Initializes a new instance of the <see cref="DataService"/> class.
        /// </summary>
        /// <param name="container">The componentry container.</param>
        /// <param name="messagingAdapter">The messaging adapter.</param>
        /// <param name="dataBusAdapter">The data bus adapter.</param>
        /// <param name="dataGateway">The data gateway.</param>
        /// <param name="config">The service configuration.</param>
        /// <exception cref="ArgumentException">If the addresses is empty.</exception>
        public DataService(
            IComponentryContainer container,
            MessageBusAdapter messagingAdapter,
            DataBusAdapter dataBusAdapter,
            IDataGateway dataGateway,
            ServiceConfiguration config)
            : base(
                container,
                messagingAdapter,
                config.FixConfig)
        {
            this.dataBus           = dataBusAdapter;
            this.dataGateway       = dataGateway;
            this.managedComponents = new List <Address>
            {
                ComponentAddress.DataServer,
                ComponentAddress.DataPublisher,
                ComponentAddress.MarketDataRepository,
                ComponentAddress.TickPublisher,
                ComponentAddress.TickProvider,
                ComponentAddress.BarProvider,
                ComponentAddress.InstrumentRepository,
                ComponentAddress.InstrumentProvider,
            };

            this.subscribingSymbols = config.DataConfig.SubscribingSymbols;

            this.RegisterConnectionAddress(ComponentAddress.DataGateway);
        }
コード例 #25
0
 public void Save(IAccount account)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         dataGateway.SaveEntity(account);
     }
 }
コード例 #26
0
 public Photo GetPhotoByIdInAlbum(int vkGroupId, string vkAlbumId, string vkId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <Photo>().SingleOrDefault(p => p.VkGroupId == vkGroupId && p.AlbumId == vkAlbumId && p.VkId == vkId));
     }
 }
コード例 #27
0
 public IList <IAccount> GetAccounts()
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <API.IAccount>().ToList());
     }
 }
コード例 #28
0
 public IAccount GetAccount(int accountId)
 {
     using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
     {
         return(dataGateway.GetEntities <API.IAccount>().FirstOrDefault(x => x.Id == accountId));
     }
 }
コード例 #29
0
        public CategorialValue LikesRepostCommentDiagramData(int vkGroupId, AudienceFilteringResult filteringResult)
        {
            var    result  = new CategorialValue();
            string userIds = filteringResult.IsAllMembers
                ? string.Empty
                : QueryArrayBuilder.GetString(filteringResult.Members.Select(m => m.VkMemberId).ToArray());

            using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
            {
                string creatorIdClause = filteringResult.IsAllMembers
                    ? string.Empty
                    : string.Format("AND creatorid = ANY({0})", userIds);

                string memberIdClause = filteringResult.IsAllMembers
                    ? string.Empty
                    : string.Format("AND vkmemberid = ANY({0})", userIds);

                string query = string.Format("SELECT COUNT(*)::integer FROM postcomment WHERE vkgroupid = {0} {1}", vkGroupId, creatorIdClause);
                result.CategoryA = dataGateway.Connection.Query <int>(query).SingleOrDefault();

                query            = string.Format("SELECT COUNT(*)::integer FROM membershare WHERE vkgroupid = {0} {1} AND itemtype = {2}", vkGroupId, memberIdClause, (int)LikeShareType.Post);
                result.CategoryB = dataGateway.Connection.Query <int>(query).SingleOrDefault();

                query            = string.Format("SELECT COUNT(*)::integer FROM memberlike WHERE vkgroupid = {0} {1} AND itemtype = {2}", vkGroupId, memberIdClause, (int)LikeShareType.Post);
                result.CategoryC = dataGateway.Connection.Query <int>(query).SingleOrDefault();

                query            = string.Format("SELECT COUNT(*)::integer FROM post WHERE vkgroupid = {0} {1}", vkGroupId, creatorIdClause);
                result.CategoryD = dataGateway.Connection.Query <int>(query).SingleOrDefault();
            }

            return(result);
        }
コード例 #30
0
        public IEnumerable <GroupedObject <City> > GetCityInformationActiveUsers(int vkGroupId, AudienceFilteringResult result)
        {
            IDictionary <int, int> memberPerCity = new Dictionary <int, int>();

            foreach (var member in result.Members)
            {
                if (memberPerCity.ContainsKey(member.CityId))
                {
                    memberPerCity[member.CityId]++;
                }
                else
                {
                    memberPerCity.Add(member.CityId, 0);
                }
            }

            using (IDataGateway dataGateway = this.dataGatewayProvider.GetDataGateway())
            {
                IList <string> ids    = memberPerCity.Keys.Select(x => string.Format("'{0}'", x)).ToList();
                string         query  = string.Format("SELECT id, vkid, title FROM city WHERE vkid IN ({0})", new SeparatedStringBuilder(ids));
                var            cities = dataGateway.Connection.Query <City>(query).ToDictionary(x => int.Parse(x.VkId));

                IList <GroupedObject <City> > items = memberPerCity.Select(item => new GroupedObject <City>
                {
                    Item = cities.ContainsKey(item.Key) ? cities[item.Key] : new City {
                        Id = 0, VkId = item.Key.ToString(), Title = "<неизвестно>"
                    },
                    Value = item.Value
                }).ToList();

                return(items);
            }
        }
コード例 #31
0
 public void Setup()
 {
     Bootstrapper.Run();
      _dataGateway = Container.Windsor.Resolve<IDataGateway>();
 }