コード例 #1
0
        public static Uri BuildNntpRequestUri(INntpServerDefinition sd, string nntpGroup)
        {
            // We do not use NntpWebRequest.NewsUriScheme here ("news"),
            // because the UriBuilder build the Uri without slashes...
            string schema = NntpWebRequest.NntpUriScheme;

            if (sd.UseSSL)
            {
                schema = NntpWebRequest.NntpsUriScheme;
            }

            int port = NntpWebRequest.NntpDefaultServerPort;

            if (sd.Port > 0 && sd.Port != NntpWebRequest.NntpDefaultServerPort)
            {
                port = sd.Port;
            }

            UriBuilder uriBuilder;

            if (string.IsNullOrEmpty(nntpGroup))
            {
                uriBuilder = new UriBuilder(schema, sd.Server, port);
            }
            else
            {
                uriBuilder = new UriBuilder(schema, sd.Server, port, nntpGroup);
            }
            return(uriBuilder.Uri);
        }
コード例 #2
0
        /// <summary>
        /// Really loads the group list from the server.
        /// </summary>
        /// <param name="owner">Windows handle</param>
        /// <param name="sd">NntpServerDefinition</param>
        /// <returns>List of groups a server offer</returns>
        /// <exception cref="ArgumentNullException">If <see paramref="sd">param sd</see> is null</exception>
        /// <exception cref="Exception">On any failure we get on request</exception>
        IList <string> FetchNewsGroupsFromServer(IWin32Window owner, INntpServerDefinition sd)
        {
            if (sd == null)
            {
                throw new ArgumentNullException("sd");
            }

            FetchNewsgroupsThreadHandler threadHandler = new FetchNewsgroupsThreadHandler(app, sd);
            DialogResult result = threadHandler.Start(owner, SR.NntpLoadingGroupsWaitMessage, true);

            if (DialogResult.OK != result)
            {
                return(new List <string>(0));     // cancelled
            }
            if (!threadHandler.OperationSucceeds)
            {
                MessageBox.Show(String.Format(
                                    SR.ExceptionNntpLoadingGroupsFailed, sd.Server, threadHandler.OperationException.Message),
                                SR.GUINntpLoadingGroupsFailedCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(new List <string>(0));     // failed
            }

            return(threadHandler.Newsgroups);
        }
コード例 #3
0
        /// <summary>
        /// Return ICredentials of a feed.
        /// </summary>
        /// <param name="sd">NntpServerDefinition</param>
        /// <returns>null in the case the nntp server does not have credentials</returns>
        public ICredentials GetFeedCredentials(INntpServerDefinition sd)
        {
            ICredentials c = null;

            if (sd.AuthUser != null)
            {
                string u, p;
                GetNntpServerCredentials(sd, out u, out p);
                c = CreateCredentialsFrom(u, p);
            }
            return(c);
        }
コード例 #4
0
        private void SaveNewsGroupsToCache(INntpServerDefinition sd, ICollection <string> list)
        {
            string fn = BuildCacheFileName(sd);

            RemoveCachedGroups(fn);

            if (list != null && list.Count > 0)
            {
                try {
                    using (StreamWriter w = new StreamWriter(FileHelper.OpenForWrite(fn))) {
                        foreach (string line in list)
                        {
                            w.WriteLine(line);
                        }
                    }
                } catch (Exception ex) {
                    _log.Error("SaveNewsGroupsToCache() failed to save '" + fn + "'", ex);
                }
            }
        }
コード例 #5
0
        private IList <string> LoadNewsGroupsFromCache(INntpServerDefinition sd)
        {
            List <string> result = new List <string>();
            string        fn     = BuildCacheFileName(sd);

            if (File.Exists(fn))
            {
                try {
                    using (StreamReader r = new StreamReader(FileHelper.OpenForRead(fn))) {
                        string line = r.ReadLine();
                        while (line != null)
                        {
                            result.Add(line);
                            line = r.ReadLine();
                        }
                    }
                } catch (Exception ex) {
                    _log.Error("LoadNewsGroupsFromCache() failed to load '" + fn + "'", ex);
                }
            }

            return(result);
        }
コード例 #6
0
        /// <summary>
        /// Load the list of groups from either the cache, or if not available or forced
        /// from the nntp server.
        /// </summary>
        /// <param name="owner">Windows handle</param>
        /// <param name="sd">NntpServerDefinition</param>
        /// <param name="forceLoadFromServer">set to true, if a 'fresh' group list should be loaded from the server</param>
        /// <returns>List of groups a server offer</returns>
        public IList <string> LoadNntpNewsGroups(IWin32Window owner, INntpServerDefinition sd, bool forceLoadFromServer)
        {
            IList <string> list;

            if (forceLoadFromServer)
            {
                list = FetchNewsGroupsFromServer(owner, sd);
                if (list != null && list.Count > 0)
                {
                    SaveNewsGroupsToCache(sd, list);
                }
                else
                {
                    RemoveCachedGroups(sd);
                }
            }
            else
            {
                list = LoadNewsGroupsFromCache(sd);
            }

            return(list);
        }
コード例 #7
0
 public FetchNewsgroupsThreadHandler(RssBanditApplication app, INntpServerDefinition sd)
 {
     this.app        = app;
     this.serverDef  = sd;
     this.Newsgroups = new List <string>(0);
 }
コード例 #8
0
 private void RemoveCachedGroups(INntpServerDefinition sd)
 {
     RemoveCachedGroups(BuildCacheFileName(sd));
 }
コード例 #9
0
 private string BuildCacheFileName(INntpServerDefinition sd)
 {
     return(Path.Combine(cachePath, String.Format("{0}_{1}.xml", sd.Server, sd.Port != 0 ? sd.Port : NntpWebRequest.NntpDefaultServerPort)));
 }
コード例 #10
0
 public static Uri BuildNntpRequestUri(INntpServerDefinition sd)
 {
     return(BuildNntpRequestUri(sd, null));
 }
コード例 #11
0
 /// <summary>
 /// Gets (filters) the current subscriptions for Nntp feeds of a specific nntp server.
 /// </summary>
 /// <param name="sd">NntpServerDefinition</param>
 /// <returns>List of NewsFeed objects, that match</returns>
 public IList <NewsFeed> CurrentSubscriptions(INntpServerDefinition sd)
 {
     //TODO: impl. CurrentSubscriptions()
     return(new List <NewsFeed>());
 }