public async Task <ActionResult <CComment> > PostCComment(CComment cComment) { _context.CComment.Add(cComment); await _context.SaveChangesAsync(); return(CreatedAtAction("GetCComment", new { id = cComment.Id }, cComment)); }
public async Task <IActionResult> PutCComment(int id, CComment cComment) { if (id != cComment.Id) { return(BadRequest()); } _context.Entry(cComment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!CCommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public int DislikeProductDetial(int fCommentId) { CComment comment = CCommentFactory.fn留言查詢().FirstOrDefault(p => p.fCommentId == fCommentId); comment.fLikeCount -= 1; CCommentFactory.fn留言更新(comment); int result = comment.fLikeCount; return(result); }
public void CComment_ParseTest() { string text = "/* */"; ITextProvider tp = new StringTextProvider(text); TokenStream tokens = Helpers.MakeTokenStream(tp); CComment cc = new CComment(); Assert.IsTrue(cc.Parse(new ItemFactory(tp, null), tp, tokens)); Assert.AreEqual(2, cc.Children.Count); Assert.IsNull(cc.CommentText); Assert.AreEqual(CssTokenType.OpenCComment, ((TokenItem)cc.Children[0]).TokenType); Assert.AreEqual(CssTokenType.CloseCComment, ((TokenItem)cc.Children[1]).TokenType); text = "/* <!-- --> */"; tp = new StringTextProvider(text); tokens = Helpers.MakeTokenStream(tp); cc = new CComment(); Assert.IsTrue(cc.Parse(new ItemFactory(tp, null), tp, tokens)); Assert.AreEqual(3, cc.Children.Count); Assert.AreEqual(CssTokenType.OpenCComment, ((TokenItem)cc.Children[0]).TokenType); Assert.AreEqual(CssTokenType.CommentText, ((TokenItem)cc.Children[1]).TokenType); Assert.AreEqual(CssTokenType.CloseCComment, ((TokenItem)cc.Children[2]).TokenType); text = "/* "; tp = new StringTextProvider(text); tokens = Helpers.MakeTokenStream(tp); cc = new CComment(); Assert.IsTrue(cc.Parse(new ItemFactory(tp, null), tp, tokens)); Assert.AreEqual(1, cc.Children.Count); Assert.IsNull(cc.CommentText); Assert.AreEqual(CssTokenType.OpenCComment, ((TokenItem)cc.Children[0]).TokenType); Assert.IsTrue(cc.HasParseErrors); Assert.AreEqual(ParseErrorType.CloseCommentMissing, cc.ParseErrors[0].ErrorType); text = "/*"; tp = new StringTextProvider(text); tokens = Helpers.MakeTokenStream(tp); cc = new CComment(); Assert.IsTrue(cc.Parse(new ItemFactory(tp, null), tp, tokens)); Assert.AreEqual(1, cc.Children.Count); Assert.IsNull(cc.CommentText); Assert.IsTrue(cc.HasParseErrors); Assert.AreEqual(CssTokenType.OpenCComment, ((TokenItem)cc.Children[0]).TokenType); Assert.AreEqual(ParseErrorType.CloseCommentMissing, cc.ParseErrors[0].ErrorType); }
public IEnumerable <ISmartTagAction> GetSmartTagActions(ParseItem item, int position, ITrackingSpan itemTrackingSpan, ITextView view) { UrlItem url = (UrlItem)item; if (!url.IsValid || url.UrlString == null || !url.UrlString.Text.Contains(";base64,")) { yield break; } CComment comment = url.NextSibling as CComment; if (comment != null && comment.CommentText != null) { string path = comment.CommentText.Text.Trim(); yield return(new UpdateEmbedSmartTagAction(itemTrackingSpan, url, path)); } else { RuleBlock rule = item.FindType <RuleBlock>(); Declaration dec = item.FindType <Declaration>(); if (rule == null || dec == null || dec.PropertyName == null) { yield break; } foreach (Declaration sibling in rule.Declarations.Where(d => d.PropertyName != null && d != dec)) { if (sibling.PropertyName.Text == "*" + dec.PropertyName.Text || sibling.PropertyName.Text == "_" + dec.PropertyName.Text) { var visitor = new CssItemCollector <UrlItem>(); sibling.Accept(visitor); UrlItem siblingUrl = visitor.Items.FirstOrDefault(); if (siblingUrl != null && siblingUrl.UrlString != null) { yield return(new UpdateEmbedSmartTagAction(itemTrackingSpan, url, siblingUrl.UrlString.Text)); break; } } } } }
public void ToComment(string content, int pid) { //登入的會員資訊 CMember member = (CMember)Session[CMemberSession.Session_Login_User]; CComment c = new CComment(); c.fCommentDateTime = DateTime.UtcNow.AddHours(08); c.fContent = content; c.fIsBanned = false; c.fIsRetract = false; c.fLikeCount = 0; c.fMemberId = member.fMemberId; c.fProductId = pid; CCommentFactory.fn留言新增(c); var m = CMemberFactory.fn會員查詢().Where(z => z.fMemberId == member.fMemberId); GlobalHost.ConnectionManager.GetHubContext <ProductHub>().Clients.Group(ProductHub.getGroupIdString(pid)).newMessage(m.Single().fPhoto, m.Single().fTheNickName, DateTime.UtcNow.AddHours(08).ToString(), content); }
private void ExtractText(CComment obj, StringBuilder target) /* nothing */ }
public void VisitComment(CComment comment) { visitor.VisitComment(comment); }
private static void Write(CComment obj) { Console.Write("/* {0} */", obj.Text); }
public void IncrementalParse_UnclosedRule() { CssTree doc = new CssTree(null) { // Make an unclosed rule and look for the right parse error TextProvider = new StringTextProvider("p { color: red; /* Comment }") }; Assert.AreEqual(1, doc.StyleSheet.Children.Count); RuleSet rs = doc.StyleSheet.Children[0] as RuleSet; Assert.IsNotNull(rs); Assert.IsTrue(rs.IsUnclosed); Assert.IsFalse(rs.HasParseErrors); Assert.IsTrue(rs.Block.HasParseErrors); Assert.IsTrue(rs.Block.ParseErrors[0].ErrorType == ParseErrorType.CloseCurlyBraceMissing); Assert.IsTrue(rs.Block.ParseErrors[0].Location == ParseErrorLocation.AfterItem); Assert.IsInstanceOfType(doc.StyleSheet.ItemFromRange(16, 10), typeof(CComment)); Assert.IsInstanceOfType(doc.StyleSheet.ItemFromRange(16, 10).Parent, typeof(RuleBlock)); // Close the rule (make sure the error goes away) void changedHandler(object sender, CssItemsChangedEventArgs eventArgs) { // The change is crafted in such a way that the incremental parse is // confined to the rule block that has a missing curly brace, but now // the curly brace is detected and the parse error goes away. Assert.AreEqual(2, eventArgs.DeletedItems.Count); Assert.IsInstanceOfType(eventArgs.DeletedItems[0], typeof(Declaration)); Assert.IsInstanceOfType(eventArgs.DeletedItems[1], typeof(CComment)); Assert.AreEqual(3, eventArgs.InsertedItems.Count); Assert.IsInstanceOfType(eventArgs.InsertedItems[0], typeof(Declaration)); Assert.IsInstanceOfType(eventArgs.InsertedItems[1], typeof(CComment)); Assert.IsInstanceOfType(eventArgs.InsertedItems[2], typeof(TokenItem)); Assert.AreEqual(1, eventArgs.ErrorsChangedItems.Count); Assert.AreSame(rs.Block, eventArgs.ErrorsChangedItems[0]); } doc.ItemsChanged += changedHandler; doc.OnTextChange(new StringTextProvider("p { color: red; /* Comment */ }"), 27, 0, 3); doc.ItemsChanged -= changedHandler; Assert.AreEqual(1, doc.StyleSheet.Children.Count); Assert.IsFalse(rs.IsUnclosed); Assert.IsFalse(rs.HasParseErrors); Assert.IsFalse(rs.Block.HasParseErrors); Assert.IsInstanceOfType(doc.StyleSheet.ItemFromRange(16, 10), typeof(CComment)); Assert.IsInstanceOfType(doc.StyleSheet.ItemFromRange(16, 10).Parent, typeof(RuleBlock)); // Open the rule again doc.OnTextChange(new StringTextProvider("p { color: red; /* Comment"), 26, 5, 0); Assert.AreEqual(1, doc.StyleSheet.Children.Count); rs = doc.StyleSheet.Children[0] as RuleSet; Assert.IsNotNull(rs); Assert.IsTrue(rs.IsUnclosed); Assert.IsFalse(rs.HasParseErrors); Assert.IsTrue(rs.Block.HasParseErrors); Assert.IsTrue(rs.Block.ParseErrors[0].ErrorType == ParseErrorType.CloseCurlyBraceMissing); Assert.IsTrue(rs.Block.ParseErrors[0].Location == ParseErrorLocation.AfterItem); CComment comment = doc.StyleSheet.ItemFromRange(16, 10) as CComment; Assert.IsNotNull(comment); Assert.IsInstanceOfType(comment.Parent, typeof(RuleBlock)); Assert.IsTrue(comment.IsUnclosed); }
private async Task UpdateEmbeddedImageValues(ParseItem item) { if (!WESettings.Instance.Css.SyncBase64ImageValues) { return; } Declaration dec = item.FindType <Declaration>(); if (dec == null || !Cache.Contains(dec)) { return; } var url = dec.Values.FirstOrDefault() as UrlItem; if (url == null || !url.IsValid || url.UrlString == null || url.UrlString.Text.Contains(";base64,")) { return; } var matches = Cache.Where(d => d.IsValid && d != dec && d.Parent == dec.Parent && d.Values.Any() && (d.Values[0].NextSibling as CComment) != null); // Undo sometimes messes with the positions, so we have to make this check before proceeding. if (!matches.Any() || dec.Text.Length < dec.Colon.AfterEnd - dec.Start || dec.Colon.AfterEnd < dec.Start) { return; } string urlText = url.UrlString.Text.Trim('\'', '"'); string filePath = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(_buffer.GetFileName()), urlText)); string b64UrlText = await FileHelpers.ConvertToBase64(filePath); string b64Url = url.Text.Replace(urlText, b64UrlText); IEnumerable <Tuple <SnapshotSpan, string> > changes = matches.Reverse().SelectMany(match => { ParseItem value = match.Values[0]; CComment comment = value.NextSibling as CComment; SnapshotSpan span = new SnapshotSpan(_buffer.CurrentSnapshot, comment.CommentText.Start, comment.CommentText.Length); url = value as UrlItem; if (url == null) { return(null); } SnapshotSpan b64Span = new SnapshotSpan(_buffer.CurrentSnapshot, url.Start, url.Length); return(new[] { new Tuple <SnapshotSpan, string>(span, urlText), new Tuple <SnapshotSpan, string>(b64Span, b64Url) }); }); await Dispatcher.CurrentDispatcher.InvokeAsync(() => { using (ITextEdit edit = _buffer.CreateEdit()) { foreach (Tuple <SnapshotSpan, string> change in changes) { SnapshotSpan currentSpan = change.Item1.TranslateTo(_buffer.CurrentSnapshot, SpanTrackingMode.EdgeExclusive); edit.Replace(currentSpan, change.Item2); } edit.Apply(); } }); }