public int DownvoteComment(string userId, int CommentId) { var _userAlreadyUpvoted = UserAlreadyUpvoted(userId, CommentId); if (_userAlreadyUpvoted == null) { var model = new CommentState() { CommentId = CommentId, UserId = userId, Vote = false }; Add(model); return(_CommentService.DecrementUpvote(CommentId)); } var upvote = _userAlreadyUpvoted.Vote; if (!upvote) { return(_userAlreadyUpvoted.Comment.Upvotes); } _userAlreadyUpvoted.Vote = false; _context.SaveChanges(); return(_CommentService.DecrementUpvote(CommentId)); }
private void ReplyResponse(IAsyncResult ar) { CommentState commentState = (CommentState)ar.AsyncState; HttpWebRequest request = commentState.AsyncRequest; commentState.AsyncResponse = (HttpWebResponse)request.EndGetResponse(ar); var data = Reddit.GetResponseString(commentState.AsyncResponse.GetResponseStream()); var json = JObject.Parse(data); returnComment = new Comment(Reddit, json["json"]["data"]["things"][0]); }
public Lexer(InputString inputString) { _inputString = inputString; _currentSymbol = _inputString.GetNextSymbol(); _idState = new IdState(); _symbolState = new SymbolState(); _charState = new CharState(); _stringState = new StringState(); _commentState = new CommentState(); _digitState = new DigitState(); _verbatinState = new VerbatinState(); }
public void Distinguish(DistinguishType distinguishType) { if (Reddit.User == null) { throw new Exception("No user logged in."); } var request = Reddit.CreatePost(DistinguishUrl); CommentState commentState = new CommentState(); commentState.AsyncRequest = request; commentState.ParameterValue = distinguishType; request.BeginGetRequestStream(new AsyncCallback(DistinguishRequest), commentState); }
public void EditText(string newText) { if (Reddit.User == null) { throw new Exception("No user logged in."); } var request = Reddit.CreatePost(EditUserTextUrl); CommentState commentState = new CommentState(); commentState.AsyncRequest = request; commentState.ParameterValue = newText; request.BeginGetRequestStream(new AsyncCallback(EditTextRequest), commentState); }
private void DistinguishResponse(IAsyncResult ar) { CommentState commentState = (CommentState)ar.AsyncState; HttpWebRequest request = commentState.AsyncRequest; commentState.AsyncResponse = (HttpWebResponse)request.EndGetResponse(ar); var data = Reddit.GetResponseString(commentState.AsyncResponse.GetResponseStream()); var json = JObject.Parse(data); if (json["jquery"].Count(i => i[0].Value <int>() == 11 && i[1].Value <int>() == 12) == 0) { throw new Exception("You are not permitted to distinguish this comment."); } }
private void ReplyRequest(IAsyncResult ar) { CommentState commentState = (CommentState)ar.AsyncState; HttpWebRequest request = commentState.AsyncRequest; Stream stream = request.EndGetRequestStream(ar); Reddit.WritePostBody(stream, new { text = (String)commentState.ParameterValue, thing_id = FullName, uh = Reddit.User.Modhash, api_type = "json" //r = Subreddit }); }
private void EditTextRequest(IAsyncResult ar) { CommentState commentState = (CommentState)ar.AsyncState; HttpWebRequest request = commentState.AsyncRequest; Stream stream = request.EndGetRequestStream(ar); Reddit.WritePostBody(stream, new { api_type = "json", text = (String)commentState.ParameterValue, thing_id = FullName, uh = Reddit.User.Modhash }); request.BeginGetResponse(new AsyncCallback(EditTextResponse), commentState); }
public IEnumerable<CommentTransport> GetNextComments([FromBody]CommentState cs) { var user = context.User.FirstOrDefault(u => u.login == HttpContext.Session.GetString("Username")); List<Comment> comments = new List<Comment>(); if (cs.lastCommentId == -1) { comments = context.Comment.Where(comment => comment.id_post==cs.postId) .OrderByDescending(comment => comment.id) .Take(20).ToList(); } else { comments = context.Comment.Where(comment => comment.id_post == cs.postId) .OrderByDescending(comment => comment.id) .Where(comment => cs.lastCommentId > comment.id) .Take(20).ToList(); } var users = (from u in context.User from p in comments where u.id == p.id_user select u).ToList(); List<CommentTransport> sendingComments = new List<CommentTransport>(); foreach (Comment comment in comments) { if(user != null && user.id==comment.id_user) sendingComments.Add(new CommentTransport(comment,true)); else sendingComments.Add(new CommentTransport(comment,false)); } foreach (CommentTransport comment in sendingComments) { foreach (User currUser in users) { if (comment.id_user == currUser.id) { comment.username = currUser.login; comment.avatar = currUser.avatar; } } } return sendingComments; }
private void EditTextResponse(IAsyncResult ar) { CommentState commentState = (CommentState)ar.AsyncState; HttpWebRequest request = commentState.AsyncRequest; commentState.AsyncResponse = (HttpWebResponse)request.EndGetResponse(ar); var data = Reddit.GetResponseString(commentState.AsyncResponse.GetResponseStream()); JToken json = JToken.Parse(data); if (json["json"].ToString().Contains("\"errors\": []")) { Body = (String)commentState.ParameterValue; } else { throw new Exception("Error editing text."); } }
public Comment Reply(string message) { if (Reddit.User == null) { // RedditSharp used an AuthenticationException // but it's not available for Windows Phone throw new Exception("No user logged in."); } CommentState commentState = new CommentState(); var request = Reddit.CreatePost(CommentUrl); commentState.AsyncRequest = request; commentState.ParameterValue = message; IAsyncResult replyRequestAR = request.BeginGetRequestStream(new AsyncCallback(ReplyRequest), commentState); IAsyncResult replyResponseAR = request.BeginGetResponse(new AsyncCallback(ReplyResponse), commentState); return(returnComment); }
public override XmlParserContext TryRecreateState(XObject xobject, int position) { return (TagState.TryRecreateState(xobject, position) ?? ClosingTagState.TryRecreateState(xobject, position) ?? CommentState.TryRecreateState(xobject, position) ?? CDataState.TryRecreateState(xobject, position) ?? DocTypeState.TryRecreateState(xobject, position) ?? ProcessingInstructionState.TryRecreateState(xobject, position) ?? TextState.TryRecreateState(xobject, position) ?? new XmlParserContext { CurrentState = this, Position = xobject.Span.Start, PreviousState = Parent, CurrentStateLength = 0, KeywordBuilder = new System.Text.StringBuilder(), Nodes = NodeStack.FromParents(xobject), StateTag = FREE }); }
public ActionResult CommentSpam(CommentState state) { var comment = api.Comments.GetSingle(where : c => c.Id == state.CommentId && c.PostId == state.PostId); if (comment != null) { comment.IsSpam = state.Status; api.SaveChanges(); } return(View("Partial/CommentList", api.Comments.Get(where : c => c.PostId == state.PostId) .Select(c => new Piranha.Manager.Models.Post.EditModel.CommentListItem() { Author = c.Author, Body = c.Body, Created = c.Created, Email = c.Email, Id = c.Id, IsApproved = c.IsApproved, IsSpam = c.IsSpam, WebSite = c.WebSite }).ToList())); }
private void DistinguishRequest(IAsyncResult ar) { CommentState commentState = (CommentState)ar.AsyncState; DistinguishType distinguishType = (DistinguishType)commentState.ParameterValue; HttpWebRequest request = commentState.AsyncRequest; Stream stream = request.EndGetRequestStream(ar); string how; switch (distinguishType) { case DistinguishType.Admin: how = "admin"; break; case DistinguishType.Moderator: how = "yes"; break; case DistinguishType.None: how = "no"; break; default: how = "special"; break; } Reddit.WritePostBody(stream, new { how, id = Id, uh = Reddit.User.Modhash }); request.BeginGetResponse(new AsyncCallback(DistinguishResponse), commentState); }
public async Task <IActionResult> Index(CancellationToken cancellationToken, CommentState commentState = CommentState.Active) { var comments = await _commentsManagementService.GetAllComments(CurrentCookiesToken, cancellationToken); var viewModels = new List <CommentViewModel>(); foreach (var comment in comments.Where(c => c.State == commentState)) { var petName = GetFromCache <string>(comment.PetUuid); if (petName == null) { petName = (await _petsManagementService.GetPet(comment.PetUuid, CurrentCookiesToken, cancellationToken))?.Name; TimeSpan?timeSpan = TimeSpan.FromMinutes(AppSettings.CacheExpirationTimeInMinutes); SetCache(comment.PetUuid, petName, CacheItemPriority.High, timeSpan); } viewModels.Add(new CommentViewModel() { Comment = comment, PetName = petName }); } return(View(viewModels.OrderByDescending(x => x.Comment.Created).ToList())); }
public static Color GetStateColor(CommentState state) { float sat = 0.8f; float v = 1f; switch (state) { default: case CommentState.Open: return(Color.HSVToRGB(0.3f, sat, v)); case CommentState.Blocked: return(Color.HSVToRGB(0.05f, sat, v)); case CommentState.Resolved: return(Color.HSVToRGB(0.5f, sat, v)); case CommentState.WontFix: return(Color.HSVToRGB(0.05f, sat, v)); case CommentState.Closed: return(Color.HSVToRGB(0.7f, 0f, v)); } }
public void Add(CommentState CommentState) { _context.CommentStates.Add(CommentState); _context.SaveChanges(); }
public void Remove(CommentState CommentState) { _context.CommentStates.Remove(CommentState); _context.SaveChanges(); }
public static KVFile Parse(string Raw, out string ErrorMessage) { List <KVPair> includePaths = new List <KVPair>(); KVFile rv = new KVFile(); KVPair rvBase = null; KVPair ParentKV = null; KVPair CurrentKV = null; int Line = 0; ParserState parserState = ParserState.BEFORE_KEY; CommentState commentState = CommentState.NOT_COMMENT; for (int x = 0; x < Raw.Length; x++) { if (commentState == CommentState.NOT_COMMENT) { switch (Raw[x]) { case SafetyKey: { commentState = CommentState.SAFETY_KEY; } break; case '/': { if (parserState != ParserState.KEY && parserState != ParserState.VALUE) { string symbolCheck = SafeSubstring(Raw, x, 2); switch (symbolCheck) { case "//": commentState = CommentState.LINE_COMMENT; break; /*case "/*": * commentState = CommentState.BLOCK_COMMENT; * break;*/ } } } break; case '#': { switch (parserState) { case ParserState.BEFORE_KEY: case ParserState.AFTER_VALUE: CurrentKV = new KVPair(); parserState = ParserState.AFTER_KEY; includePaths.Add(CurrentKV); break; } } break; case '"': { switch (parserState) { case ParserState.BEFORE_KEY: case ParserState.AFTER_VALUE: case ParserState.BEFORE_FIRST_ELEMENT: CurrentKV = new KVPair(); if (ParentKV != null) { CurrentKV.Parent = ParentKV; ParentKV.ChildKVs.Add(CurrentKV); } if (rvBase == null) { rvBase = CurrentKV; } parserState = ParserState.KEY; break; default: parserState++; break; } } break; case '{': { //parserState = ParserState.BEFORE_KEY; if (parserState != ParserState.AFTER_KEY) { ErrorMessage = "Attempting to create table when value of key is already assigned. Line " + Line; return(null); } parserState = ParserState.BEFORE_FIRST_ELEMENT; ParentKV = CurrentKV; } break; case '}': { parserState = ParserState.AFTER_VALUE; if (ParentKV == null) { ErrorMessage = "Item KV Curly Braces are not balanced"; return(null); } if (ParentKV.ChildKVs.Count > 0) { Tabs(ref CurrentKV.ValueComment, ref ParentKV.ValueComment); } else { Tabs(ref ParentKV.KeyComment, ref ParentKV.ValueComment); } CurrentKV = ParentKV; ParentKV = ParentKV.Parent; } break; } } if (Raw[x] != '"' || commentState != CommentState.NOT_COMMENT) { WriteToKV(rv, CurrentKV, parserState, Raw[x]); } if (SafeSubstring(Raw, x, Environment.NewLine.Length) == Environment.NewLine) { Line++; } if ((SafeSubstring(Raw, x, Environment.NewLine.Length) == Environment.NewLine && commentState == CommentState.LINE_COMMENT)) // || (SafeSubstring(Raw, x, 2) == "*/" && commentState == CommentState.BLOCK_COMMENT)) { commentState = CommentState.NOT_COMMENT; } } ErrorMessage = ""; rv.root = rvBase; rv.dependencies = includePaths; return(rv); }
public static void StateLabel(CommentState value) { GUIUtils.ColoredLabel(value.ToString(), GetStateColor(value)); }