public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session) { if (request.UriPath == Url) { ThreadStore.GetStorageEngine().UpdateThreadStoreStats(); ThreadStoreStats stats = ThreadStore.GetStorageEngine().StoreStats; JsonArray ja = new JsonArray(); IEnumerable <string> boards = Program.ValidBoards.Keys; for (int i = 0, j = boards.Count(); i < j; i++) { string boardName = boards.ElementAt(i); int threadCount = stats[boardName]; if (threadCount > 0) { JsonArray inner = new JsonArray(); inner.Add(boardName); inner.Add(threadCount); ja.Add(inner); } } WriteJsonResponse(response, ja.ToString()); return(true); } return(false); }
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session) { if (request.UriPath.StartsWith(Url)) { string board = request.QueryString[UrlParameters.Board].Value; string threadIdStr = request.QueryString[UrlParameters.ThreadId].Value; int threadId = -1; int.TryParse(threadIdStr, out threadId); if (!Program.IsBoardLetterValid(board)) { ThreadServerModule.write_text("Invalid board letter", response); return(true); } if (threadId <= 0) { ThreadServerModule.write_text("Invalid thread id", response); return(true); } string notes = request.QueryString[UrlParameters.ThreadNotesText].Value; notes = System.Web.HttpUtility.HtmlDecode(notes); ThreadStore.GetStorageEngine().setThreadNotes(board, threadId, notes); response.Redirect(ThreadServerModule.GetThreadPageLink(board, threadId)); return(true); } return(false); }
private string get_running_time_info() { StringBuilder s = new StringBuilder(); s.Append("<tr>"); s.AppendFormat("<td>{0}</td>", HMSFormatter.GetReadableTimespan(DateTime.Now - Program.StartUpTime)); if (Settings.EnableFileStats) { s.AppendFormat("<td>{0}</td>", Program.format_size_string(FileSystemStats.TotalUsage)); } else { s.Append("<td><i class=\"fa fa-times-circle-o\"></i></td>"); } s.AppendFormat("<td>{0}</td>", Program.format_size_string(NetworkUsageCounter.TotalConsumedAllTime)); s.AppendFormat("<td>{0}</td>", ThreadStore.GetStorageEngine().StoreStats.TotalArchivedThreadsCount); s.Append("</tr>"); return(s.ToString()); }
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session) { if (request.UriPath == Url) { ThreadStore.GetStorageEngine().UpdateThreadStoreStats(); StringBuilder sb = new StringBuilder(HtmlTemplates.OverviewPageTemplate); IncludeCommonHtml(sb); if (Settings.ThumbnailOnly) { string url = ThumbnailOnlySettingsController.GetLinkToThisPage(true, Url); sb.Replace("{thumbmode}", string.Format(ThumbnailOnlyWarningMessageHtml, url)); } else { sb.Replace("{thumbmode}", ""); } if (FileSystemStats.IsSaveDirDriveLowOnDiskSpace) { sb.Replace("{lowdiskspacenotice}", LowDiskSpaceWarningMessageHtml); } else { sb.Replace("{lowdiskspacenotice}", ""); } sb.Replace("{RunningTime}", get_running_time_info()); if (Settings.EnableFileStats) { sb.Replace("{DiskUsage}", string.Format(DiskUsageTableHtml, get_DiskUsageInfo())); } else { sb.Replace("{DiskUsage}", ""); } sb.Replace("{NetworkStats}", get_NetWorkStats()); sb.Replace("{ArchivedThreads}", get_ArchivedThreadsStats()); sb.Replace("{get-network-stats-today-api-link}", GetDailyNetworkStatisticsJsonApiHandler.GetLinkToThisPage(DateTime.Now)); sb.Replace("{get-network-stats-month-api-link}", GetMonthlyNetworkStatisticsJsonApiHandler.GetLinkToThisPage(DateTime.Now)); sb.Replace("{get-threads-stats-api-link}", GetThreadsStatisticsJsonApiHandler.GetLinkToThisPage()); WriteFinalHtmlResponse(response, sb.ToString()); return(true); } return(false); }
public void SetUp() { BaseSetUp(); mockRemoteThread = Substitute.For <RemoteThread>(); var grpcThreadFactory = new GrpcThreadFactory(); threadProxy = grpcThreadFactory.Create(Connection, new GrpcSbThread { Id = ThreadStore.AddObject(mockRemoteThread) }); }
private string get_ArchivedThreadsStats() { StringBuilder sb = new StringBuilder(); ThreadStoreStats stats = ThreadStore.GetStorageEngine().StoreStats; foreach (string board in Program.ValidBoards.Keys) { int threadCount = stats[board]; if (threadCount > 0) { sb.Append("<tr>"); sb.AppendFormat("<td>/{0}/</td>", board); sb.AppendFormat("<td>{0}</td>", threadCount); sb.Append("</tr>"); } } return(sb.ToString()); }
public override bool Process(HttpServer.IHttpRequest request, HttpServer.IHttpResponse response, HttpServer.Sessions.IHttpSession session) { if (request.UriPath.StartsWith(Url)) { string board = request.QueryString[UrlParameters.Board].Value; string threadIdStr = request.QueryString[UrlParameters.ThreadId].Value; int threadId = -1; int.TryParse(threadIdStr, out threadId); if (!Program.IsBoardLetterValid(board)) { ThreadServerModule.write_text("Invalid board letter", response); return(true); } if (threadId <= 0) { ThreadServerModule.write_text("Invalid thread id", response); return(true); } PostFormatter[] thread_data = ThreadStore.GetStorageEngine().GetThread(board, threadIdStr); MemoryStream memIO = new MemoryStream(); ZipOutputStream zipStream = new ZipOutputStream(memIO); zipStream.SetLevel(0); // no compression is needed since most of the files are media files, and they are already compressed anyway write_file_to_zip(zipStream, "res/blue.css", Encoding.UTF8.GetBytes(Properties.Resources.css_blue)); write_file_to_zip(zipStream, "res/sticky.png", Properties.Resources.sticky); write_file_to_zip(zipStream, "res/locked.png", Properties.Resources.locked); foreach (PostFormatter pf in thread_data) { if (pf.MyFile != null) { string full_path; if (FileOperations.ResolveFullFilePath(pf.MyFile.Hash, pf.MyFile.Extension, out full_path)) { string ext = Path.GetExtension(full_path); if (!string.IsNullOrEmpty(ext)) { ext = ext.Substring(1); } if (ext != pf.MyFile.Extension) { pf.MyFile.ChangeExtension(ext); } string zip_file_name = string.Format("file/{0}.{1}", pf.MyFile.Hash, ext); byte[] data = File.ReadAllBytes(full_path); pf.MyFile.Size = data.Length; write_file_to_zip(zipStream, zip_file_name, data); } string thumb_path; if (FileOperations.CheckThumbFileExist(pf.MyFile.Hash, out thumb_path)) { string zip_file_name = string.Format("thumb/{0}.jpg", pf.MyFile.Hash); write_file_to_zip(zipStream, zip_file_name, File.ReadAllBytes(thumb_path)); } } } string notes = ThreadStore.GetStorageEngine().GetThreadNotes(board, threadId); string pageHtml = build_page_html(board, threadIdStr, thread_data, notes); write_file_to_zip(zipStream, "index.html", Encoding.UTF8.GetBytes(pageHtml)); zipStream.Close(); memIO.Close(); byte[] result = memIO.ToArray(); response.Status = System.Net.HttpStatusCode.OK; response.ContentType = ServerConstants.ZipContentType; response.ContentLength = result.Length; response.AddHeader("content-disposition", string.Format("attachment; filename=\"{0}.zip\"", threadId)); response.SendHeaders(); response.SendBody(result); return(true); } return(false); }