Example #1
0
        private void SyncRun(object state)
        {
            Action action = ((RunContent)state).Action;
            object body   = ((RunContent)state).Body;

            switch (action)
            {
            case Action.SetStatus:
                var param = (SetStatusParam)body;
                _logger.Add(param.Message, param.ToMessage, param.IsError);
                break;

            case Action.IsUpdaterTrue:
                ((Author)body).IsUpdated = true;
                break;

            case Action.IsUpdaterFalse:
                ((Author)body).IsUpdated = false;
                break;

            case Action.UpdateAuthorText:
                var updateTextParam = (UpdateTextParam)body;
                if (updateTextParam.IsNew)
                {
                    _logger.Add(string.Format("{1}/{2}: '{0}' обновлен", updateTextParam.Author.Name,
                                              updateTextParam.Index, updateTextParam.Count));
                    if (_baloonInfo == "")
                    {
                        _baloonInfo = "Обновились авторы:\n";
                    }
                    _baloonInfo = _baloonInfo + updateTextParam.Author.Name + "; ";
                }
                break;

            case Action.CachedAdd:
                var cachedParamAdd    = (CachedParam)body;
                DownloadTextItem item = DownloadTextHelper.Add(cachedParamAdd.Author, cachedParamAdd.AuthorText);
                if (item.Text == null)
                {
                    item.Start();
                }
                cachedParamAdd.DownloadTextItem = item;
                break;

            case Action.CachedRemove:
                var cachedParamRemove = (CachedParam)body;
                cachedParamRemove.DownloadTextItem.Stop();
                break;

            default:
                throw new ArgumentOutOfRangeException("state");
            }
        }
        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 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);
                }
            }
        }