|
1 |
| -@page "/" |
2 |
| -@inject SessionStorage SessionStorage |
3 |
| -@inject LocalStorage LocalStorage |
4 |
| -@inject HttpClient Http |
5 |
| -@inject InteropStorage InteropStorage |
6 |
| -@inject IJSRuntime JSRuntime |
7 |
| -@using Blazor.Extensions.Storage.Test.Interop |
8 |
| - |
9 |
| -<h1>Test logging output: (See debugger log for full output)</h1> |
10 |
| - |
11 |
| -<div> |
12 |
| - @foreach (var message in log) |
13 |
| - { |
14 |
| - <div>@message</div> |
15 |
| - } |
16 |
| -</div> |
17 |
| - |
18 |
| -@functions { |
19 |
| - private WeatherForecast[] forecasts; |
20 |
| - |
21 |
| - private List<string> log = new List<string>(); |
22 |
| - |
23 |
| - private async void LogInformation(object message) |
24 |
| - { |
25 |
| - log.Add(message.ToString()); |
26 |
| - var _ = await JSRuntime.InvokeAsync<object>("console.info", message); |
27 |
| - } |
28 |
| - |
29 |
| - private async void LogError(object message) |
30 |
| - { |
31 |
| - log.Add($"ERROR: {message.ToString()}"); |
32 |
| - var _ = await JSRuntime.InvokeAsync<object>("console.error", message); |
33 |
| - } |
34 |
| - |
35 |
| - protected override async Task OnInitAsync() |
36 |
| - { |
37 |
| - forecasts = (await Http.GetJsonAsync<WeatherForecast[]>("weather.json")); |
38 |
| - var key = "forecasts"; |
39 |
| - try |
40 |
| - { |
41 |
| - await SessionStorage.SetItem<WeatherForecast[]>(key, forecasts); |
42 |
| - await LocalStorage.SetItem<WeatherForecast[]>(key, forecasts); |
43 |
| - |
44 |
| - var fromIopSession = await InteropStorage.GetSessionStorage(key); |
45 |
| - var fromIopLocal = await InteropStorage.GetLocalStorage(key); |
46 |
| - |
47 |
| - var iopSessionHasQuotes = fromIopSession.StartsWith("\"") || fromIopSession.EndsWith("\""); |
48 |
| - var iopLocalHasQuotes = fromIopLocal.StartsWith("\"") || fromIopLocal.EndsWith("\""); |
49 |
| - |
50 |
| - LogInformation($"Interop get from session storage contains extra quotes: {iopSessionHasQuotes}"); |
51 |
| - LogInformation(fromIopSession); |
52 |
| - LogInformation($"Interop get from local storage contains extra quotes: {iopLocalHasQuotes}"); |
53 |
| - LogInformation(fromIopLocal); |
54 |
| - |
55 |
| - var fromSession = await SessionStorage.GetItem<WeatherForecast[]>(key); |
56 |
| - var fromLocal = await LocalStorage.GetItem<WeatherForecast[]>(key); |
57 |
| - |
58 |
| - LogInformation("From session storage:"); |
59 |
| - LogInformation(fromSession); |
60 |
| - LogInformation("From local storage:"); |
61 |
| - LogInformation(fromLocal); |
62 |
| - |
63 |
| - LogInformation($"Total in session: {await SessionStorage.Length()}"); |
64 |
| - LogInformation($"Total in local: {await LocalStorage.Length()}"); |
65 |
| - |
66 |
| - LogInformation("Removing from session storage..."); |
67 |
| - await SessionStorage.RemoveItem(key); |
68 |
| - LogInformation("Removing from local storage..."); |
69 |
| - await LocalStorage.RemoveItem(key); |
70 |
| - |
71 |
| - LogInformation($"Total in session: {await SessionStorage.Length()}"); |
72 |
| - LogInformation($"Total in local: {await SessionStorage.Length()}"); |
73 |
| - } |
74 |
| - catch (Exception ex) |
75 |
| - { |
76 |
| - LogError(ex); |
77 |
| - } |
78 |
| - } |
79 |
| - |
80 |
| - class WeatherForecast |
81 |
| - { |
82 |
| - public DateTime Date { get; set; } |
83 |
| - public int TemperatureC { get; set; } |
84 |
| - public int TemperatureF { get; set; } |
85 |
| - public string Summary { get; set; } |
86 |
| - } |
87 |
| -} |
| 1 | +@page "/" |
| 2 | +@inject SessionStorage SessionStorage |
| 3 | +@inject LocalStorage LocalStorage |
| 4 | +@inject HttpClient Http |
| 5 | +@inject InteropStorage InteropStorage |
| 6 | +@inject IJSRuntime JSRuntime |
| 7 | +@using Blazor.Extensions.Storage.Test.Interop |
| 8 | + |
| 9 | +<h1>Test logging output: (See debugger log for full output)</h1> |
| 10 | + |
| 11 | +<div> |
| 12 | + @foreach (var message in log) |
| 13 | + { |
| 14 | + <div>@message</div> |
| 15 | + } |
| 16 | +</div> |
| 17 | + |
| 18 | +@functions { |
| 19 | + private WeatherForecast[] forecasts; |
| 20 | + |
| 21 | + private List<string> log = new List<string>(); |
| 22 | + |
| 23 | + private async void LogInformation(object message) |
| 24 | + { |
| 25 | + log.Add(message.ToString()); |
| 26 | + var _ = await JSRuntime.InvokeAsync<object>("console.info", message); |
| 27 | + } |
| 28 | + |
| 29 | + private async void LogError(object message) |
| 30 | + { |
| 31 | + log.Add($"ERROR: {message.ToString()}"); |
| 32 | + var _ = await JSRuntime.InvokeAsync<object>("console.error", message); |
| 33 | + } |
| 34 | + |
| 35 | + protected override async Task OnInitializedAsync() |
| 36 | + { |
| 37 | + forecasts = (await Http.GetJsonAsync<WeatherForecast[]>("weather.json")); |
| 38 | + var key = "forecasts"; |
| 39 | + try |
| 40 | + { |
| 41 | + await SessionStorage.SetItem<WeatherForecast[]>(key, forecasts); |
| 42 | + await LocalStorage.SetItem<WeatherForecast[]>(key, forecasts); |
| 43 | + |
| 44 | + var fromIopSession = await InteropStorage.GetSessionStorage(key); |
| 45 | + var fromIopLocal = await InteropStorage.GetLocalStorage(key); |
| 46 | + |
| 47 | + var iopSessionHasQuotes = fromIopSession.StartsWith("\"") || fromIopSession.EndsWith("\""); |
| 48 | + var iopLocalHasQuotes = fromIopLocal.StartsWith("\"") || fromIopLocal.EndsWith("\""); |
| 49 | + |
| 50 | + LogInformation($"Interop get from session storage contains extra quotes: {iopSessionHasQuotes}"); |
| 51 | + LogInformation(fromIopSession); |
| 52 | + LogInformation($"Interop get from local storage contains extra quotes: {iopLocalHasQuotes}"); |
| 53 | + LogInformation(fromIopLocal); |
| 54 | + |
| 55 | + var fromSession = await SessionStorage.GetItem<WeatherForecast[]>(key); |
| 56 | + var fromLocal = await LocalStorage.GetItem<WeatherForecast[]>(key); |
| 57 | + |
| 58 | + LogInformation("From session storage:"); |
| 59 | + LogInformation(fromSession); |
| 60 | + LogInformation("From local storage:"); |
| 61 | + LogInformation(fromLocal); |
| 62 | + |
| 63 | + LogInformation($"Total in session: {await SessionStorage.Length()}"); |
| 64 | + LogInformation($"Total in local: {await LocalStorage.Length()}"); |
| 65 | + |
| 66 | + LogInformation("Removing from session storage..."); |
| 67 | + await SessionStorage.RemoveItem(key); |
| 68 | + LogInformation("Removing from local storage..."); |
| 69 | + await LocalStorage.RemoveItem(key); |
| 70 | + |
| 71 | + LogInformation($"Total in session: {await SessionStorage.Length()}"); |
| 72 | + LogInformation($"Total in local: {await SessionStorage.Length()}"); |
| 73 | + } |
| 74 | + catch (Exception ex) |
| 75 | + { |
| 76 | + LogError(ex); |
| 77 | + } |
| 78 | + } |
| 79 | + |
| 80 | + class WeatherForecast |
| 81 | + { |
| 82 | + public DateTime Date { get; set; } |
| 83 | + public int TemperatureC { get; set; } |
| 84 | + public int TemperatureF { get; set; } |
| 85 | + public string Summary { get; set; } |
| 86 | + } |
| 87 | +} |
0 commit comments