Skip to content

Commit 0e3bd6c

Browse files
committed
Initial commit
1 parent d73de5d commit 0e3bd6c

File tree

5 files changed

+224
-0
lines changed

5 files changed

+224
-0
lines changed

.gitignore

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
*.swp
2+
*.*~
3+
project.lock.json
4+
.DS_Store
5+
*.pyc
6+
nupkg/
7+
8+
# Visual Studio Code
9+
.vscode
10+
11+
# Rider
12+
.idea
13+
14+
# User-specific files
15+
*.suo
16+
*.user
17+
*.userosscache
18+
*.sln.docstates
19+
20+
# Build results
21+
[Dd]ebug/
22+
[Dd]ebugPublic/
23+
[Rr]elease/
24+
[Rr]eleases/
25+
x64/
26+
x86/
27+
build/
28+
bld/
29+
[Bb]in/
30+
[Oo]bj/
31+
[Oo]ut/
32+
msbuild.log
33+
msbuild.err
34+
msbuild.wrn
35+
36+
# Visual Studio 2015
37+
.vs/
38+
39+
GFN.Queue/appsettings.Development.json

GFN.Queue.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 16
4+
VisualStudioVersion = 16.0.30523.141
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GFN.Queue", "GFN.Queue\GFN.Queue.csproj", "{93C538FD-B38A-42AB-A7F8-C65A9016DCAD}"
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+
{93C538FD-B38A-42AB-A7F8-C65A9016DCAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{93C538FD-B38A-42AB-A7F8-C65A9016DCAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{93C538FD-B38A-42AB-A7F8-C65A9016DCAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{93C538FD-B38A-42AB-A7F8-C65A9016DCAD}.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 = {AF430AE3-5EC7-4D5C-90A0-C806BCF85D5D}
24+
EndGlobalSection
25+
EndGlobal

GFN.Queue/GFN.Queue.csproj

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net5.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
10+
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
11+
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="5.0.0" />
12+
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
13+
<PackageReference Include="Spectre.Console" Version="0.33.0" />
14+
</ItemGroup>
15+
16+
<ItemGroup>
17+
<None Update="appsettings.Development.json">
18+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
19+
</None>
20+
<None Update="appsettings.json">
21+
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
22+
</None>
23+
</ItemGroup>
24+
25+
</Project>

GFN.Queue/Program.cs

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
using Microsoft.Extensions.Configuration;
2+
using Spectre.Console;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.IO;
6+
using System.Linq;
7+
using System.Threading;
8+
9+
namespace GFN.Queue
10+
{
11+
class Program
12+
{
13+
private const string TEXT_BEFORE_QUEUE_NUMBER = "queue: ";
14+
private static IConfigurationRoot config;
15+
16+
static void Main(string[] args)
17+
{
18+
var builder = new ConfigurationBuilder()
19+
.AddJsonFile($"appsettings.json", true, true);
20+
21+
config = builder.Build();
22+
23+
var startTimeSpan = TimeSpan.Zero;
24+
var periodTimeSpan = TimeSpan.FromSeconds(7);
25+
26+
var timer = new Timer((e) =>
27+
{
28+
Refresh();
29+
}, null, startTimeSpan, periodTimeSpan);
30+
Console.Read();
31+
}
32+
33+
private static void Refresh()
34+
{
35+
int currentQueueNumber = -1;
36+
var startDate = DateTime.Now;
37+
38+
var path = Path.GetFullPath(config["path"]);
39+
40+
List<string> debugFileLines = new List<string>();
41+
42+
var queueDatas = new List<QueueData>();
43+
44+
using (var fileStream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
45+
using (var reader = new StreamReader(fileStream))
46+
{
47+
string line;
48+
49+
while ((line = reader.ReadLine()) != null)
50+
{
51+
debugFileLines.Add(line);
52+
}
53+
}
54+
55+
foreach (var line in debugFileLines)
56+
{
57+
var queueData = ParseLine(line);
58+
if(queueData is null)
59+
{
60+
continue;
61+
}
62+
queueDatas.Add(queueData);
63+
currentQueueNumber = queueData.QueueNumber;
64+
}
65+
var queueHandler = new QueueHandler(queueDatas);
66+
AnsiConsole.Console.Clear(true);
67+
var table = new Table();
68+
// Add some columns
69+
table.AddColumn("Position in queue");
70+
table.AddColumn("StartTime");
71+
table.AddColumn("Time Awaited");
72+
table.AddColumn("Time by queue increment");
73+
table.AddColumn("Estimation");
74+
table.AddRow(
75+
queueHandler.CurrentQueuePosition.ToString(),
76+
queueHandler.StartTime.ToString(),
77+
queueHandler.TimeAwaited.ToString(),
78+
queueHandler.TimeByQueueIncrement.ToString(),
79+
queueHandler.Estimation.ToString());
80+
AnsiConsole.Render(table);
81+
}
82+
83+
private static QueueData ParseLine(string line)
84+
{
85+
if (!line.Contains(TEXT_BEFORE_QUEUE_NUMBER))
86+
{
87+
return null;
88+
}
89+
90+
int f = line.IndexOf("INFO:");
91+
var dateString = line.Substring(f - 13, 12);
92+
var date = DateTime.Parse(dateString);
93+
94+
int pFrom = line.IndexOf(TEXT_BEFORE_QUEUE_NUMBER) + TEXT_BEFORE_QUEUE_NUMBER.Length;
95+
96+
int pTo = line.LastIndexOf(",");
97+
98+
var result = line.Substring(pFrom, pTo - pFrom);
99+
100+
var queueNumber = int.Parse(result);
101+
102+
return new QueueData(queueNumber, date);
103+
}
104+
}
105+
106+
public class QueueHandler
107+
{
108+
public List<QueueData> QueueDatas { get; set; }
109+
110+
public int StartQueuePosition => QueueDatas.First().QueueNumber;
111+
public int CurrentQueuePosition => QueueDatas.Last().QueueNumber;
112+
public DateTime StartTime => QueueDatas.First().Date;
113+
public TimeSpan TimeAwaited => DateTime.Now.Subtract(StartTime);
114+
public TimeSpan TimeByQueueIncrement => TimeAwaited / (StartQueuePosition - CurrentQueuePosition);
115+
public TimeSpan Estimation => TimeByQueueIncrement * CurrentQueuePosition;
116+
public QueueHandler(List<QueueData> queueDatas)
117+
{
118+
QueueDatas = queueDatas;
119+
}
120+
}
121+
public class QueueData
122+
{
123+
public int QueueNumber { get; set; }
124+
public DateTime Date { get; set; }
125+
126+
public QueueData(int queueNumber, DateTime date)
127+
{
128+
QueueNumber = queueNumber;
129+
Date = date;
130+
}
131+
}
132+
}

GFN.Queue/appsettings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"path": ""
3+
}

0 commit comments

Comments
 (0)