private static void UpdateBBSResponse() { // チャンネル一覧 List<Channel> channelList = ChannelDao.Select(); // レス読み込み List<BBSThread> threadList = BBSThreadDao.Select(); // スレッドURLの重複をはずす threadList = threadList.GroupBy(e => e.ThreadUrl).Select(e => e.First()).ToList(); // 登録済みレス一覧 List<BBSResponse> savedResList = BBSResponseDao.Select(); foreach (BBSThread thread in threadList) { // スレッドストップしていたらスルー if (thread.IsThreadStop) { continue; } BbsReader reader = new BbsReader(); bool isThreadStop; List<ResInfo> resList = reader.ReadRes(thread.ThreadUrl, out isThreadStop); resList = resList.Where(res => int.Parse(res.ResNo) > thread.MaxResNo) .Where(res => !savedResList.Any(e => e.ThreadUrl == thread.ThreadUrl && e.ResNo.ToString() == res.ResNo)) .ToList(); // レスの追加 BBSResponseDao.Insert(thread.ThreadUrl, resList); // 最大レス番号 string maxResNo = (resList.Count() == 0) ? "0" : resList.Last().ResNo; // 掲示板の更新(スレッドストップを更新) BBSThreadDao.Update(thread.ChannelId, thread.ThreadUrl, maxResNo, isThreadStop); // Link抽出 foreach (ResInfo res in resList) { Match match = Regex.Match(res.Message, @"ttp://.*\.(jpg|JPG|jpeg|JPEG|bmp|BMP|png|PNG)"); if (match.Success) { string channelName = channelList.Where(e => e.ChannelId == thread.ChannelId).Single().ChannelName; string imageUrl = "h" + match.Value; ImageLinkDao.Insert(thread.ThreadUrl, channelName, imageUrl, res); } } } }
/// <summary> /// スレッド情報の更新 /// </summary> /// <param name="channelDetails">チャンネル詳細</param> private static void UpdateBBSThread(List<ChannelDetail> channelDetails) { List<Channel> channelList = ChannelDao.Select(); var channelDetailsJoin = channelDetails.Join(channelList, detail => detail.ChannelName, channel => channel.ChannelName, (detail, channel) => new { Detail = detail, Channel = channel }); List<BBSThread> threadList = BBSThreadDao.Select(); foreach (var detail in channelDetailsJoin) { // コンタクトURLからスレッドURLを取得 BbsReader reader = new BbsReader(); string threadUrl = reader.GetThreadUrl(detail.Detail.ContactUrl); // スレッド情報が登録されていなければ登録する bool isExist = threadList.Any(thread => (thread.ChannelId == detail.Channel.ChannelId) && (thread.ThreadUrl == threadUrl)); if (!isExist) { BBSThreadDao.Insert(detail.Channel.ChannelId, threadUrl, false); } } }