Skip to content

Commit 7ef982d

Browse files
Add LabStatus solution
1 parent 7f8ef5b commit 7ef982d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1666
-0
lines changed

LabStatus/LabStatus.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.3.32519.111
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LabStatus", "LabStatus\LabStatus.csproj", "{E6F257E2-7738-42A1-A169-BD6E59DA5E38}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{E6F257E2-7738-42A1-A169-BD6E59DA5E38}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{E6F257E2-7738-42A1-A169-BD6E59DA5E38}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{E6F257E2-7738-42A1-A169-BD6E59DA5E38}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{E6F257E2-7738-42A1-A169-BD6E59DA5E38}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {B35286D8-15E6-4BF5-AD70-FC3C6CE09AF4}
24+
EndGlobalSection
25+
EndGlobal

LabStatus/LabStatus/App.razor

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
namespace LabStatus.Data
2+
{
3+
public class LabInfo
4+
{
5+
public string Name { get; set; } = string.Empty;
6+
public int Status { get; set; }
7+
}
8+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
namespace LabStatus.Data
2+
{
3+
public class LabStatusDal
4+
{
5+
public List<string> GetLabs()
6+
{
7+
lock (LabStatusDb.SyncKey)
8+
{
9+
return LabStatusDb.Labs.ToList();
10+
}
11+
}
12+
13+
public Dictionary<string, int> GetUserStatus(string user)
14+
{
15+
lock (LabStatusDb.SyncKey)
16+
{
17+
var userExists = LabStatusDb.CurrentUsers.Where(r => r == user).Any();
18+
if (!userExists)
19+
AddUser(user);
20+
21+
var userData = LabStatusDb.LabStatus.Where(r => r.Key == user).FirstOrDefault().Value;
22+
var result = new Dictionary<string, int>();
23+
int i = 0;
24+
foreach (var item in GetLabs())
25+
result.Add(item, userData[i++]);
26+
return result;
27+
}
28+
}
29+
30+
public void UpdateStatus(string user, string itemName, int status)
31+
{
32+
lock (LabStatusDb.SyncKey)
33+
{
34+
var index = -1;
35+
foreach (var item in LabStatusDb.Labs)
36+
{
37+
index++;
38+
if (item == itemName)
39+
break;
40+
}
41+
var userData = LabStatusDb.LabStatus.Where(r => r.Key == user).First().Value;
42+
userData[index] = status;
43+
}
44+
}
45+
46+
public void AddUser(string user)
47+
{
48+
lock (LabStatusDb.SyncKey)
49+
{
50+
var exists = LabStatusDb.CurrentUsers.Where(r => r == user).Any();
51+
if (!exists)
52+
LabStatusDb.CurrentUsers.Add(user);
53+
LabStatusDb.LabStatus.TryAdd(user, new List<int> { 0, 0, 0, 0, 0, 0 });
54+
}
55+
}
56+
57+
public void RemoveUser(string user)
58+
{
59+
lock (LabStatusDb.SyncKey)
60+
{
61+
var exists = LabStatusDb.CurrentUsers.Where(r => r == user).Any();
62+
if (exists)
63+
{
64+
List<int> x;
65+
LabStatusDb.LabStatus.TryRemove(user, out x);
66+
LabStatusDb.CurrentUsers.Remove(user);
67+
}
68+
}
69+
}
70+
71+
public List<string> GetUsers()
72+
{
73+
lock (LabStatusDb.SyncKey)
74+
{
75+
return LabStatusDb.CurrentUsers.ToList();
76+
}
77+
}
78+
79+
public Dictionary<string, List<int>> GetAllData()
80+
{
81+
lock (LabStatusDb.SyncKey)
82+
{
83+
var result = new Dictionary<string, List<int>>();
84+
foreach (var item in LabStatusDb.LabStatus)
85+
result.Add(item.Key, item.Value.ToList());
86+
return result;
87+
}
88+
}
89+
}
90+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Collections.Concurrent;
2+
3+
namespace LabStatus.Data
4+
{
5+
public static class LabStatusDb
6+
{
7+
public readonly static object SyncKey = new();
8+
9+
public readonly static List<string> Labs = new List<string>
10+
{
11+
{ "Lab00 - verify tools" },
12+
{ "Lab01 - aspnetcore in docker" },
13+
{ "Lab02 - aspnetcore in Azure" },
14+
{ "Lab03 - example running in docker-compose" },
15+
{ "Lab04 - install rabbitmq in kubernetes" },
16+
{ "Lab05 - example running in kubernetes" }
17+
};
18+
19+
public readonly static List<string> CurrentUsers = new List<string>();
20+
21+
public readonly static ConcurrentDictionary<string, List<int>> LabStatus = new ConcurrentDictionary<string, List<int>>();
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace LabStatus.Data
2+
{
3+
public class WeatherForecast
4+
{
5+
public DateTime Date { get; set; }
6+
7+
public int TemperatureC { get; set; }
8+
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
10+
11+
public string? Summary { get; set; }
12+
}
13+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace LabStatus.Data
2+
{
3+
public class WeatherForecastService
4+
{
5+
private static readonly string[] Summaries = new[]
6+
{
7+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
8+
};
9+
10+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
11+
{
12+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
13+
{
14+
Date = startDate.AddDays(index),
15+
TemperatureC = Random.Shared.Next(-20, 55),
16+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
17+
}).ToArray());
18+
}
19+
}
20+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
@page "/counter"
2+
3+
<PageTitle>Counter</PageTitle>
4+
5+
<h1>Counter</h1>
6+
7+
<p role="status">Current count: @currentCount</p>
8+
9+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
10+
11+
@code {
12+
private int currentCount = 0;
13+
14+
private void IncrementCount()
15+
{
16+
currentCount++;
17+
}
18+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@page
2+
@model LabStatus.Pages.ErrorModel
3+
4+
<!DOCTYPE html>
5+
<html lang="en">
6+
7+
<head>
8+
<meta charset="utf-8" />
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
10+
<title>Error</title>
11+
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet" />
12+
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true" />
13+
</head>
14+
15+
<body>
16+
<div class="main">
17+
<div class="content px-4">
18+
<h1 class="text-danger">Error.</h1>
19+
<h2 class="text-danger">An error occurred while processing your request.</h2>
20+
21+
@if (Model.ShowRequestId)
22+
{
23+
<p>
24+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
25+
</p>
26+
}
27+
28+
<h3>Development Mode</h3>
29+
<p>
30+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
31+
</p>
32+
<p>
33+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
34+
It can result in displaying sensitive information from exceptions to end users.
35+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
36+
and restarting the app.
37+
</p>
38+
</div>
39+
</div>
40+
</body>
41+
42+
</html>

0 commit comments

Comments
 (0)