Example #1
0
 public void OnOnlineUpdated(BoardTableUpdateEventArgs e)
 {
     lastModified = e.LastModified;
     updateCompleted = true;
     if (OnlineUpdated != null)
     {
         OnlineUpdated(this, e);
     }
 }
Example #2
0
        /// <summary>
        /// 板一覧を指定したURLでアップデート
        /// </summary>
        /// <param name="url"></param>
        public void OnlineUpdate(string url)
        {
            BoardTableUpdateEventArgs e = new BoardTableUpdateEventArgs();
            e.LastModified = lastModified;
            try
            {
                InternetClient.DownloadResult result = InternetClient.DownloadData(url, lastModified);
                if (!result.Success)
                {
                    OnOnlineUpdated(e);
                    return;
                }

                e.LastModified = result.LastModified;
                CategoryCollection categories = new CategoryCollection();
                string[] maybeCategoryTexts = Regex.Split(result.Data, @"^\s*${3,}?", RegexOptions.Multiline);
                foreach (string maybeCategoryText in maybeCategoryTexts)
                {
                    Match categoryName = CategoryNamePattern.Match(maybeCategoryText);
                    if (!categoryName.Success)
                    {
                        continue;
                    }

                    Category item = new Category(categoryName.Groups["category"].Value);
                    foreach (Match boardMatch in BoardPattern.Matches(maybeCategoryText))
                    {
                        BoardInfo info = ThreadUtility.ParseBoardInfo(boardMatch.Groups["url"].Value, item.Name);
                        if (info != null)
                        {
                            info.Name = boardMatch.Groups["subject"].Value;
                            item.Children.Add(info);
                            IBoardInfo oldInfo = FindFromName(info.Name, info.DomainPath);
                            if (oldInfo != null)
                            {
                                Replace(oldInfo, info);
                            }
                        }
                    }
                    if (item.Children.Count > 0)
                    {
                        categories.Add(item);
                    }
                }

                if (categories.Count <= 0)
                {
                    throw new ApplicationException("板一覧の更新に失敗しました");
                }
                this.Clear();
                foreach (Category category in categories)
                {
                    Add(category);
                }
                e.Updated = true;
            }
            catch (System.Net.WebException ex)
            {
                if (ex.Status == WebExceptionStatus.ProtocolError)
                {
                    HttpWebResponse errorResponse = (HttpWebResponse)ex.Response;
                    if (ContinueStatuses.Contains(errorResponse.StatusCode))
                    {
                        e.Message = ex.Message;
                    }
                    else if (HttpStatusCode.NotModified != errorResponse.StatusCode)
                    {
                        throw;
                    }
                }
                else//プロトコルエラー以外の例外
                {
                    e.Message = ex.Message;
                }
            }

            OnOnlineUpdated(e);
        }