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); }
/// <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); }
/// <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); }
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); } } }
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); }
/// <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); }
public FetchNewsgroupsThreadHandler(RssBanditApplication app, INntpServerDefinition sd) { this.app = app; this.serverDef = sd; this.Newsgroups = new List <string>(0); }
private void RemoveCachedGroups(INntpServerDefinition sd) { RemoveCachedGroups(BuildCacheFileName(sd)); }
private string BuildCacheFileName(INntpServerDefinition sd) { return(Path.Combine(cachePath, String.Format("{0}_{1}.xml", sd.Server, sd.Port != 0 ? sd.Port : NntpWebRequest.NntpDefaultServerPort))); }
public static Uri BuildNntpRequestUri(INntpServerDefinition sd) { return(BuildNntpRequestUri(sd, null)); }
/// <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>()); }