Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

if running on WebAssembly reload the client application if the server application is restarted #1212

Merged
merged 1 commit into from
Mar 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Oqtane.Client/UI/SiteRouter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
var urlparameters = string.Empty;
var editmode = false;
var reload = Reload.None;
var lastsyncdate = DateTime.UtcNow;
var lastsyncdate = DateTime.UtcNow.AddHours(-1);
var runtime = GetRuntime();

Uri uri = new Uri(_absoluteUri);
Expand All @@ -107,9 +107,14 @@
SiteState.Alias = alias; // set state for services
lastsyncdate = alias.SyncDate;

// process any sync events for site
// process any sync events
if (reload != Reload.Site && alias.SyncEvents.Any())
{
// if running on WebAssembly reload the client application if the server application was restarted
if (runtime == Shared.Runtime.WebAssembly && PageState != null && alias.SyncEvents.Exists(item => item.TenantId == -1))
{
NavigationManager.NavigateTo(uri.Scheme + "://" + uri.Authority + "?reload", true);
}
if (alias.SyncEvents.Exists(item => item.EntityName == EntityNames.Site && item.EntityId == alias.SiteId))
{
reload = Reload.Site;
Expand Down
4 changes: 2 additions & 2 deletions Oqtane.Server/Infrastructure/SyncManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Oqtane.Models;
using Oqtane.Models;
using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -17,7 +17,7 @@ public SyncManager()

public List<SyncEvent> GetSyncEvents(int tenantId, DateTime lastSyncDate)
{
return SyncEvents.Where(item => item.TenantId == tenantId && item.ModifiedOn >= lastSyncDate).ToList();
return SyncEvents.Where(item => (item.TenantId == tenantId || item.TenantId == -1) && item.ModifiedOn >= lastSyncDate).ToList();
}

public void AddSyncEvent(int tenantId, string entityName, int entityId)
Expand Down
5 changes: 4 additions & 1 deletion Oqtane.Server/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void ConfigureServices(IServiceCollection services)
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISyncManager sync)
{
ServiceActivator.Configure(app.ApplicationServices);

Expand Down Expand Up @@ -264,6 +264,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
endpoints.MapControllers();
endpoints.MapFallbackToPage("/_Host");
});

// create a sync event to identify server application startup
sync.AddSyncEvent(-1, "Application", -1);
}
}
}