Example #1
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);
        }
Example #2
0
 public void LoadBoardFromXml()
 {
     XmlDocument bbsMenu = new XmlDocument();
     using (Stream xmlStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("DeanCCCore.bbs.xml"))
     {
         bbsMenu.Load(xmlStream);
     }
     foreach (XmlElement categoryElement in bbsMenu.GetElementsByTagName("category"))
     {
         Category item = new Category(categoryElement.GetAttribute("title"));
         foreach (XmlElement boardElement in categoryElement.ChildNodes)
         {
             BoardInfo info = ThreadUtility.ParseBoardInfo(boardElement.GetAttribute("url"), item.Name);
             if (info != null)
             {
                 info.Name = boardElement.GetAttribute("title");
                 item.Children.Add(info);
                 IBoardInfo oldInfo = FindFromName(info.Name, info.DomainPath);
                 if (oldInfo != null)
                 {
                     Replace(oldInfo, info);
                 }
             }
         }
         Add(item);
     }
     lastModified = DateTime.Parse(bbsMenu.GetElementsByTagName("bbsmenu")[0].Attributes["lastup"].Value);
     updateCompleted = true;
 }