DevOptions.razor (3240B)
1 @page "/DevOptions" 2 @using MatrixRoomUtils.Core.Extensions 3 @inject NavigationManager NavigationManager 4 @inject ILocalStorageService LocalStorage 5 6 <PageTitle>Developer options</PageTitle> 7 8 <h3>Rory&::MatrixUtils - Developer options</h3> 9 <hr/> 10 11 <InputCheckbox @bind-Value="@LocalStorageWrapper.Settings.DeveloperSettings.EnableLogViewers" @oninput="@LogStuff"></InputCheckbox><label> Enable log views</label><br/> 12 <InputCheckbox @bind-Value="@LocalStorageWrapper.Settings.DeveloperSettings.EnableConsoleLogging" @oninput="@LogStuff"></InputCheckbox><label> Enable console logging</label><br/> 13 <InputCheckbox @bind-Value="@LocalStorageWrapper.Settings.DeveloperSettings.EnablePortableDevtools" @oninput="@LogStuff"></InputCheckbox><label> Enable portable devtools</label><br/> 14 <button @onclick="@DropCaches">Drop caches</button> 15 <button @onclick="@RandomiseCacheTimers">Randomise cache timers</button> 16 <br/> 17 18 <details open> 19 <summary>View caches</summary> 20 <p>Generic cache:</p> 21 <ul> 22 @foreach (var item in RuntimeCache.GenericResponseCache) 23 { 24 <li> 25 @item.Key: @item.Value.Cache.Count entries<br/> 26 @if (item.Value.Cache.Count > 0) 27 { 28 <p>Earliest expiry: @(item.Value.Cache.Min(x => x.Value.ExpiryTime)) (@string.Format("{0:g}", item.Value.Cache.Min(x => x.Value.ExpiryTime).Value.Subtract(DateTime.Now)) from now)</p> 29 @* <p>Average expiry: @(item.Value.Cache.Average(x => x.Value.ExpiryTime.Value))(@item.Value.Cache.Average(x => x.Value.ExpiryTime).Value.Subtract(DateTime.Now) from now)</p> *@ 30 <p>Last expiry: @(item.Value.Cache.Max(x => x.Value.ExpiryTime)) (@string.Format("{0:g}", item.Value.Cache.Max(x => x.Value.ExpiryTime).Value.Subtract(DateTime.Now)) from now)</p> 31 } 32 </li> 33 } 34 </ul> 35 </details> 36 37 @code { 38 protected override async Task OnInitializedAsync() 39 { 40 await LocalStorageWrapper.LoadFromLocalStorage(LocalStorage); 41 await base.OnInitializedAsync(); 42 Task.Run(async () => 43 { 44 while (true) 45 { 46 await Task.Delay(1000); 47 StateHasChanged(); 48 } 49 }); 50 } 51 52 protected async Task LogStuff() 53 { 54 await Task.Delay(100); 55 Console.WriteLine($"Settings: {LocalStorageWrapper.Settings.ToJson()}"); 56 57 await LocalStorageWrapper.SaveToLocalStorage(LocalStorage); 58 } 59 60 protected async Task DropCaches() 61 { 62 RuntimeCache.GenericResponseCache.Clear(); 63 RuntimeCache.HomeserverResolutionCache.Clear(); 64 await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage); 65 } 66 67 protected async Task RandomiseCacheTimers() 68 { 69 foreach (var keyValuePair in RuntimeCache.GenericResponseCache) 70 { 71 Console.WriteLine($"Randomising cache timer for {keyValuePair.Key}"); 72 foreach (var cacheItem in keyValuePair.Value.Cache) 73 { 74 cacheItem.Value.ExpiryTime = DateTime.Now.AddSeconds(Random.Shared.Next(15, 120)); 75 } 76 77 await LocalStorageWrapper.SaveCacheToLocalStorage(LocalStorage); 78 } 79 } 80 81 }