public override void EditBulletins(IEnumerable <TaskCache_old> tasks) { DCT.Execute(d => { var accessContainer = AccessContainerList.Get(Uid); foreach (var task in tasks) { var bulletin = task.BulletinPackage; if (accessContainer.TryAuth(bulletin.Access)) { PrepareBulletin(bulletin); ContinueAddOrEdit(EnumHelper.GetValue <BulletinState>(bulletin.State)); Publicate(bulletin); } } DCT.ExecuteAsync(d2 => { foreach (var task in tasks) { var bulletin = task.BulletinPackage; if (string.IsNullOrEmpty(bulletin.Url)) { bulletin.State = (int)BulletinState.Error; task.State = (int)TaskCacheState.Error; } else { bulletin.State = (int)BulletinState.OnModeration; task.State = (int)TaskCacheState.Completed; } } //DriverTaskHelper.Complete(tasks); }); }); }
IEnumerable <BulletinPackage> GetBulletinList(AccessCache access) { var result = Enumerable.Empty <BulletinPackage>(); DCT.Execute(d => { var tabStates = new List <TabState>(); var bulletins = new List <BulletinPackage>(); var fieldValueContainer = FieldValueContainerList.Get(Uid); var accessContainer = AccessContainerList.Get(Uid); UiHelper.UpdateActionState("Попытка авторизоваться"); if (accessContainer.TryAuth(access)) { Thread.Sleep(2000); UiHelper.UpdateActionState("Ожидание прогрузки страницы"); Thread.Sleep(2000); UiHelper.UpdateActionState("Переход на страницу профиля"); Thread.Sleep(2000); UiHelper.UpdateActionState("Считывание списка буллетинов"); Thread.Sleep(2000); } result = bulletins; }); return(result); }
public override void GetBulletinDetails(IEnumerable <TaskCache_old> tasks) { DCT.Execute(d => { var accessContainer = AccessContainerList.Get(Uid); var packages = tasks.Select(q => q.BulletinPackage); var accessCollection = packages.Where(q => q.Access != null).GroupBy(q => q.Access.Login).Select(q => new { Access = q.Key, Collection = q.ToList() }).ToList(); foreach (var a in accessCollection) { var bulletins = a.Collection; foreach (var bulletin in bulletins) { Thread.Sleep(2000); var url = Path.Combine(bulletin.Url, "edit"); WebDriver.NavigatePage(url); Thread.Sleep(1500); var values = new Dictionary <string, string>(); foreach (var pair in bulletin.AccessFields) { } } } }); }
public override void GetBulletinDetails(IEnumerable <BulletinPackage> packages) { UiHelper.UpdateWorkState("Выгрузка полей для списка буллетинов"); DCT.Execute(d => { { var fieldValueContainer = FieldValueContainerList.Get(Uid); var accessContainer = AccessContainerList.Get(Uid); var accessCollection = packages.Cast <BulletinPackage>().Where(q => q.Access != null).GroupBy(q => q.Access.Login).Select(q => new { Access = q.Key, Collection = q.ToList() }).ToList(); foreach (var a in accessCollection) { UiHelper.UpdateObjectState($"Access {a.Access}"); var bulletins = a.Collection; foreach (var bulletin in bulletins) { UiHelper.UpdateActionState("Попытка авторизоваться"); Thread.Sleep(2000); if (accessContainer.TryAuth(bulletin.Access)) { Thread.Sleep(1000); var url = Path.Combine(bulletin.Url, "edit"); UiHelper.UpdateActionState($"Переход на страницу {url}"); Thread.Sleep(2000); var values = new Dictionary <string, string>(); foreach (var pair in bulletin.AccessFields) { var v = fieldValueContainer.GetFieldValue(bulletin.AccessFields, pair.Key); values.Add(pair.Key, v); } bulletin.ValueFields = values; bulletin.State = (int)CheckBulletinState(bulletin.Url); } } } } { UiHelper.UpdateActionState("Отправка коллбека"); Thread.Sleep(1000); } }); }
public override void EditBulletins(IEnumerable <BulletinPackage> packages) { DCT.Execute(d => { { var fieldValueContainer = FieldValueContainerList.Get(Uid); var accessContainer = AccessContainerList.Get(Uid); foreach (var bulletin in packages) { var name = bulletin.ValueFields["Название объявления"]; UiHelper.UpdateObjectState($"Bulletin {name}, state = {bulletin.State}"); UiHelper.UpdateActionState("Попытка авторизоваться"); if (accessContainer.TryAuth(bulletin.Access)) { UiHelper.UpdateActionState("Ожидание прогрузки страницы"); Thread.Sleep(2000); Tools.WebWorker.NavigatePage(Path.Combine(bulletin.Url, "edit")); UiHelper.UpdateActionState("Установка значений"); Thread.Sleep(1000); SetValueFields(bulletin, fieldValueContainer); Thread.Sleep(1000); ContinueAddOrEdit(EnumHelper.GetValue <BulletinState>(bulletin.State)); Thread.Sleep(1000); Publicate(bulletin); } } } { foreach (var b in packages) { b.State = (int)BulletinState.OnModeration; var name = b.ValueFields["Название объявления"]; UiHelper.UpdateObjectState($"Bulletin {name}, state = {b.State}"); Thread.Sleep(1000); } UiHelper.UpdateActionState("Отправка коллбека"); Thread.Sleep(1000); } }); }
IEnumerable <BulletinPackage> GetBulletinList(AccessCache access) { var result = Enumerable.Empty <BulletinPackage>(); DCT.Execute(d => { var tabStates = new List <TabState>(); var bulletins = new List <BulletinPackage>(); var accessContainer = AccessContainerList.Get(Uid); if (accessContainer.TryAuth(access)) { WebDriver.NavigatePage(ProfileUrl); var tabs = WebDriver.FindMany(By.ClassName("tabs-item")); tabStates.Add(new TabState { Title = "Активные", Href = ProfileUrl }); foreach (var tab in tabs) { var a = tab.FindElement(By.XPath("/a")); var tabUrl = a.GetAttribute("href"); var tabState = a.Text; if (tabState == "Удаленные") { continue; } tabStates.Add(new TabState { Title = tabState, Href = tabUrl, }); } foreach (var tabState in tabStates) { var bulletinState = GetStateFromTabString(tabState.Title); if (bulletinState == BulletinState.Blocked || bulletinState == BulletinState.Removed) { continue; } WebDriver.NavigatePage(tabState.Href); var nextPages = new List <string>(); nextPages.Add(tabState.Href); var hasNextPage = true; do { var bulletinOnPage = GetBulletinPages(tabState.Title); bulletins.AddRange(bulletinOnPage); var nextPage = WebDriver.Find(By.ClassName("js-pagination-next")); if (nextPage == null) { hasNextPage = false; } else { var nextPageHref = nextPage.GetAttribute("href"); nextPages.Add(nextPageHref); hasNextPage = true; nextPage.Click(); Thread.Sleep(1000); } } while (hasNextPage); } foreach (var bulletin in bulletins) { var url = Path.Combine(bulletin.Url, "edit"); WebDriver.NavigatePage(url); Thread.Sleep(1500); var groupElement = WebDriver.Find(By.ClassName("form-category-path")); if (groupElement == null) { continue; } var categories = groupElement.Text.Split('/').Select(q => q.Trim()).ToArray(); bulletin.Signature = new GroupSignature(categories); bulletin.Access = access; } result = bulletins; } }); return(result); }
public override void CloneBulletins(IEnumerable <AggregateBulletinPackage> packages) { UiHelper.UpdateWorkState("Клонирование буллетинов"); DCT.Execute(d => { var createdBulletins = new List <BulletinPackage>(); { var fieldValueContainer = FieldValueContainerList.Get(Uid); var accessContainer = AccessContainerList.Get(Uid); foreach (var package in packages) { var name = package.Bulletin.ValueFields["Название объявления"]; UiHelper.UpdateObjectState($"Bulletin {name}, state = {package.Bulletin.State}"); UiHelper.UpdateActionState("Попытка авторизоваться"); var accesses = package.Accesses.ToArray(); foreach (var access in accesses) { if (accessContainer.TryAuth(access)) { UiHelper.UpdateActionState("Ожидание прогрузки страницы"); Thread.Sleep(2000); UiHelper.UpdateActionState("Переход на страницу - additem"); Thread.Sleep(1000); UiHelper.UpdateActionState("Выбор категорий"); ChooseCategories(package.Bulletin.Signature); UiHelper.UpdateActionState("Установка значений"); Thread.Sleep(1000); SetValueFields(package.Bulletin, fieldValueContainer); ContinueAddOrEdit(BulletinState.WaitPublication); Thread.Sleep(1000); Publicate(package.Bulletin); // Thread.Sleep(20000); GetUrl(package.Bulletin); var newBulletin = new BulletinPackage { Access = access, BulletinId = package.Bulletin.BulletinId, Url = package.Bulletin.Url, Title = package.Bulletin.Title, State = package.Bulletin.State, Signature = package.Bulletin.Signature, ValueFields = package.Bulletin.ValueFields }; createdBulletins.Add(newBulletin); } } } } { UiHelper.UpdateActionState("Проверка Url и установка состояний"); Thread.Sleep(1000); foreach (var p in packages) { var name = p.Bulletin.ValueFields["Название объявления"]; UiHelper.UpdateObjectState($"Bulletin {name}, state = {p.Bulletin.State}"); } UiHelper.UpdateActionState("Отправка коллбека"); Thread.Sleep(1000); } }); }
public override void AddBulletins(IEnumerable <BulletinPackage> packages) { UiHelper.UpdateWorkState("Добавление списка буллетинов"); DCT.Execute(d => { var createdBulletins = new List <BulletinPackage>(); { var fieldValueContainer = FieldValueContainerList.Get(Uid); var accessContainer = AccessContainerList.Get(Uid); foreach (var bulletin in packages) { var name = bulletin.ValueFields["Название объявления"]; UiHelper.UpdateObjectState($"Bulletin {name}, state = {bulletin.State}"); UiHelper.UpdateActionState("Попытка авторизоваться"); if (accessContainer.TryAuth(bulletin.Access)) { UiHelper.UpdateActionState("Ожидание прогрузки страницы"); Thread.Sleep(2000); UiHelper.UpdateActionState("Переход на страницу - additem"); Thread.Sleep(1000); UiHelper.UpdateActionState("Выбор категорий"); ChooseCategories(bulletin.Signature); UiHelper.UpdateActionState("Установка значений"); Thread.Sleep(1000); SetValueFields(bulletin, fieldValueContainer); Thread.Sleep(1000); ContinueAddOrEdit(EnumHelper.GetValue <BulletinState>(bulletin.State)); Thread.Sleep(1000); Publicate(bulletin); Thread.Sleep(1000); GetUrl(bulletin); Thread.Sleep(1000); } } } { DCT.ExecuteAsync(d2 => { UiHelper.UpdateActionState("Проверка Url и установка состояний"); Thread.Sleep(1000); foreach (var b in packages) { if (string.IsNullOrEmpty(b.Url)) { b.State = (int)BulletinState.Error; } else { b.State = (int)BulletinState.OnModeration; } var name = b.ValueFields["Название объявления"]; UiHelper.UpdateObjectState($"Bulletin {name}, state = {b.State}"); } UiHelper.UpdateActionState("Отправка коллбека"); Thread.Sleep(1000); }); } }); }