public void SendToSubscribers(int snippetId)
        {
            var snippet = _dbContext.CodeSnippets.Find(snippetId);

            if (snippet == null)
            {
                return;
            }

            _hubContext.Clients.Group(SnippetHub.GetGroup(snippet.Id))
            .highlight(snippet.Id, snippet.HighlightedCode, snippet.HighlightedIn?.TotalMilliseconds.ToString("N0"));
        }
Esempio n. 2
0
        public static void HighlightSnippet(int snippetId)
        {
            using (var context = new HighlighterDbContext())
            {
                var snippet = context.Snippets.Find(snippetId);
                snippet.HighlightedSource = HighlightSource(snippet.Source);
                snippet.HighlightedAt     = DateTime.UtcNow;

                context.SaveChanges();

                var hubContext = GlobalHost.ConnectionManager.GetHubContext <SnippetHub>();
                hubContext.Clients.Group(SnippetHub.GetGroup(snippet.Id))
                .highlight(snippet.Id, snippet.HighlightedSource);
            }
        }
        public void Highlight(int snippetId)
        {
            var snippet = _dbContext.CodeSnippets.Find(snippetId);

            if (snippet == null)
            {
                return;
            }

            snippet.HighlightedCode = HighlightSource(snippet.SourceCode);
            snippet.HighlightedAt   = DateTime.UtcNow;

            _dbContext.SaveChanges();

            _hubContext.Clients.Group(SnippetHub.GetGroup(snippet.Id))
            .highlight(snippet.HighlightedCode);
        }
        public async Task HighlightAsync(int snippetId)
        {
            var snippet = await _dbContext.CodeSnippets.FindAsync(snippetId);

            if (snippet == null)
            {
                return;
            }

            snippet.HighlightedCode = await HighlightSourceAsync(snippet.SourceCode);

            snippet.HighlightedAt = DateTime.UtcNow;

            await _dbContext.SaveChangesAsync();

            _hubContext.Clients.Group(SnippetHub.GetGroup(snippet.Id))
            .highlight(snippet.Id, snippet.HighlightedCode);
        }