public static void AddAuthor(string url) { SetStatus("Добавление автора..."); if (!url.EndsWith("indexdate.shtml")) { url = (url.EndsWith("/")) ? url + "indexdate.shtml" : url + "/indexdate.shtml"; } byte[] buffer; WebClient client = new WebClient(); string error = "Страничка не входит в круг наших интересов."; try { buffer = WEB.downloadPageSilent(client, url); string page = WEB.convertPage(buffer); int si = page.IndexOf('.', page.IndexOf("<title>")) + 1; DateTime updateDate = GetUpdateDate(page); if (updateDate != DateTime.MinValue) { string authorName = page.Substring(si, page.IndexOf('.', si) - si); if (FindAuthor(url) != null) { error = authorName + " уже присутствует в списке"; throw new Exception(); } Author author = new Author() { Name = authorName, IsNew = false, UpdateDate = updateDate, URL = url }; authors.Add(author); // запоминаем информацию со странички автора UpdateAuthorInfo(page, author); // сортируем данные по дате Sort(); // сохраняем конфиг SaveConfig(); SetStatus("Добавлен: " + author.Name); } else { SetStatus(error); } } catch (Exception) { SetStatus(error); } }
private void OpenReader(AuthorText authorText, int?readerType) { if (readerType == null) { readerType = MainWindow.GetSettings().DefaultReader; } readerType = readerType ?? 0; var site = Logic.Sites.SitesDetector.GetSite(_author.URL); if (site != null) { readerType = site.GetSupportedReaderNumber((int)readerType); } string url = authorText.GetFullLink(_author); switch (readerType) { case 0: // веб-страничка WEB.OpenURL(url.Trim()); break; case 1: // внутренняя читалка case 3: // другая читалка DownloadTextItem item = DownloadTextHelper.Add(_author, authorText); item.ReaderType = readerType; item.DownloadTextComplete += ItemDownloadTextComplete; if (item.Text == null) { item.Start(); } else { ItemDownloadTextComplete(item, null); } break; case 2: // Aj-reader string aj = "http://samlib.ru/img/m/mertwyj_o_a/aj.shtml?" + url.Replace("http://samlib.ru/", ""); WEB.OpenURL(aj.Trim()); break; default: break; } }
private static bool UpdateAuthor(Author author) { byte[] buffer; WebClient client = new WebClient(); bool retValue = false; try { if (!author.URL.EndsWith("indexdate.shtml")) { author.URL = (author.URL.EndsWith("/")) ? author.URL + "indexdate.shtml" : author.URL + "/indexdate.shtml"; } buffer = WEB.downloadPageSilent(client, author.URL); if (buffer != null) { retValue = UpdateAuthorInfo(WEB.convertPage(buffer), author); } } catch (Exception exception) { } return(retValue); }