forked from AIStoryBuilders/AIStoryBuilders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainLayout.razor
90 lines (81 loc) · 2.7 KB
/
MainLayout.razor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
@using AIStoryBuilders.Models;
@inherits LayoutComponentBase
@inject AppMetadata _AppMetadata
<RadzenDialog />
<RadzenNotification />
<RadzenTooltip />
<RadzenContextMenu />
<main>
<div class="top-row px-4">
@if (UpdateAvailable)
{
<a href="https://apps.microsoft.com/detail/9NCJN9W323DB?rtc=1&hl=en-us&gl=US" target="_blank">* Update Available *</a>
}
else
{
<a href="https://AIStoryBuilders.com/" target="_blank">AIStoryBuilders.com</a>
}
</div>
<article class="content px-4">
@Body
</article>
</main>
<RadzenFooter>
<div class="row justify-content-start align-items-center px-2 pt-2 p-3 mb-2 bg-light text-dark">
<div class="col-12 d-flex align-items-left">
© @year - Version: @versionLocal
</div>
</div>
</RadzenFooter>
@code {
bool UpdateAvailable = false;
private string versionLocal = "";
private string versionPublished = "";
private string year = DateTime.Now.Year.ToString();
protected override void OnInitialized()
{
versionLocal = _AppMetadata.Version;
}
protected override async Task OnInitializedAsync()
{
try
{
// Call the API at https://aistorybuilders.com/api/version/GetVersion
// to get the version
var client = new HttpClient();
var response = await client.GetAsync("https://aistorybuilders.com/api/version/GetVersion");
response.EnsureSuccessStatusCode();
var result = await response.Content.ReadAsStringAsync();
versionPublished = result;
// Use the version number from the API if it is greater than the local version
if (ConvertToInteger(versionPublished) > ConvertToInteger(versionLocal))
{
UpdateAvailable = true;
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
#region private int ConvertToInteger(string strParamVersion)
private int ConvertToInteger(string strParamVersion)
{
int intVersionNumber = 0;
string strVersion = strParamVersion;
// Split into parts seperated by periods
char[] splitchar = { '.' };
var strSegments = strVersion.Split(splitchar);
// Process the segments
int i = 0;
List<int> colMultiplyers = new List<int> { 10000, 100, 1 };
foreach (var strSegment in strSegments)
{
int intSegmentNumber = Convert.ToInt32(strSegment);
intVersionNumber = intVersionNumber + (intSegmentNumber * colMultiplyers[i]);
i++;
}
return intVersionNumber;
}
#endregion
}