Ejemplo n.º 1
0
        public void SendMessageToUnread(AccountViewModel accountViewModel)
        {
            const string functionName = "Ответ на непрочитанные сообщения";

            _notice.AddNotice(functionName, accountViewModel.Id, string.Format("Начинаем отвечать"));

            try
            {
                var account = _accountManager.GetAccountById(accountViewModel.Id);
                if (account.GroupSettingsId == null)
                {
                    _notice.AddNotice(functionName, account.Id, "Ошибка! Не указана группа настроек.");
                    return;
                }

                var settings = _accountSettingsManager.GetSettings((long)account.GroupSettingsId);

                var unreadMessagesList = GetUnreadMessages(account);
                _notice.AddNotice(functionName, accountViewModel.Id, string.Format("Получено {0} непрочитанных сообщений", unreadMessagesList.UnreadMessages.Count));
                SendMessages(unreadMessagesList.UnreadMessages, account, functionName);

                if (settings.GetMessagesFromThoseConnectedToMessenger)
                {
                    var newMessangerMessagesList = GetMessangerMessages(account);
                    _notice.AddNotice(functionName, accountViewModel.Id, string.Format("Получено {0} сообщений о добавлении пользователя в мессенджер", newMessangerMessagesList.UnreadMessages.Count));
                    SendMessages(newMessangerMessagesList.UnreadMessages, account, functionName);
                }

                _notice.AddNotice(functionName, accountViewModel.Id, string.Format("Успешно завершено"));
            }
            catch (Exception ex)
            {
                _notice.AddNotice(functionName, accountViewModel.Id, string.Format("Возникла ошибка {0}", ex.Message));
            }
        }
Ejemplo n.º 2
0
        public void RecoverAccount(long accountId, IBackgroundJobService backgroundJobService)
        {
            new RecoverUserCommandHandler(new DataBaseContext()).Handle(new RecoverUserCommand
            {
                AccountId = accountId
            });

            var account = new GetAccountByIdQueryHandler(new DataBaseContext()).Handle(new GetAccountByIdQuery
            {
                UserId = accountId
            });

            new CookieService().RefreshCookies(new AccountViewModel
            {
                Id            = accountId,
                Login         = account.Login,
                Password      = account.Password,
                Proxy         = account.Proxy,
                ProxyLogin    = account.ProxyLogin,
                ProxyPassword = account.ProxyPassword,
                UserAgentId   = account.UserAgentId
            },
                                               forSpy: false,
                                               backgroundJob: backgroundJobService);

            if (account.GroupSettingsId == null)
            {
                return;
            }

            var settings         = _accountSettingsManager.GetSettings((long)account.GroupSettingsId);
            var accountViewModel = new AccountViewModel
            {
                Id = account.Id,
                AuthorizationDataIsFailed = account.AuthorizationDataIsFailed,
                Cookie            = account.Cookie.CookieString,
                IsDeleted         = account.IsDeleted,
                ProxyDataIsFailed = account.ProxyDataIsFailed,
                GroupSettingsId   = account.GroupSettingsId,
                Name                     = account.Name,
                Proxy                    = account.Proxy,
                FacebookId               = account.FacebookId,
                Login                    = account.Login,
                PageUrl                  = account.PageUrl,
                Password                 = account.Password,
                ProxyLogin               = account.ProxyLogin,
                ProxyPassword            = account.ProxyPassword,
                ConformationDataIsFailed = account.ConformationIsFailed,
                UserAgentId              = account.UserAgentId
            };

            var model = new AddOrUpdateAccountModel()
            {
                Account     = accountViewModel,
                NewSettings = settings,
                OldSettings = null
            };

            backgroundJobService.AddOrUpdateAccountJobs(model);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public void SendMessageToUnanswered(AccountViewModel accountViewModel)
        {
            const string functionName = "Ответ на неотвеченные сообщения";

            _notice.AddNotice(functionName, accountViewModel.Id, _noticeService.ConvertNoticeText(functionName, string.Format("Начинаем отвечать")));

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

            try
            {
                _notice.AddNotice(functionName, accountViewModel.Id, string.Format("Собираемся посылать экстра-сообщения"));

                var unreadMessagesList = GetUnreadMessages(account);


                if (unreadMessagesList.UnreadMessages.Count != 0)
                {
                    return;
                }

                if (account.GroupSettingsId == null)
                {
                    return;
                }
                var settings = _accountSettingsManager.GetSettings((long)account.GroupSettingsId);

                if (settings == null)
                {
                    return;
                }

                var delayTime = settings.UnansweredDelay;
                if (delayTime < 0)
                {
                    return;
                }

                var unansweredMessagesList =
                    new GetUnansweredMessagesQueryHandler(new DataBaseContext()).Handle(new GetUnansweredMessagesQuery
                {
                    DelayTime = delayTime,
                    AccountId = account.Id
                });

                _notice.AddNotice(functionName, accountViewModel.Id, string.Format("Получено {0} неотвеченных сообщений", unansweredMessagesList.Count));

                int i = 1;
                foreach (var unansweredMessage in unansweredMessagesList)
                {
                    _notice.AddNotice(functionName, accountViewModel.Id, string.Format("Отправляем экстра-сообщения друзьям {0}/{1}", i, unansweredMessagesList.Count));
                    var friend = _friendManager.GetFriendById(unansweredMessage.FriendId);

                    new SendMessageCore(_notice).SendMessageToUnanswered(account, friend);

                    Thread.Sleep(3000);

                    i++;
                }
            }
            catch (Exception ex)
            {
                _notice.AddNotice(functionName, accountViewModel.Id, _noticeService.ConvertNoticeText(functionName, string.Format("Возникла ошибка {0}", ex.Message)));
            }
        }
Ejemplo n.º 5
0
        public FriendViewModel GetFriendToWink(AccountViewModel account)
        {
            const string functionName = "Получение друзей для подмигивания";

            _notice.AddNotice(functionName, account.Id, "Получаем друга для подмигиваний");
            var groupId = account.GroupSettingsId;

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

            var settings = _accountSettingsManager.GetSettings((long)groupId);

            var model = new GetFriendToWinkQueryHandler(new DataBaseContext()).Handle(new GetFriendToWinkQuery
            {
                AccountId       = account.Id,
                GroupSettingsId = (long)groupId
            });

            if (model == null)
            {
                _notice.AddNotice(functionName, account.Id, string.Format("Нет ниодного подходящего друга."));
                return(null);
            }

            _notice.AddNotice(functionName, account.Id, string.Format("Получили {0}({1})", model.FriendName, model.FacebookId));

            var testedFriendsId = new List <long> {
                model.FacebookId
            };

            var considerGeoForWink = settings.ConsiderGeoForWinkFriends;

            if (!considerGeoForWink)
            {
                return(new FriendViewModel
                {
                    AddDateTime = model.AddedDateTime,
                    Id = model.Id,
                    Deleted = model.Deleted,
                    FacebookId = model.FacebookId,
                    MessagesEnded = model.DialogIsCompleted,
                    Name = model.FriendName,
                    Href = model.Href,
                    IsAddedToGroups = model.IsAddedToGroups,
                    IsAddedToPages = model.IsAddedToPages,
                    IsWinked = model.IsWinked,
                    MessageRegime = model.MessageRegime,
                    AddedToRemoveDateTime = model.AddedToRemoveDateTime
                });
            }

            var driver = _seleniumManager.RegisterNewDriver(account); // открываем драйвер

            _notice.AddNotice(functionName, account.Id, string.Format("Проверяем гео данные для {0}({1})", model.FriendName, model.FacebookId));

            var isSuccces = new SpyService(null).AnalizeFriend(account, model.FacebookId, settings, driver);

            while (!isSuccces && settings.ConsiderGeoForWinkFriends)
            {
                _notice.AddNotice(functionName, account.Id, string.Format("Не прошел провергу по Гео {0}({1}), берем другого", model.FriendName, model.FacebookId));
                model = new GetFriendToWinkQueryHandler(new DataBaseContext()).Handle(new GetFriendToWinkQuery
                {
                    AccountId       = account.Id,
                    GroupSettingsId = (long)groupId,
                    TestedFriendsId = testedFriendsId
                });

                testedFriendsId.Add(model.FacebookId);

                _notice.AddNotice(functionName, account.Id, string.Format("Проверяем гео данные для {0}({1})", model.FriendName, model.FacebookId));

                isSuccces = new SpyService(null).AnalizeFriend(account, model.FacebookId, settings, driver);

                settings = _accountSettingsManager.GetSettings((long)groupId); //Обновляем настройки
            }

            driver.Quit(); //Закрываем драйвер

            _notice.AddNotice(functionName, account.Id, string.Format("Получили {0}({1})", model.FriendName, model.FacebookId));
            return(new FriendViewModel
            {
                AddDateTime = model.AddedDateTime,
                Id = model.Id,
                Deleted = model.Deleted,
                FacebookId = model.FacebookId,
                MessagesEnded = model.DialogIsCompleted,
                Name = model.FriendName,
                Href = model.Href,
                IsAddedToGroups = model.IsAddedToGroups,
                IsAddedToPages = model.IsAddedToPages,
                IsWinked = model.IsWinked,
                MessageRegime = model.MessageRegime,
                AddedToRemoveDateTime = model.AddedToRemoveDateTime
            });
        }
Ejemplo n.º 6
0
        public void AnalyzeFriends(AccountViewModel accountViewModel)
        {
            var spyAccount = new AccountModel
            {
                Id            = accountViewModel.Id,
                FacebookId    = accountViewModel.FacebookId,
                Login         = accountViewModel.Login,
                Name          = accountViewModel.Name,
                PageUrl       = accountViewModel.PageUrl,
                Password      = accountViewModel.Password,
                Proxy         = accountViewModel.Proxy,
                ProxyLogin    = accountViewModel.ProxyLogin,
                ProxyPassword = accountViewModel.ProxyPassword,
                Cookie        = new CookieModel
                {
                    CookieString = accountViewModel.Cookie
                }
            };

            var driver = _seleniumManager.RegisterNewDriver(accountViewModel); // открываем драйвер для spy

            try
            {
                var friendList = new GetAnalisysFriendsQueryHandler(new DataBaseContext()).Handle(new GetAnalisysFriendsQuery());

                foreach (var analysisFriendData in friendList)
                {
                    var accountAnalysisFriend = _accountManager.GetAccountById(analysisFriendData.AccountId);

                    if (!new AccountManager().HasAWorkingAccount(accountAnalysisFriend.Id))
                    {
                        continue;
                    }

                    var settingsModel = accountAnalysisFriend.GroupSettingsId != null
                        ? _accountSettingsManager.GetSettings((long)accountAnalysisFriend.GroupSettingsId)
                        : new GroupSettingsViewModel();

                    var settings = new GroupSettingsViewModel
                    {
                        GroupId   = settingsModel.GroupId,
                        Gender    = settingsModel.Gender,
                        Countries = settingsModel.Countries,
                        Cities    = settingsModel.Cities
                    };

                    var friendIsSuccess = AnalizeFriend(new AccountViewModel
                    {
                        FacebookId    = spyAccount.FacebookId,
                        Cookie        = spyAccount.Cookie.CookieString,
                        Proxy         = spyAccount.Proxy,
                        ProxyLogin    = spyAccount.ProxyLogin,
                        ProxyPassword = spyAccount.ProxyPassword
                    }, analysisFriendData.FacebookId,
                                                        settings,
                                                        driver);

                    new AnalizeFriendCore().StartAnalyze(new AnalyzeModel
                    {
                        Settings       = settings,
                        AnalysisFriend = analysisFriendData,
                        InfoIsSuccess  = friendIsSuccess,
                        SpyAccountId   = spyAccount.Id
                    });
                }
            }
            catch (Exception)
            {
                driver.Quit();
            }

            driver.Quit();
        }