public static ForumThread ConvertToForumThread(this _ForumThreadResult thread) { return(new ForumThread { StatusCode = (int)HttpStatusCode.OK, Title = thread.Channel?.Title, Description = thread.Channel?.Description, Language = thread.Channel?.Language, LastBuildDate = (DateTime)thread.Channel?.LastBuildDate.GetSafeDateTime(), PublicationDate = (DateTime)thread.Channel?.PublicationDate.GetSafeDateTime(), Link = thread.Channel?.Link, Webmaster = thread.Channel?.Webmaster, Image = ConvertForumThreadImage(thread.Channel?.Image), Comments = ConvertForumThreadComments(thread.Channel?.Items) }); }
public async Task <ForumThread> GetForumThread(int id, RetrySettings retrySettings, int?startArticle = null, int?count = null, string username = null) { string uri = $"{Endpoints.GET_FORUM_THREAD}/{id}"; List <string> queryParams = new List <string>(); if (startArticle.HasValue) { queryParams.Add($"start={startArticle.Value}"); } if (count.HasValue) { queryParams.Add($"count={count.Value}"); } if (!string.IsNullOrEmpty(username)) { queryParams.Add($"username={username}"); } if (queryParams.Any()) { uri = uri + $"?{string.Join("&", queryParams)}"; } HttpResponseMessage resp = null; _ForumThreadResult result = null; bool done = false; int retry = 0; TimeSpan waitSeconds = TimeSpan.FromSeconds(Math.Max(retrySettings.WaitSeconds, 1)); while (!done) { resp = await xmlRestClient.GetAsync(uri); if (!resp.IsSuccessStatusCode) { return(new ForumThread { StatusCode = (int)resp.StatusCode }); } result = await resp.Content.DeserializeXml <_ForumThreadResult>(); if (DateTime.Parse(result.Channel?.PublicationDate).Year <= 1970) { if (!retrySettings.Retry || retry >= retrySettings.RetryCount) { done = true; } else { retry += 1; Thread.Sleep(waitSeconds); } } else { done = true; } } return(result.ConvertToForumThread()); }