Datei: NDODLL/Provider/NDOProviderPathFinder.cs

Last Commit (37b7958)
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Linq;
5
6 namespace NDO.Provider
7 {
8 ····class NDOProviderPathFinder : IProviderPathFinder
9 ····{
10 ········readonly string[] netstandardVersions = {··"2.0", "2.1"};
11 ········readonly string standard = "netstandard";
12
13 ········public IEnumerable<string> GetPaths()
14 ········{
15 ············List<string>paths = new List<string>();
16 ············var path = AppDomain.CurrentDomain.BaseDirectory;
17 ············paths.Add( path );
18 ············
19 ············string binPath = Path.Combine( path, "bin" );
20 ············if (Directory.Exists( binPath ))
21 ················paths.Add(binPath);
22
23 ············// This is a hack to determine any loaded provider packages.
24 ············var runtimeDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
25
26 ············if (runtimeDir != null && runtimeDir.IndexOf( "Microsoft.NETCore.App" ) > -1)
27 ············{
28 ················path = typeof( PersistenceManager ).Assembly.Location;
29 ················var pattern = $".nuget{Path.DirectorySeparatorChar}packages";
30 ················int p;
31 ················if (( p = path.IndexOf( pattern ) ) > -1)
32 ················{
33 ····················p += pattern.Length;
34 ····················path = path.Substring( 0, p );
35 ····················var majorVersion = GetType().Assembly.GetName().Version.Major.ToString();
36
37 ····················foreach (var subPath in Directory.GetDirectories( path, "ndo.*" ))
38 ····················{
39 ························if (Path.GetFileName( subPath ).Equals( "ndo.dll", StringComparison.OrdinalIgnoreCase ))
40 ····························continue;
41 ························if (Path.GetFileName( subPath ).Equals( "ndo.jsonformatter", StringComparison.OrdinalIgnoreCase ) )
42 ····························continue;
43 #warning We must sort the versions here and take the last one of the same major version
44 ························var versionDir = Directory.GetDirectories( subPath ).FirstOrDefault( s => Path.GetFileName( s ).StartsWith( majorVersion) );
45 ························if (versionDir == null)
46 ····························continue;
47
48 ························foreach (var v in netstandardVersions)
49 ························{
50 ····························var libDir = Path.Combine( versionDir, "lib", standard + v );
51 ····························if (!Directory.Exists( libDir ))
52 ································continue;
53 ····························paths.Add( libDir );
54 ························}
55 ····················}
56 ················}
57 ············}
58
59 ············return paths;
60 ········}
61 ····}
62 }
63
New Commit (1b950ea)
1 using System;
2 using System.Collections.Generic;
3 using System.IO;
4 using System.Linq;
5
6 namespace NDO.Provider
7 {
8 ····class NDOProviderPathFinder : IProviderPathFinder
9 ····{
10 ········readonly string[] netstandardVersions = {··"2.0", "2.1"};
11 ········readonly string standard = "netstandard";
12
13 ········public IEnumerable<string> GetPaths()
14 ········{
15 ············List<string>paths = new List<string>();
16 ············var path = AppDomain.CurrentDomain.BaseDirectory;
17 ············paths.Add( path );
18 ············
19 ············string binPath = Path.Combine( path, "bin" );
20 ············if (Directory.Exists( binPath ))
21 ················paths.Add(binPath);
22
23 ············// This is a hack to determine any loaded provider packages.
24 ············var runtimeDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
25
26 ············if (runtimeDir != null && runtimeDir.IndexOf( "Microsoft.NETCore.App" ) > -1)
27 ············{
28 ················path = typeof( PersistenceManager ).Assembly.Location;
29 ················var pattern = $".nuget{Path.DirectorySeparatorChar}packages";
30 ················int p;
31 ················if (( p = path.IndexOf( pattern ) ) > -1)
32 ················{
33 ····················p += pattern.Length;
34 ····················path = path.Substring( 0, p );
35 ····················var majorVersion = GetType().Assembly.GetName().Version.Major.ToString();
36
37 ····················foreach (var subPath in Directory.GetDirectories( path, "ndo.*" ))
38 ····················{
39 ························if (Path.GetFileName( subPath ).Equals( "ndo.dll", StringComparison.OrdinalIgnoreCase ))
40 ····························continue;
41 ························if (Path.GetFileName( subPath ).Equals( "ndo.jsonformatter", StringComparison.OrdinalIgnoreCase ) )
42 ····························continue;
43 //TODO We should sort the versions here and take the last one of the same major version
44 ························var versionDir = Directory.GetDirectories( subPath ).FirstOrDefault( s => Path.GetFileName( s ).StartsWith( majorVersion) );
45 ························if (versionDir == null)
46 ····························continue;
47
48 ························foreach (var v in netstandardVersions)
49 ························{
50 ····························var libDir = Path.Combine( versionDir, "lib", standard + v );
51 ····························if (!Directory.Exists( libDir ))
52 ································continue;
53 ····························paths.Add( libDir );
54 ························}
55 ····················}
56 ················}
57 ············}
58
59 ············return paths;
60 ········}
61 ····}
62 }
63