Skip to content

Commit 4fa1d06

Browse files
committed
Update KF app to use NET 6
1 parent f391fbb commit 4fa1d06

Some content is hidden

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

53 files changed

+1412
-1859
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>WinExe</OutputType>
5+
<TargetFramework>net6.0-windows</TargetFramework>
6+
<Nullable>enable</Nullable>
7+
<UseWindowsForms>true</UseWindowsForms>
8+
<FileVersion>2.3.0</FileVersion>
9+
<AssemblyVersion>2.3.0</AssemblyVersion>
10+
<RepositoryType>git</RepositoryType>
11+
<PackageReadmeFile>README.md</PackageReadmeFile>
12+
</PropertyGroup>
13+
14+
<ItemGroup>
15+
<None Include="..\..\README.md">
16+
<Pack>True</Pack>
17+
<PackagePath></PackagePath>
18+
</None>
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<Compile Update="Resources\MessagesText.Designer.cs">
23+
<DesignTime>True</DesignTime>
24+
<AutoGen>True</AutoGen>
25+
<DependentUpon>MessagesText.resx</DependentUpon>
26+
</Compile>
27+
<Compile Update="Views\AboutView.cs">
28+
<SubType>Form</SubType>
29+
</Compile>
30+
<Compile Update="Views\Controls\FlatTabControl.cs">
31+
<SubType>Component</SubType>
32+
</Compile>
33+
<Compile Update="Views\CreateProjectView.cs">
34+
<SubType>Form</SubType>
35+
</Compile>
36+
<Compile Update="Views\FlutterInstallView.cs">
37+
<SubType>Form</SubType>
38+
</Compile>
39+
<Compile Update="Views\StartupView.cs">
40+
<SubType>Form</SubType>
41+
</Compile>
42+
</ItemGroup>
43+
44+
<ItemGroup>
45+
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
46+
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
47+
<PackageReference Include="Serilog" Version="2.10.0" />
48+
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
49+
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
50+
<PackageReference Include="System.Text.Json" Version="5.0.2" />
51+
</ItemGroup>
52+
53+
<ItemGroup>
54+
<ProjectReference Include="..\KFlearning.Core\KFlearning.Core.csproj" />
55+
</ItemGroup>
56+
57+
<ItemGroup>
58+
<EmbeddedResource Update="Resources\MessagesText.resx">
59+
<Generator>ResXFileCodeGenerator</Generator>
60+
<LastGenOutput>MessagesText.Designer.cs</LastGenOutput>
61+
</EmbeddedResource>
62+
</ItemGroup>
63+
64+
</Project>

src/KFlearning.App/Program.cs

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
using System;
2+
using System.Net;
3+
using System.Threading;
4+
using System.Windows.Forms;
5+
using KFlearning.App.Resources;
6+
using KFlearning.App.Services;
7+
using KFlearning.App.Views;
8+
using KFlearning.Core.Extensions;
9+
using KFlearning.Core.Services;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Serilog;
12+
13+
namespace KFlearning.App
14+
{
15+
internal static class Program
16+
{
17+
private const int MutexTimeout = 1000;
18+
private const string MutexName = "KFlearning.SingleInstanceGuard";
19+
20+
public static ServiceProvider Container { get; private set; } = null!;
21+
22+
/// <summary>
23+
/// The main entry point for the application.
24+
/// </summary>
25+
[STAThread]
26+
static void Main()
27+
{
28+
//try
29+
//{
30+
using var mutex = new Mutex(true, MutexName);
31+
if (!mutex.WaitOne(MutexTimeout))
32+
{
33+
MessageBox.Show(MessagesText.SingleInstanceError, MessagesText.AppName,
34+
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
35+
return;
36+
}
37+
38+
// install services
39+
RegisterLogger();
40+
RegisterServices();
41+
42+
// find vscode
43+
var path = Container.GetRequiredService<IPathManager>();
44+
if (!path.IsVscodeInstalled)
45+
{
46+
Log.Debug("Visual Studio Code not found");
47+
MessageBox.Show(MessagesText.VSCodeNotInstalled, MessagesText.AppName,
48+
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
49+
return;
50+
}
51+
52+
// find mingw
53+
if (!path.IsKfMingwInstalled)
54+
{
55+
Log.Debug("KF-MinGW not found");
56+
MessageBox.Show(MessagesText.KFmingwNotInstalled, MessagesText.AppName,
57+
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
58+
return;
59+
}
60+
61+
// enable TLS
62+
Log.Debug("Enabling TLS support");
63+
NetworkHelpers.EnableTls();
64+
65+
// app exit handler
66+
Application.ApplicationExit += Application_ApplicationExit;
67+
68+
// bootstrapper
69+
Log.Debug("Bootstrapping application");
70+
71+
ApplicationConfiguration.Initialize();
72+
73+
Application.EnableVisualStyles();
74+
Application.SetCompatibleTextRenderingDefault(false);
75+
Application.Run(Container.GetRequiredService<KFlearningApplicationContext>());
76+
//}
77+
//catch (Exception e)
78+
//{
79+
// Log.Fatal("Application shutdown unexpectedly", e);
80+
// Log.CloseAndFlush();
81+
82+
// MessageBox.Show(MessagesText.FatalShutdown, MessagesText.AppName,
83+
// MessageBoxButtons.OK, MessageBoxIcon.Error);
84+
//}
85+
}
86+
87+
private static void RegisterLogger()
88+
{
89+
Log.Logger = new LoggerConfiguration()
90+
.MinimumLevel.Debug()
91+
.WriteTo.File("logs/kflearning-.txt", rollingInterval: RollingInterval.Day)
92+
.CreateLogger();
93+
}
94+
95+
private static void RegisterServices()
96+
{
97+
var services = new ServiceCollection();
98+
99+
// register views and presenters
100+
services.AddTransient<StartupView>();
101+
services.AddTransient<StartupViewPresenter>();
102+
services.AddTransient<AboutView>();
103+
services.AddTransient<CreateProjectView>();
104+
services.AddTransient<CreateProjectViewPresenter>();
105+
services.AddTransient<FlutterInstallView>();
106+
services.AddTransient<FlutterInstallViewPresenter>();
107+
108+
// register services
109+
services.AddSingleton<KFlearningApplicationContext>();
110+
services.AddSingleton<IHistoryService, HistoryService>();
111+
112+
services.AddSingleton<IPathManager, PathManager>();
113+
services.AddSingleton<IProcessManager, ProcessManager>();
114+
services.AddSingleton<IProjectService, ProjectService>();
115+
services.AddSingleton<ITemplateService, TemplateService>();
116+
services.AddSingleton<IPersistanceStorage, PersistanceStorage>();
117+
services.AddSingleton<IFlutterInstallService, FlutterInstallService>();
118+
services.AddSingleton<IVisualStudioCodeService, VisualStudioCodeService>();
119+
120+
// register clients
121+
services.AddTransient<WebClient>();
122+
123+
// setup logging
124+
services.AddLogging(configure =>
125+
{
126+
configure.AddSerilog();
127+
});
128+
129+
Container = services.BuildServiceProvider();
130+
}
131+
132+
private static void Application_ApplicationExit(object? sender, EventArgs e)
133+
{
134+
try
135+
{
136+
foreach (var usesPersistence in Container.GetServices<IUsesPersistence>())
137+
{
138+
usesPersistence.Save();
139+
}
140+
}
141+
catch (Exception ex)
142+
{
143+
Log.Error("Cannot save persistence", ex);
144+
}
145+
146+
Container.Dispose();
147+
}
148+
}
149+
}

0 commit comments

Comments
 (0)