示例#1
0
        public static void DownloadHeadersFromGroup(IResource group)
        {
            Guard.NullArgument(group, "group");

            if (!Utils.IsNetworkConnectedLight())
            {
                return;
            }

            NewsgroupResource groupResource = new NewsgroupResource(group);
            IResource         server        = groupResource.Server;

            if (server != null)
            {
                NntpConnectionPool.GetConnection(server, "background").StartUnit(
                    Int32.MaxValue - 3, new NntpDownloadHeadersUnit(groupResource, JobPriority.AboveNormal));

                /**
                 * also download bodies if necessary
                 */
                if (new ServerResource(server).DownloadBodiesOnDeliver)
                {
                    NntpConnectionPool.GetConnection(server, "background").StartUnit(
                        0, new NntpDeliverEmptyArticlesFromGroupsUnit(group.ToResourceList(), null));
                }
            }
        }
示例#2
0
        public static void DownloadAllHeadersFromGroup(IResource group)
        {
            Guard.NullArgument(group, "group");

            if (!Utils.IsNetworkConnectedLight())
            {
                return;
            }

            NewsgroupResource groupResource = new NewsgroupResource(group);
            IResource         server        = groupResource.Server;

            if (server != null)
            {
                NntpConnection connection = NntpConnectionPool.GetConnection(server, "background");
                connection.StartUnit(Int32.MaxValue - 5,
                                     new NntpDownloadAllHeadersUnit(groupResource, JobPriority.AboveNormal));
            }
        }
示例#3
0
        public static void PostArticle(IResource draftArticle, AsciiProtocolUnitDelegate finishedMethod, bool invokedByUser)
        {
            Guard.NullArgument(draftArticle, "draftArticle");

            if (!Utils.IsNetworkConnectedLight())
            {
                return;
            }

            lock ( _articlesBeenPosted )
            {
                if (_articlesBeenPosted.Contains(draftArticle))
                {
                    return;
                }
                _articlesBeenPosted.Add(draftArticle);
            }
            IResourceList groups = draftArticle.GetLinksFrom(NntpPlugin._newsGroup, NntpPlugin._propTo);

            if (groups.Count > 0)
            {
                IResource server = new NewsgroupResource(groups[0]).Server;
                if (server != null)
                {
                    NntpConnection      postConnection = NntpConnectionPool.GetConnection(server, "foreground");
                    NntpPostArticleUnit postUnit       =
                        new NntpPostArticleUnit(draftArticle, server, finishedMethod, invokedByUser);
                    postUnit.Finished += postUnit_Finished;
                    postConnection.StartUnit(invokedByUser ? Int32.MaxValue - 2 : 0, postUnit);
                    return;
                }
            }
            ArticlePostedOrFailed(draftArticle);
            if (finishedMethod != null)
            {
                finishedMethod(null);
            }
        }
示例#4
0
        public override void DisplayResource(IResource article, WordPtr[] wordsToHighlight)
        {
            if (_downloadLabel == null)
            {
                _downloadLabel               = new JetLinkLabel();
                _downloadLabel.Text          = "Click here or press F5 to download the article";
                _downloadLabel.BackColor     = Color.Transparent;
                _downloadLabel.ClickableLink = true;
                _downloadLabel.Click        += _downloadLabel_Click;
                Controls.Add(_downloadLabel);
            }
            _downloadLabel.Visible = false;
            _ieBrowser.Visible     = true;
            bool redisplayed = _articleIsRedisplayed;

            _articleIsRedisplayed = false;

            DisposeArticleListener();

            // Set the subject, highlight if needed
            ShowSubject(article.GetPropText(Core.Props.Subject), wordsToHighlight);

            try
            {
                //  The content being indexed (plaintext) is not the same that is
                //  displayed (autogenerated HTML), so the offsets are updated by
                //  this method to correspond to the new formatting.
                string sFormattedArticle = ArticleBody2Html(article, ref wordsToHighlight);
                ShowHtml(sFormattedArticle, _ctxRestricted, wordsToHighlight);
            }
            catch (Exception e)
            {
                Utils.DisplayException(e, "Error");
                return;
            }

            /**
             * set last selected article for article's owner
             */
            IResource owner = _rbrowser.OwnerResource;

            if (owner != null && (owner.Type == NntpPlugin._newsGroup ||
                                  owner.Type == NntpPlugin._newsFolder || owner.Type == NntpPlugin._newsServer))
            {
                ResourceProxy proxy = new ResourceProxy(owner);
                proxy.AsyncPriority = JobPriority.AboveNormal;
                proxy.SetPropAsync(NntpPlugin._propLastSelectedArticle, article.Id);
            }

            _articleListener = article.ToResourceListLive();
            _articleListener.ResourceChanged += _articleListener_ResourceChanged;

            bool hasNoBody = article.HasProp(NntpPlugin._propHasNoBody);

            if (!hasNoBody)
            {
                Core.UIManager.GetStatusWriter(this, StatusPane.Network).ClearStatus();
            }
            else
            {
                if (!Utils.IsNetworkConnectedLight())
                {
                    ShowHtml("<pre>" + NntpPlugin._networkUnavailable + ".</pre>", WebSecurityContext.Internet, null);
                    return;
                }
                IResourceList groups = article.GetLinksOfType(NntpPlugin._newsGroup, NntpPlugin._propTo);
                if (groups.Count > 0)
                {
                    foreach (IResource groupRes in groups.ValidResources)
                    {
                        IResource server = new NewsgroupResource(groupRes).Server;
                        if (server != null)
                        {
                            ServerResource serverRes = new ServerResource(server);
                            if (redisplayed || serverRes.DownloadBodiesOnDeliver || serverRes.DownloadBodyOnSelection)
                            {
                                Core.UIManager.GetStatusWriter(this, StatusPane.Network).ShowStatus("Downloading article...");
                                NntpConnection          articlesConnection = NntpConnectionPool.GetConnection(server, "foreground");
                                NntpDownloadArticleUnit downloadUnit       =
                                    new NntpDownloadArticleUnit(article, groupRes, JobPriority.Immediate, true);
                                downloadUnit.OnProgress += downloadUnit_OnProgress;
                                ShowHtml("<pre>Downloading article: 0%</pre>", WebSecurityContext.Internet, null);
                                articlesConnection.StartUnit(Int32.MaxValue - 1, downloadUnit);
                                return;
                            }
                        }
                    }
                    if (!redisplayed)
                    {
                        Point location = _ieBrowser.Location;
                        _downloadLabel.Location = new Point(location.X + 8, location.Y + 8);
                        _downloadLabel.Visible  = true;
                        _ieBrowser.Visible      = false;
                    }
                }
            }
        }
示例#5
0
        public static void DeliverNewsFromServer(IResource server,
                                                 IResource preferableGroup,
                                                 bool invokedByUser,
                                                 AsciiProtocolUnitDelegate finishedMethod)
        {
            Guard.NullArgument(server, "server");

            ServerResource serverResource = new ServerResource(server);

            if (Utils.IsNetworkConnectedLight())
            {
                NntpConnection connection = NntpConnectionPool.GetConnection(server, "background");
                IResourceList  groups     = serverResource.Groups;

                if (groups.Count > 0)
                {
                    /**
                     * at first deliver news from prefered group
                     */
                    if (preferableGroup != null && groups.Contains(preferableGroup))
                    {
                        connection.StartUnit(Int32.MaxValue - 2,
                                             new NntpDownloadHeadersUnit(new NewsgroupResource(preferableGroup), JobPriority.AboveNormal));
                        if (serverResource.DownloadBodiesOnDeliver)
                        {
                            connection.StartUnit(Int32.MaxValue - 3,
                                                 new NntpDeliverEmptyArticlesFromGroupsUnit(preferableGroup.ToResourceList(), null));
                        }
                    }

                    /**
                     * then deliver headers of other groups
                     */
                    NntpDeliverHeadersFromGroupsUnit deliverHeadersFromGroupsUnit =
                        new NntpDeliverHeadersFromGroupsUnit(groups, preferableGroup);
                    if (finishedMethod != null)
                    {
                        deliverHeadersFromGroupsUnit.Finished += finishedMethod;
                    }
                    int clientPriority = 0;
                    if (invokedByUser && preferableGroup != null && groups.Contains(preferableGroup))
                    {
                        clientPriority = Int32.MaxValue - 3;
                    }
                    connection.StartUnit(clientPriority, deliverHeadersFromGroupsUnit);

                    /**
                     * then download empty bodies
                     */
                    if (serverResource.DownloadBodiesOnDeliver)
                    {
                        NntpDeliverEmptyArticlesFromGroupsUnit deliverEmptyArticlesUnit =
                            new NntpDeliverEmptyArticlesFromGroupsUnit(groups, preferableGroup);
                        if (finishedMethod != null)
                        {
                            deliverEmptyArticlesUnit.Finished += finishedMethod;
                        }
                        connection.StartUnit(clientPriority, deliverEmptyArticlesUnit);
                    }
                }

                /**
                 * finally replicate new groups
                 */
                NntpDownloadGroupsUnit groupsUnit = new NntpDownloadGroupsUnit(server, false, JobPriority.Lowest);
                if (finishedMethod != null)
                {
                    groupsUnit.Finished += finishedMethod;
                }
                connection.StartUnit(0, groupsUnit);
            }

            /**
             * queue timed news delivering is necessary
             */
            int freq = serverResource.DeliverFreq;

            if (freq > 0)
            {
                Core.NetworkAP.QueueJobAt(
                    DateTime.Now.AddMinutes(freq), new ResourceDelegate(DeliverNewsFromServer), server);
            }
        }