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 }); }
public void WinkFriendsFriends(AccountViewModel account) { const string functionName = "Подмигнуть друзьям друзей"; try { _notice.AddNotice(functionName, account.Id, string.Format("Начинаем подмигивать друзьям друзей.")); if (account.GroupSettingsId == null) { return; } var friends = new GetFriendsToWinkFriendsFriendsQueryHandler(new DataBaseContext()).Handle( new GetFriendsToWinkFriendsFriendsQuery { AccountId = account.Id, GroupSettingsId = (long)account.GroupSettingsId, CountFriends = 5 }); if (friends == null) { _notice.AddNotice(functionName, account.Id, string.Format("Друзья для подмигивания не найдены.")); return; } _notice.AddNotice(functionName, account.Id, string.Format("Получаем друзей друзей...")); var friendsFriendsToWink = new GetRandomFriendFriendsEngine().Execute( new GetRandomFriendFriendsModel { Proxy = _accountManager.GetAccountProxy(account), Cookie = account.Cookie, AccountFacebookId = account.FacebookId, Driver = _seleniumManager.RegisterNewDriver(account), FriendsIdList = friends.Select(model => new GetRandomFriendModel { FriendId = model.FriendId, FriendFacebookId = model.FriendFacebookId }).ToList() }); if (friendsFriendsToWink == null) { _notice.AddNotice(functionName, account.Id, string.Format("Друзья друзей для подмигивания не найдены.")); return; } _notice.AddNotice(functionName, account.Id, string.Format("Друзья друзей получены, начинаем подмигивать.")); var settings = _accountSettingsManager.GetSettings((long)account.GroupSettingsId); if (settings.ConsiderGeoForWinkFriendsFriends) { var driver = _seleniumManager.RegisterNewDriver(account); // открываем драйвер try { foreach (var friendFacebook in friendsFriendsToWink) { _notice.AddNotice(functionName, account.Id, string.Format("Проверяем Гео для ({0})", friendFacebook.FriendFriendFacebookId)); var isSuccces = new SpyService(null).AnalizeFriend(account, friendFacebook.FriendFriendFacebookId, settings, driver); if (isSuccces) { _notice.AddNotice(functionName, account.Id, string.Format("Подмигиваем другу друга({0})", friendFacebook.FriendFriendFacebookId)); new WinkEngine().Execute(new WinkModel { AccountFacebookId = account.FacebookId, Proxy = _accountManager.GetAccountProxy(account), Cookie = account.Cookie, FriendFacebookId = Convert.ToInt64(friendFacebook.FriendFriendFacebookId), UrlParameters = new GetUrlParametersQueryHandler(new DataBaseContext()).Handle(new GetUrlParametersQuery { NameUrlParameter = NamesUrlParameter.Wink }) }); new MarkWinksFriendsFriendsCommandHandler(new DataBaseContext()).Handle(new MarkWinksFriendsFriendsCommand { FriendId = friendFacebook.FriendId, AccountId = account.Id }); } } } catch (Exception ex) { _notice.AddNotice(functionName, account.Id, string.Format("Произошла оибка - {0}", ex.Message)); } driver.Quit(); } else { foreach (var friendFacebook in friendsFriendsToWink) { _notice.AddNotice(functionName, account.Id, string.Format("Подмигиваем другу друга({0})", friendFacebook.FriendFriendFacebookId)); new WinkEngine().Execute(new WinkModel { AccountFacebookId = account.FacebookId, Proxy = _accountManager.GetAccountProxy(account), Cookie = account.Cookie, FriendFacebookId = Convert.ToInt64(friendFacebook.FriendFriendFacebookId), UrlParameters = new GetUrlParametersQueryHandler(new DataBaseContext()).Handle(new GetUrlParametersQuery { NameUrlParameter = NamesUrlParameter.Wink }) }); new MarkWinksFriendsFriendsCommandHandler(new DataBaseContext()).Handle(new MarkWinksFriendsFriendsCommand { FriendId = friendFacebook.FriendId, AccountId = account.Id }); } } } catch (Exception ex) { _notice.AddNotice(functionName, account.Id, string.Format("Произошла оибка - {0}", ex.Message)); } }