private Board CreateBoard(Uri uri) { Debug.Assert(uri.Host.Equals("jbbs.shitaraba.net", StringComparison.InvariantCultureIgnoreCase)); Match match; match = Regex.Match(uri.AbsolutePath, @"^/([A-Za-z]+)/(\d+)/?$"); if (!match.Success) match = Regex.Match(uri.AbsolutePath, @"^/bbs/read\.cgi/([A-Za-z]+)/(\d+)($|/)"); Debug.Assert(match.Success); Board b = new Board(); b._server = this; var data = new BoardData(); data.Category = match.Groups[1].Value; data.BoardNumber = match.Groups[2].Value; b._data = data; return b; }
public override string GetLocalRules(Board b) { return "unimplemented"; }
public override List<Thread> GetThreads(Board b) { var threadList = new List<Thread>(); var http = new HttpClient(); BoardData boardData = b._data as BoardData; string subjectTxtUri = String.Format("http://jbbs.shitaraba.net/{0}/{1}/subject.txt", boardData.Category, boardData.BoardNumber); var responseMessage = http.GetAsync(subjectTxtUri).Result; if (!responseMessage.IsSuccessStatusCode) { throw new ApplicationException("スレッド一覧が取得できません。"); } var bytes = responseMessage.Content.ReadAsByteArrayAsync().Result; var eucJp = Encoding.GetEncoding("EUC-JP"); string body = eucJp.GetString(bytes); List<string> threadNumbers = new List<string>(); var lines = body.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (var line in lines) { // "1370999611.cgi,19(2)" var match = Regex.Match(line, @"^(\d+)\.cgi,([^(]+)\((\d+)\)$"); Debug.Assert(match.Success); var threadNumber = match.Groups[1].Value; var threadTitle = match.Groups[2].Value; var numberOfReses = match.Groups[3].Value; if (!threadNumbers.Contains(threadNumber)) { var threadUri = String.Format("http://jbbs.shitaraba.net/bbs/read.cgi/{0}/{1}/{2}", boardData.Category, boardData.BoardNumber, threadNumber); ThreadData threadData = new ThreadData(); threadData.Uri = new Uri(threadUri); var newThread = new Thread(threadNumber.ToInt(), threadTitle, this, threadData); threadList.Add(newThread); threadNumbers.Add(threadNumber); } } return threadList; }
public override string GetBoardTitle(Board b) { var data = b._data as BoardData; if (data.Settings == null) data.Settings = GetSettings(data.Category, data.BoardNumber.ToInt()); return data.Settings["BBS_TITLE"]; }
public override Uri GetBoardUri(Board b) { BoardData data = b._data as BoardData; return data.uri; }
public abstract List<Thread> GetThreads(Board b);
public override void CreateNewThread(Board b, string title, Message msg) { return; }
public abstract string GetLocalRules(Board b);
public abstract Uri GetBoardUri(Board b);
public abstract string GetBoardTitle(Board b);
public abstract void CreateNewThread(Board b, string title, Message msg);
static void Open(string[] args) { if (args.Length != 1) { Usage("open [url]"); return; } string url = args[0]; Uri uri; try { uri = new Uri(url); } catch (UriFormatException) { Console.WriteLine("URL がおかしいです。"); return; } if (Service.IsThread(uri)) { m_Thread = Service.GetThread(uri); Console.WriteLine("スレッド{0}を開きました。", m_Thread.Title); } else { m_Thread = null; } if (Service.IsBoard(uri)) { m_Board = Service.GetBoard(uri); Console.WriteLine("板「{0}」を開きました。", m_Board.Title); } }