Example #1
0
        public AnalizeFriendListViewModel GetIncomingRequestsFriendshipByAccount(long accountId)
        {
            var friendsIncoming = new GetFriendsByAccountIdQueryHandler(new DataBaseContext()).Handle(new GetFriendsByAccountIdQuery
            {
                AccountId   = accountId,
                FriendsType = FriendTypes.Incoming
            });
            var friendsRecommended = new GetFriendsByAccountIdQueryHandler(new DataBaseContext()).Handle(new GetFriendsByAccountIdQuery
            {
                AccountId   = accountId,
                FriendsType = FriendTypes.Recommended
            });

            var friends = friendsIncoming.Concat(friendsRecommended);

            var result = new AnalizeFriendListViewModel
            {
                AccountId = accountId,
                Friends   = friends.Select(model => new AnalizeFriendViewModel
                {
                    FacebookId    = model.FacebookId,
                    Id            = model.Id,
                    AccountId     = accountId,
                    FriendName    = model.FriendName,
                    AddedDateTime = model.AddedDateTime,
                    Status        = model.Status,
                    Type          = model.Type
                }).ToList()
            };

            return(result);
        }
Example #2
0
        public bool GetCurrentFriends(AccountViewModel accountViewModel)
        {
            const string functionName = "Обновление текущего списка друзей";

            var account = _accountManager.GetAccountById(accountViewModel.Id);

            try
            {
                _notice.AddNotice(functionName, account.Id, "Начинаем обновлять список друзей");

                var userAgent = new GetUserAgentQueryHandler(new DataBaseContext()).Handle(new GetUserAgentQuery
                {
                    UserAgentId = account.UserAgentId
                });

                var groupId = account.GroupSettingsId;

                if (groupId == null)
                {
                    _notice.AddNotice(functionName, account.Id, "Ошибка! Группа не выбрана.");
                    return(false);
                }

                var settings           = _accountSettingsManager.GetSettings((long)groupId);
                var accountInformation = _accountManager.GetAccountInformation((long)groupId);

                var friends = new GetCurrentFriendsBySeleniumEngine().Execute(new GetCurrentFriendsBySeleniumModel
                {
                    Cookie            = account.Cookie,
                    AccountFacebookId = account.FacebookId,
                    Driver            = _seleniumManager.RegisterNewDriver(new AccountViewModel
                    {
                        Proxy         = account.Proxy,
                        ProxyLogin    = account.ProxyLogin,
                        ProxyPassword = account.ProxyPassword,
                        UserAgentId   = userAgent.Id
                    }),
                    Proxy     = _accountManager.GetAccountProxy(account),
                    UserAgent = userAgent.UserAgentString
                });

                _notice.AddNotice(functionName, account.Id, "Список текущих друзей получен, количество - " + friends.Count);

                _notice.AddNotice(functionName, account.Id, string.Format("Учитываем погрешность {0}%", settings.AllowedRemovalPercentage));

                var notError = _friendManager.RecountError(accountInformation.CountCurrentFriends, friends.Count, settings.AllowedRemovalPercentage);

                if (!notError)
                {
                    _notice.AddNotice(functionName, account.Id, string.Format("Ошибка получения друзей. Получено - {0}, текущее колиство в базе - {1}, погрешность - {2}%", friends.Count, accountInformation.CountCurrentFriends, settings.AllowedRemovalPercentage));

                    return(false);
                }

                var outgoingFriendships =
                    new GetFriendsByAccountIdQueryHandler(new DataBaseContext()).Handle(new GetFriendsByAccountIdQuery
                {
                    AccountId   = account.Id,
                    FriendsType = FriendTypes.Outgoig
                });


                if (friends.Count == 0)
                {
                    _notice.AddNotice(functionName, account.Id, "Нет друзей. Обновление друзей завершено.");

                    return(true);
                }

                _notice.AddNotice(functionName, account.Id, "Сверяем друзей с исходящими заявками");
                foreach (var newFriend in friends)
                {
                    if (outgoingFriendships.All(data => data.FacebookId != newFriend.FacebookId))
                    {
                        continue;
                    }

                    _notice.AddNotice(functionName, account.Id, newFriend.FriendName + "добавился в друзья ");

                    new DeleteAnalysisFriendByIdHandler(new DataBaseContext()).Handle(new DeleteAnalysisFriendById
                    {
                        AnalysisFriendFacebookId = newFriend.FacebookId
                    });

                    new AddOrUpdateAccountStatisticsCommandHandler(new DataBaseContext()).Handle(
                        new AddOrUpdateAccountStatisticsCommand
                    {
                        AccountId = account.Id,
                        CountOrdersConfirmedFriends = 1
                    });

                    _notice.AddNotice(functionName, account.Id, "Сверяем друзей с исходящими заявками");
                }

                // drop blocked users
                _notice.AddNotice(functionName, account.Id, "Сверяем друзей с черным списком");

                var newFriendList = (from friend in friends
                                     let isBlocked =
                                         new CheckForFriendBlacklistedQueryHandler().Handle(new CheckForFriendBlacklistedQuery
                {
                    FriendFacebookId = friend.FacebookId,
                    GroupSettingsId = (long)groupId
                })
                                         where !isBlocked
                                         select new FriendData
                {
                    FacebookId = friend.FacebookId,
                    FriendName = friend.FriendName,
                    Href = friend.Uri,
                    Gender = friend.Gender
                }).ToList();

                _notice.AddNotice(functionName, account.Id, "Совпадений с черным списком - " + (friends.Count - newFriendList.Count));

                _notice.AddNotice(functionName, account.Id, "Сохраняем друзей");

                new SaveUserFriendsCommandHandler(new DataBaseContext()).Handle(new SaveUserFriendsCommand
                {
                    AccountId = account.Id,
                    Friends   = newFriendList
                });

                new AddAccountInformationCommandHandler(new DataBaseContext()).Handle(new AddAccountInformationCommand
                {
                    AccountId = account.Id,
                    AccountInformationData = new AccountInformationDataDbModel
                    {
                        CountCurrentFriends = friends.Count
                    }
                });

                _notice.AddNotice(functionName, account.Id, "Обновление друзей завершено.");
            }
            catch (Exception ex)
            {
                _notice.AddNotice(functionName, account.Id, string.Format("Ошибка - {0}", ex.Message));
            }
            return(true);
        }