Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
        }