public IHttpActionResult Get(int id) { var item = _db.Entries.Include(x => x.Votes).Include(x => x.Comments).SingleOrDefault(x => x.Id == id && x.Status != EntryStatus.Trash && x.Visibility != EntryVisibility.Hidden); if (item == null) { return(NotFound()); } var result = new EntryView { Id = item.Id, Author = _userContext.GetUser(UserHelper.GetUserNameFromComplexUsername(item.Author)).Name, Title = item.Title, Message = item.Message, Vote = EntryHelper.GetVotes(item.Votes), VoteResult = EntryHelper.UserVoteResult(User.Identity, item.Votes), Comments = item.Comments != null ? item.Comments.Count : 0, Status = item.Status.GetEnumDescription(), CreateDate = item.CreateDate.ToString("yyyy-MM-dd HH:mm"), UpdateDate = item.UpdateDate.HasValue ? item.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm") : "" }; return(Ok(result)); }
public void ExtendQuery(IEnumerable <DisplayableEntry> de) { foreach (var d in de) { d.LoadPreview(_db.FileDownloadStream(EntryHelper.PosePreviewID(d))); } }
public async Task UploadFiles() { IEnumerable <Entry> collection = _dBService.GetAll(); int count = collection.Count(); int ide = 1; foreach (var entry in collection) { if (_stopFlag) { MessageBox.Show("Aborting..."); Reset(); return; } if (entry.Tags.Contains("model")) { OnProgressChanged?.Invoke($"[{ide}/{count}]Skipping"); ide++; continue; } string pvid = EntryHelper.PosePreviewID(entry); Uri pvuri = EntryHelper.PosePreviewUri(entry); using (Stream stream = await GetFileStream(pvuri)) { _dBService.FileUpload(pvid, "pose_0001_thumb.jpg", stream); } OnProgressChanged?.Invoke($"[{ide}/{count}]-PrevImgSaved"); (string Id, string Name, Uri Uri)[] meta = EntryHelper.GetFileMeta(entry);
public DreamMessage GetFeedEntry(string title, string date) { var entryDoc = (from entry in LoadFeed()["entry"] let pathInfo = EntryHelper.GetPathInfo(entry) where pathInfo.Title == title && pathInfo.Date == date select entry).FirstOrDefault(); return(entryDoc == null?DreamMessage.NotFound("no such entry") : DreamMessage.Ok(entryDoc)); }
public DatabaseHelperProvider(VoteMystContext context, AvatarHelper avatarHelper) { Context = context; Authorization = new AuthorizationHelper(context); Users = new UserAccountHelper(context, avatarHelper); Entries = new EntryHelper(context); Events = new EventHelper(context); Votes = new VoteHelper(context); }
public async Task ExtendEntry(Entry entry) { entry.Counts = 36; string page = await GetString(new Uri(EntryHelper.CombinePath(_HostAddr, "archives", entry.ID.ToString()))); HtmlDocument hd = new HtmlDocument(); hd.LoadHtml(page); var tags = hd.DocumentNode.Descendants("a").Where(n => n.Attributes.Contains("rel")).Where(n => n.Attributes["rel"].Value == "category tag").Select(n => n.InnerText).ToList(); entry.Tags = tags; }
public void Initialize() { foreach (Type type in EntryHelper.GetCurrentTypes()) { int typeLength = type.ToString().Length; if (typeLength > this.maxTypeLength) { this.maxTypeLength = typeLength; } } Debug.WriteLine("length:" + maxTypeLength); }
public async Task <Result> Analyse() { string frontpage = await GetString(new Uri(_HostAddr)); HtmlDocument hd = new HtmlDocument(); hd.LoadHtml(frontpage); List <int> pagimation = hd.DocumentNode.Descendants().Where(n => n.GetClasses().Contains("page")).Select(n => int.Parse(n.InnerText)).ToList(); pagimation.Sort(); int pages = pagimation.Last(); int errCounter = 0; List <string> errmsg = new List <string>(); OnProgressChanged?.Invoke($"[{pages}]pages found"); List <Entry> Entrys = new List <Entry>(); for (int i = 1; i <= pages; i++) { string page = await GetString(new Uri(EntryHelper.CombinePath(_HostAddr, "page", i.ToString()))); Entrys.AddRange(ExtractEntry(page)); OnProgressChanged?.Invoke($"[{i}/{pages}]pages done"); } int idx = 1; foreach (var e in Entrys) { await ExtendEntry(e); Thread.Sleep(50); try { _dBService.Insert(e); }catch (Exception exc) { errCounter += 1; errmsg.Add(exc.Message); } OnProgressChanged?.Invoke($"[{idx}/{Entrys.Count}]pages done"); idx++; } OnProgressChanged?.Invoke("Ready"); Result ret = new Result { PageCount = pages, ErrorEntry = errCounter, ErrorMessages = errmsg, }; return(ret); }
public async Task <IHttpActionResult> PostVote(int id, VoteView voteView) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var entry = _db.Entries.Include(x => x.Votes).Include(x => x.User).SingleOrDefault(x => x.Id == id); if (entry == null) { return(NotFound()); } var userVoteResult = EntryHelper.UserVoteResult(User.Identity, entry.Votes); if (userVoteResult != null) { return(BadRequest()); } var userName = UserHelper.GetUserNameFromIdentity(User.Identity); var user = _userContext.GetUser(userName); var vote = new Vote { Author = UserHelper.GetUserNameFromIdentity(User.Identity), CreateDate = DateTime.Now, Entry = entry, IsPositive = voteView.IsPositive, UserId = user.Id }; _db.Votes.Add(vote); await _db.SaveChangesAsync(); _mailer.InformAboutVote(entry); var location = $"api/entry/{vote.Entry.Id}"; return(Created(location, new VoteView { Id = vote.Id, Author = _userContext.GetUser(UserHelper.GetUserNameFromComplexUsername(vote.Author)).Name, CreateDate = vote.CreateDate, IsPositive = voteView.IsPositive })); }
//--- Methods --- public ActionResult Index() { _log.Debug("Getting feed index"); var feed = FeedService.Get().ToDocument(); var posts = from entry in feed["entry"] let pathInfo = EntryHelper.GetPathInfo(entry) select new PostModel() { Title = entry["title"].AsText, Summary = entry["summary"].AsText, PathDate = pathInfo.Date, PathTitle = pathInfo.Title }; return(View(posts.ToArray())); }
public IHttpActionResult Get() { List <Entry> entries = _db.Entries.Include(x => x.Votes).Include(x => x.Comments).ToList(); if (!entries.Any(x => x.Status != EntryStatus.Trash && x.Visibility != EntryVisibility.Hidden)) { return(Ok(new List <int>())); } var user = _userContext.GetUser(UserHelper.GetUserNameFromIdentity(User.Identity)); if (!user.IsModerator) { entries = entries.Where( x => x.Status != EntryStatus.AwaitingApproval || (x.Status == EntryStatus.AwaitingApproval && UserHelper.GetUserNameFromComplexUsername(x.Author) == UserHelper.GetUserNameFromIdentity(User.Identity))).ToList(); } List <EntryView> result = entries .Where(x => x.Status != EntryStatus.Trash && x.Visibility != EntryVisibility.Hidden) .Select(x => { var author = _userContext.GetUser(UserHelper.GetUserNameFromComplexUsername(x.Author)); return(new EntryView { Id = x.Id, Author = author.Name, Title = x.Title, Message = x.Message, Vote = EntryHelper.GetVotes(x.Votes), VoteResult = EntryHelper.UserVoteResult(User.Identity, x.Votes), Comments = x.Comments != null ? x.Comments.Count : 0, Status = x.Status.GetEnumDescription(), CreateDate = x.CreateDate.ToString("yyyy-MM-dd HH:mm"), UpdateDate = x.UpdateDate.HasValue ? x.UpdateDate.Value.ToString("yyyy-MM-dd HH:mm") : "" }); }).ToList(); return(Ok(result)); }
public IEnumerable <Entry> ExtractEntry(string page) { HtmlDocument hd = new HtmlDocument(); hd.LoadHtml(page); var lists = hd.DocumentNode.Descendants().Where(n => n.GetClasses().Contains("list")).ToList(); List <Entry> entrys = new List <Entry>(); foreach (var l in lists) { foreach (var a in l.Descendants("a")) { var entry = new Entry() { ID = int.Parse(a.Attributes["href"].Value.Trim('/').Split('/').Last()), PreviewImgUri = EntryHelper.CombinePath(_HostAddr, a.FirstChild.Attributes["src"].Value), }; entrys.Add(entry); } } return(entrys); }
public void BeforeTests() { _eh = new EntryHelper(new EntryBaseHelper(new FileUrlExtractor())); }