1+ using System ;
2+ using System . Data . SqlTypes ;
3+ using System . Diagnostics ;
4+ using System . IO ;
5+ using System . Net . Http ;
6+ using System . Threading . Tasks ;
7+ using OpenTabletDriver . Web . Core . Services ;
8+
9+ namespace OpenTabletDriver . Web . Core . Framework
10+ {
11+ public class DotnetCoreService : IFrameworkService
12+ {
13+ private const string AKA_MS = @"https://aka.ms/dotnet" ;
14+ private const string CHANNEL = "current" ;
15+
16+ public string GetLatestVersionUrl ( FrameworkPlatform platform , FrameworkArchetecture archetecture )
17+ {
18+ string product = GetProduct ( platform ) ;
19+ string extension = GetExtension ( platform ) ;
20+ string os = GetNormalizedOS ( platform ) ;
21+ string arch = GetNormalizedArchitecture ( archetecture ) ;
22+
23+ switch ( platform )
24+ {
25+ case FrameworkPlatform . Linux :
26+ // Link to package manager instructions instead of binaries or an installer.
27+ return "https://docs.microsoft.com/en-us/dotnet/core/install/linux" ;
28+ case FrameworkPlatform . Windows :
29+ case FrameworkPlatform . MacOS :
30+ return $ "{ AKA_MS } /{ CHANNEL } /{ product } -{ os } -{ arch } .{ extension } ";
31+ default :
32+ throw new Exception ( "Unsupported platform." ) ;
33+ }
34+ }
35+
36+ private string GetProduct ( FrameworkPlatform platform )
37+ {
38+ switch ( platform )
39+ {
40+ case FrameworkPlatform . Linux :
41+ case FrameworkPlatform . MacOS :
42+ return "dotnet-runtime" ;
43+ case FrameworkPlatform . Windows :
44+ return "windowsdesktop-runtime" ;
45+ default :
46+ return null ;
47+ }
48+ }
49+
50+ private string GetExtension ( FrameworkPlatform platform )
51+ {
52+ switch ( platform )
53+ {
54+ case FrameworkPlatform . Linux :
55+ return "tar.gz" ;
56+ case FrameworkPlatform . MacOS :
57+ return "pkg" ;
58+ case FrameworkPlatform . Windows :
59+ return "exe" ;
60+ default :
61+ return null ;
62+ }
63+ }
64+
65+ private static string GetNormalizedOS ( FrameworkPlatform platform )
66+ {
67+ return platform switch
68+ {
69+ FrameworkPlatform . Windows => "win" ,
70+ FrameworkPlatform . Linux => "linux" ,
71+ FrameworkPlatform . MacOS => "osx" ,
72+ _ => null
73+ } ;
74+ }
75+
76+ private string GetNormalizedArchitecture ( FrameworkArchetecture archetecture )
77+ {
78+ return archetecture switch
79+ {
80+ FrameworkArchetecture . x64 => "x64" ,
81+ FrameworkArchetecture . x86 => "x86" ,
82+ FrameworkArchetecture . ARM64 => "arm64" ,
83+ _ => null
84+ } ;
85+ }
86+ }
87+ }
0 commit comments