public static PageVersion AddPage(IScribeDatabase database, string title, string content, User user, ApprovalStatus status, bool published = false, params string[] tags) { var service = new ScribeService(database, null, GetSearchService(), user); var view = service.SavePage(new PageView { ApprovalStatus = status, Title = title, Text = content, Tags = tags }); switch (status) { case ApprovalStatus.Approved: service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Approve }); break; case ApprovalStatus.Rejected: service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Reject }); break; } if (published) { service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Publish }); } return(database.PageVersions.First(x => x.Id == view.Id)); }
public static PageVersion UpdatePage(IScribeDatabase database, User user, PageView view, Action <PageView> action, ApprovalStatus status = ApprovalStatus.None, bool published = false) { var service = new ScribeService(database, null, GetSearchService(), user); action(view); service.SavePage(view); database.SaveChanges(); switch (status) { case ApprovalStatus.Approved: service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Approve }); break; case ApprovalStatus.Rejected: service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Reject }); break; } if (published) { service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Publish }); } database.SaveChanges(); return(database.PageVersions.OrderByDescending(x => x.PageId == view.Id).First()); }
public ActionResult Upload(HttpPostedFileBase file) { if (file == null) { throw new ArgumentNullException(nameof(file)); } var data = new byte[file.ContentLength]; file.InputStream.Read(data, 0, file.ContentLength); var contentType = file.ContentType; if (contentType == "application/octet-stream") { contentType = MimeMapping.GetMimeMapping(file.FileName); } var service = new ScribeService(Database, null, null, GetCurrentUser()); var fileData = new FileView { Name = Path.GetFileName(file.FileName), Type = contentType, Data = data }; service.SaveFile(fileData); Database.SaveChanges(); return(new JsonNetResult(service.GetFiles(new PagedRequest { PerPage = int.MaxValue }))); }
public ActionResult File(int id) { var service = new ScribeService(Database, null, null, GetCurrentUser(null, false)); if (!string.IsNullOrEmpty(Request.Headers["If-Modified-Since"])) { var fileInfo = service.GetFile(id); var previousModifiedOn = DateTime.ParseExact(Request.Headers["If-Modified-Since"], "r", CultureInfo.InvariantCulture).ToLocalTime(); var currentModifiedOn = fileInfo.ModifiedOn.TruncateTo(Scribe.Extensions.DateTruncate.Second); if (currentModifiedOn <= previousModifiedOn) { Response.StatusCode = 304; Response.StatusDescription = "Not Modified"; return(Content(string.Empty)); } } var file = service.GetFile(id, true); if (file != null) { Response.Cache.SetCacheability(HttpCacheability.Public); Response.Cache.SetLastModified(file.ModifiedOn); Response.AddHeader("Content-Disposition", "inline; filename=" + file.Name); return(File(file.Data, file.Type)); } Response.AddHeader("Content-Disposition", "inline; filename=404.png"); var data = Assembly.GetExecutingAssembly().ReadEmbeddedBinaryFile("Scribe.Website.Content.404.png"); return(File(data, "image/png")); }
public ActionResult UserView(int id) { var accountService = new AccountService(Database, AuthenticationService); var service = new ScribeService(Database, accountService, null, GetCurrentUser()); return(View(service.GetUser(id))); }
public ActionResult Files() { var service = new ScribeService(Database, null, null, GetCurrentUser()); return(View(service.GetFiles(new PagedRequest { PerPage = int.MaxValue }))); }
public static File AddFile(IScribeDatabase database, User user, string name, string type, byte[] data) { var service = new ScribeService(database, null, null, user); var id = service.SaveFile(new FileView { Name = name, Data = data, Type = type }); return(database.Files.First(x => x.Id == id)); }
/// <summary> Initializes the <see cref="T:System.Web.Http.ApiController" /> instance with the specified controllerContext. </summary> /// <param name="controllerContext"> /// The <see cref="T:System.Web.Http.Controllers.HttpControllerContext" /> object that is /// used for the initialization. /// </param> protected override void Initialize(HttpControllerContext controllerContext) { var path = HostingEnvironment.MapPath("~/App_Data/Indexes"); var searchService = new SearchService(Database, path, GetCurrentUser(controllerContext, false)); var accountService = new AccountService(Database, AuthenticationService); _service = new ScribeService(Database, accountService, searchService, GetCurrentUser(controllerContext, false)); base.Initialize(controllerContext); }
public ActionResult Users() { var accountService = new AccountService(Database, AuthenticationService); var service = new ScribeService(Database, accountService, null, GetCurrentUser()); return(View(service.GetUsers(new PagedRequest { PerPage = int.MaxValue }))); }
public ActionResult UsersWithTag(string tag) { var accountService = new AccountService(Database, AuthenticationService); var service = new ScribeService(Database, accountService, null, GetCurrentUser()); ViewBag.Tag = tag; return(View(service.GetUsers(new PagedRequest { Filter = $"Tags.Contains(\"{tag}\")", Page = 1, PerPage = int.MaxValue }))); }
public ScribeSpanDispatcher(string hostname, int port) { _hostname = hostname; _port = port; _tcpClient = new TcpClient { NoDelay = true }; _tcpClient.ConnectAsync(hostname, port).RunSynchronously(); _frame = new TFramedTransport(new TTcpClientTransport(_tcpClient)); _scribeService = new ScribeService(new ThriftProtocol(_frame)); }
public ActionResult Settings() { var user = GetCurrentUser(); var settings = SiteSettings.Load(Database, true); var privateService = new ScribeService(Database, null, null, user); var publicService = new ScribeService(Database, null, null, null); ViewBag.PrivatePages = privateService.GetPages(new PagedRequest { PerPage = int.MaxValue }).Results.Select(x => new PageReferenceView { Id = x.Id, Title = x.Id + " - " + x.Title }); ViewBag.PublicPages = publicService.GetPages(new PagedRequest { PerPage = int.MaxValue }).Results.Select(x => new PageReferenceView { Id = x.Id, Title = x.Id + " - " + x.Title }); return(View(settings.ToView())); }
public static PageVersion AddPage(IScribeDatabase database, string title, string content, User user, ApprovalStatus status = ApprovalStatus.None, bool published = false, bool homepage = false, params string[] tags) { var service = new ScribeService(database, null, GetSearchService(), user); var view = service.SavePage(new PageView { ApprovalStatus = status, Title = title, Text = content, Tags = tags }); switch (status) { case ApprovalStatus.Approved: service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Approve }); break; case ApprovalStatus.Rejected: service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Reject }); break; } if (published) { service.UpdatePage(new PageUpdate { Id = view.Id, Type = PageUpdateType.Publish }); } if (homepage) { var settings = SiteSettings.Load(database); settings.FrontPagePrivateId = view.Id; settings.FrontPagePublicId = view.Id; settings.Save(); database.SaveChanges(); } return(database.PageVersions.OrderByDescending(x => x.PageId == view.Id).First()); }