예제 #1
0
 private void ReadButton_Click(object sender, RoutedEventArgs e)
 {
     if (e.OriginalSource.GetType() == typeof(Button))
     {
         AuthorText text = ((Button)e.OriginalSource).DataContext as AuthorText;
         if (text != null)
         {
             text.IsNew = false;
         }
     }
 }
예제 #2
0
        private void ReadTextButton_Click(object sender, RoutedEventArgs e)
        {
            AuthorText text = (e != null) && (e.OriginalSource.GetType() == typeof(Button))
                                  ? ((Button)e.OriginalSource).DataContext as AuthorText
                                  : sender as AuthorText;

            if (text != null)
            {
                OpenReader(text);
            }
        }
예제 #3
0
 private void authorTextsListBox_PreviewKeyUp(object sender, KeyEventArgs e)
 {
     if ((e.Key == Key.S) && (Keyboard.Modifiers == ModifierKeys.Control))
     {
         AuthorText text = authorTextsListBox.SelectedValue as AuthorText;
         if (text != null)
         {
             SaveButton_Click(text, null);
         }
     }
     if ((e.Key == Key.R) && (Keyboard.Modifiers == ModifierKeys.Control))
     {
         AuthorText text = authorTextsListBox.SelectedValue as AuthorText;
         if (text != null)
         {
             ReadTextButton_Click(text, null);
         }
     }
     if (e.Key == Key.F1)
     {
         AuthorText text = authorTextsListBox.SelectedValue as AuthorText;
         if (text != null)
         {
             OpenReader(text, 1);
         }
     }
     if (e.Key == Key.F2)
     {
         AuthorText text = authorTextsListBox.SelectedValue as AuthorText;
         if (text != null)
         {
             OpenReader(text, 0);
         }
     }
     if (e.Key == Key.F3)
     {
         AuthorText text = authorTextsListBox.SelectedValue as AuthorText;
         if (text != null)
         {
             OpenReader(text, 2);
         }
     }
     if (e.Key == Key.F4)
     {
         AuthorText text = authorTextsListBox.SelectedValue as AuthorText;
         if (text != null)
         {
             OpenReader(text, 3);
         }
     }
 }
예제 #4
0
        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;
            }
        }
예제 #5
0
 private void ShowSelectedURL(Selector listBox)
 {
     try
     {
         AuthorText authorText = (AuthorText)listBox.SelectedValue;
         if (authorText == null)
         {
             return;
         }
         OpenReader(authorText);
         authorText.IsNew = false;
     }
     catch (Exception ex)
     {
         MessageBox.Show("Не удалось открыть страничку\n\n" + ex.Message, "Ошибка", MessageBoxButton.OK,
                         MessageBoxImage.Error);
     }
 }
예제 #6
0
        private void SaveButton_Click(object sender, RoutedEventArgs e)
        {
            AuthorText text = (e != null) && (e.OriginalSource.GetType() == typeof(Button))
                                  ? ((Button)e.OriginalSource).DataContext as AuthorText
                                  : sender as AuthorText;

            if (text != null)
            {
                DownloadTextItem item = DownloadTextHelper.Add(_author, text);
                item.DownloadTextComplete += ItemDownloadSaveComplete;
                if (item.Text == null)
                {
                    item.Start();
                }
                else
                {
                    ItemDownloadSaveComplete(item, null);
                }
            }
        }
예제 #7
0
 private void OpenReader(AuthorText authorText)
 {
     OpenReader(authorText, null);
 }
예제 #8
0
        public static bool UpdateAuthorInfo(string page, Author author)
        {
            Match match = Regex.Match(page, @"Обновлялось:</font></a></b>\s*(.*?)\s*$", RegexOptions.Multiline);
            DateTime date = DateTime.MinValue;
            bool retValue = false;
            if (match.Success)
            {
                string[] newDateStr = match.Groups[1].Value.Split('/');
                date = new DateTime(int.Parse(newDateStr[2]), int.Parse(newDateStr[1]), int.Parse(newDateStr[0]));
            }

            if (author != null)
            {
                #region проанализируем данные на страничке. если раньше их не загружали, то в любом случае не показываем, что есть обновления, просто заполняем данные
                MySortableBindingList<AuthorText> texts_temp = new MySortableBindingList<AuthorText>();
                MatchCollection matches = Regex.Matches(page, "<DL><DT><li>(?:<font.*?>.*?</font>)?\\s*(<b>(?<Authors>.*?)\\s*</b>\\s*)?<A HREF=(?<LinkToText>.*?)><b>\\s*(?<NameOfText>.*?)\\s*</b></A>.*?<b>(?<SizeOfText>\\d+)k</b>.*?<small>(?:Оценка:<b>(?<DescriptionOfRating>(?<rating>\\d+(?:\\.\\d+)?).*?)</b>.*?)?\\s*\"(?<Section>.*?)\"\\s*(?<Genres>.*?)?\\s*(?:<A HREF=\"(?<LinkToComments>.*?)\">Комментарии:\\s*(?<CommentsDescription>(?<CommentCount>\\d+).*?)</A>\\s*)?</small>.*?(?:<br><DD>(?<Description>.*?))?</DL>");
                if (matches.Count > 0)
                {
                    int cnt = 0;
                    foreach (Match m in matches)
                    {
                        AuthorText item = new AuthorText();
                        item.Description = NormalizeHTML(m.Groups["Description"].Value).Trim();
                        item.Genres = NormalizeHTML(m.Groups["Genres"].Value);
                        item.Link = m.Groups["LinkToText"].Value;
                        item.Name = NormalizeHTML(m.Groups["NameOfText"].Value);
                        item.Order = cnt;
                        item.SectionName = NormalizeHTML(m.Groups["Section"].Value).Replace("@","");
                        item.Size = int.Parse(m.Groups["SizeOfText"].Value);
                        texts_temp.Add(item);
                        cnt++;
                    }
                }
                if (author.Texts.Count > 0) // если раньше загружали проводим стравнение
                {
                    foreach (AuthorText txt in texts_temp)
                    {
                        bool bFound = false;
                        for (int i = 0; i < author.Texts.Count; i++)
                        {
                            if (txt.Description == author.Texts[i].Description
                                && txt.Name == author.Texts[i].Name
                                && txt.Size == author.Texts[i].Size)
                            {
                                bFound = true;
                                txt.IsNew = author.Texts[i].IsNew;// переносим значение isNew в новый массив, чтобы не потерять непрочитанные новые тексты
                                break;
                            }
                        }
                        if (!bFound)
                        {
                            txt.IsNew = author.IsNew = retValue = true;// да, автор обновился
                            if (date <= author.UpdateDate) // поменяем дату на сегодняшнюю, если дата обновления на страничке старее, чем зарегистрированная у нас
                                author.UpdateDate = DateTime.Today;
                            else // иначе ставим дату, указанную автором
                                author.UpdateDate = date;
                        }
                    }
                    // доп проверка по количеству произведений
                    if (texts_temp.Count != author.Texts.Count)
                    {
                        retValue = true;
                        if (date <= author.UpdateDate) // поменяем дату на сегодняшнюю, если дата обновления на страничке старее, чем зарегистрированная у нас
                            author.UpdateDate = DateTime.Today;
                        else// иначе ставим дату, указанную автором
                            author.UpdateDate = date;
                    }

                    // запоминаем новые данные
                }
                author.Texts = texts_temp;
                #endregion
            }
            return retValue;
        }
예제 #9
0
        public static bool UpdateAuthorInfo(string page, Author author)
        {
            Match    match    = Regex.Match(page, @"Обновлялось:</font></a></b>\s*(.*?)\s*$", RegexOptions.Multiline);
            DateTime date     = DateTime.MinValue;
            bool     retValue = false;

            if (match.Success)
            {
                string[] newDateStr = match.Groups[1].Value.Split('/');
                date = new DateTime(int.Parse(newDateStr[2]), int.Parse(newDateStr[1]), int.Parse(newDateStr[0]));
            }

            if (author != null)
            {
                #region проанализируем данные на страничке. если раньше их не загружали, то в любом случае не показываем, что есть обновления, просто заполняем данные
                MySortableBindingList <AuthorText> texts_temp = new MySortableBindingList <AuthorText>();
                MatchCollection matches = Regex.Matches(page, "<DL><DT><li>(?:<font.*?>.*?</font>)?\\s*(<b>(?<Authors>.*?)\\s*</b>\\s*)?<A HREF=(?<LinkToText>.*?)><b>\\s*(?<NameOfText>.*?)\\s*</b></A>.*?<b>(?<SizeOfText>\\d+)k</b>.*?<small>(?:Оценка:<b>(?<DescriptionOfRating>(?<rating>\\d+(?:\\.\\d+)?).*?)</b>.*?)?\\s*\"(?<Section>.*?)\"\\s*(?<Genres>.*?)?\\s*(?:<A HREF=\"(?<LinkToComments>.*?)\">Комментарии:\\s*(?<CommentsDescription>(?<CommentCount>\\d+).*?)</A>\\s*)?</small>.*?(?:<br><DD>(?<Description>.*?))?</DL>");
                if (matches.Count > 0)
                {
                    int cnt = 0;
                    foreach (Match m in matches)
                    {
                        AuthorText item = new AuthorText();
                        item.Description = NormalizeHTML(m.Groups["Description"].Value).Trim();
                        item.Genres      = NormalizeHTML(m.Groups["Genres"].Value);
                        item.Link        = m.Groups["LinkToText"].Value;
                        item.Name        = NormalizeHTML(m.Groups["NameOfText"].Value);
                        item.Order       = cnt;
                        item.SectionName = NormalizeHTML(m.Groups["Section"].Value).Replace("@", "");
                        item.Size        = int.Parse(m.Groups["SizeOfText"].Value);
                        texts_temp.Add(item);
                        cnt++;
                    }
                }
                if (author.Texts.Count > 0) // если раньше загружали проводим стравнение
                {
                    foreach (AuthorText txt in texts_temp)
                    {
                        bool bFound = false;
                        for (int i = 0; i < author.Texts.Count; i++)
                        {
                            if (txt.Description == author.Texts[i].Description &&
                                txt.Name == author.Texts[i].Name &&
                                txt.Size == author.Texts[i].Size)
                            {
                                bFound    = true;
                                txt.IsNew = author.Texts[i].IsNew;// переносим значение isNew в новый массив, чтобы не потерять непрочитанные новые тексты
                                break;
                            }
                        }
                        if (!bFound)
                        {
                            txt.IsNew = author.IsNew = retValue = true; // да, автор обновился
                            if (date <= author.UpdateDate)              // поменяем дату на сегодняшнюю, если дата обновления на страничке старее, чем зарегистрированная у нас
                            {
                                author.UpdateDate = DateTime.Today;
                            }
                            else // иначе ставим дату, указанную автором
                            {
                                author.UpdateDate = date;
                            }
                        }
                    }
                    // доп проверка по количеству произведений
                    if (texts_temp.Count != author.Texts.Count)
                    {
                        retValue = true;
                        if (date <= author.UpdateDate) // поменяем дату на сегодняшнюю, если дата обновления на страничке старее, чем зарегистрированная у нас
                        {
                            author.UpdateDate = DateTime.Today;
                        }
                        else// иначе ставим дату, указанную автором
                        {
                            author.UpdateDate = date;
                        }
                    }

                    // запоминаем новые данные
                }
                author.Texts = texts_temp;
                #endregion
            }
            return(retValue);
        }