public async Task InvokeAsync(WebSocketMessageContext context)
        {
            if (context.MessageType == WebSocketMessageType.Text &&
                context.Command == WebSocketCommands.DataSend)
            {
                if (context.Header != null)
                {
                    if (context.Header.TryGetValue("layoutrequest", out object layoutrequest))
                    {
                        if (!string.IsNullOrEmpty(HostingHelper.MainAppDirectory))
                        {
                            var layoutPagePath = PathUtility.GetLayoutPagePath(HostingHelper.MainAppDirectory);
                            var pageContent    = File.ReadAllText(layoutPagePath);
                            await _connectionManager.BroadcastAsyncFileChanged(pageContent, layoutPagePath);

                            return;
                        }

                        using (var scope = _applicationServices.GetRequiredService <IServiceScopeFactory>().CreateScope())
                            using (var db = scope.ServiceProvider.GetService <HisarCliContext>())
                            {
                                var page = db.Set <Page>().FirstOrDefault(x => x.PageType == PageType.Layout);
                                await _connectionManager.BroadcastAsyncFileChanged(page.Content, page.Name);
                            }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public async Task <IActionResult> SavePage([FromBody] PageViewModel model)
        {
            var page = new Page()
            {
                Content     = model.Content,
                ComponentId = model.ComponentId,
                Id          = model.Id,
                Name        = model.Name,
                UpdatedDate = DateTime.Now
            };

            if (page.Id > 0)
            {
                _context.Pages.Update(page);
            }
            else
            {
                _context.Pages.Add(page);
            }

            _context.SaveChanges();

            await _connectionManager.BroadcastAsyncFileChanged(model.Content, model.Name);

            return(Json(new WebResult <PageViewModel>(model)));
        }