11using System ;
2- using System . Linq ;
3- using System . Reflection ;
42using Exceptionless . Logging ;
53using Exceptionless . Models ;
4+ using Exceptionless . Utility ;
65
76namespace Exceptionless . Plugins . Default {
87 [ Priority ( 80 ) ]
@@ -40,10 +39,10 @@ private string GetVersion(IExceptionlessLog log) {
4039 if ( _appVersionLoaded )
4140 return _appVersion ;
4241
43- var entryAssembly = GetEntryAssembly ( log ) ;
42+ var entryAssembly = AssemblyHelper . GetEntryAssembly ( log ) ;
4443
4544 try {
46- string version = GetVersionFromAssembly ( entryAssembly ) ;
45+ string version = AssemblyHelper . GetVersionFromAssembly ( entryAssembly ) ;
4746 if ( ! String . IsNullOrEmpty ( version ) ) {
4847 _appVersion = version ;
4948 _appVersionLoaded = true ;
@@ -54,80 +53,11 @@ private string GetVersion(IExceptionlessLog log) {
5453 log . FormattedError ( typeof ( VersionPlugin ) , ex , "Unable to get version from loaded assemblies. Error: {0}" , ex . Message ) ;
5554 }
5655
57- #if NETSTANDARD2_0
58- try {
59- var platformService = Microsoft . Extensions . PlatformAbstractions . PlatformServices . Default ;
60-
61- _appVersion = platformService . Application . ApplicationVersion ;
62- _appVersionLoaded = true ;
63-
64- return _appVersion ;
65- } catch ( Exception ex ) {
66- log . FormattedError ( typeof ( VersionPlugin ) , ex , "Unable to get Platform Services instance. Error: {0}" , ex . Message ) ;
67- }
68- #endif
69-
7056 _appVersion = null ;
7157 _appVersionLoaded = true ;
7258
7359 return null ;
7460 }
7561
76- private string GetVersionFromAssembly ( Assembly assembly ) {
77- if ( assembly == null )
78- return null ;
79-
80- string version = assembly . GetInformationalVersion ( ) ;
81- if ( String . IsNullOrEmpty ( version ) || String . Equals ( version , "0.0.0.0" ) )
82- version = assembly . GetFileVersion ( ) ;
83-
84- if ( String . IsNullOrEmpty ( version ) || String . Equals ( version , "0.0.0.0" ) )
85- version = assembly . GetVersion ( ) ;
86-
87- if ( String . IsNullOrEmpty ( version ) || String . Equals ( version , "0.0.0.0" ) ) {
88- var assemblyName = assembly . GetAssemblyName ( ) ;
89- version = assemblyName != null ? assemblyName . Version . ToString ( ) : null ;
90- }
91-
92- return ! String . IsNullOrEmpty ( version ) && ! String . Equals ( version , "0.0.0.0" ) ? version : null ;
93- }
94-
95- private Assembly GetEntryAssembly ( IExceptionlessLog log ) {
96- var entryAssembly = Assembly . GetEntryAssembly ( ) ;
97- if ( IsUserAssembly ( entryAssembly ) )
98- return entryAssembly ;
99-
100- try {
101- var assemblies = AppDomain . CurrentDomain . GetAssemblies ( ) . Where ( a =>
102- ! a . IsDynamic
103- && a != typeof ( ExceptionlessClient ) . GetTypeInfo ( ) . Assembly
104- && a != GetType ( ) . GetTypeInfo ( ) . Assembly
105- && a != typeof ( object ) . GetTypeInfo ( ) . Assembly ) ;
106-
107- return assemblies . FirstOrDefault ( a => IsUserAssembly ( a ) ) ;
108- } catch ( Exception ex ) {
109- log . FormattedError ( typeof ( VersionPlugin ) , ex , "Unable to get entry assembly. Error: {0}" , ex . Message ) ;
110- }
111-
112- return null ;
113- }
114-
115- private bool IsUserAssembly ( Assembly assembly ) {
116- if ( assembly == null )
117- return false ;
118-
119- if ( ! String . IsNullOrEmpty ( assembly . FullName ) && ( assembly . FullName . StartsWith ( "System." ) || assembly . FullName . StartsWith ( "Microsoft." ) ) )
120- return false ;
121-
122- string company = assembly . GetCompany ( ) ?? String . Empty ;
123- string [ ] nonUserCompanies = new [ ] { "Exceptionless" , "Microsoft" } ;
124- if ( nonUserCompanies . Any ( c => company . IndexOf ( c , StringComparison . OrdinalIgnoreCase ) >= 0 ) )
125- return false ;
126-
127- if ( assembly . FullName == typeof ( ExceptionlessClient ) . GetTypeInfo ( ) . Assembly . FullName )
128- return false ;
129-
130- return true ;
131- }
13262 }
13363}
0 commit comments