From 2a5a9954125827a37ad6ff5aedcc9170ba19fa23 Mon Sep 17 00:00:00 2001 From: Paul Betts Date: Sun, 30 Jun 2013 15:13:37 -0700 Subject: [PATCH] WIP --- Splat/PlatformModeDetector.cs | 148 +++++++++++++++++----------------- Splat/Splat-NetCore45.csproj | 1 + Splat/Splat-wp8.csproj | 1 + 3 files changed, 76 insertions(+), 74 deletions(-) diff --git a/Splat/PlatformModeDetector.cs b/Splat/PlatformModeDetector.cs index 70e917d..4be6281 100644 --- a/Splat/PlatformModeDetector.cs +++ b/Splat/PlatformModeDetector.cs @@ -1,75 +1,75 @@ -using System; -using System.IO; -using System.Reflection; -using System.Collections.Generic; -using System.Linq; - -namespace Splat -{ - public class PlatformModeDetector : IModeDetector - { - public bool? InUnitTestRunner() - { - var testAssemblies = new[] { - "CSUNIT", - "NUNIT", - "XUNIT", - "MBUNIT", - "PEX.", - "NBEHAVE", - }; - - try { - return searchForAssembly(testAssemblies); - } catch (Exception) { - return null; - } - } - - public bool? InDesignMode() - { -#if SILVERLIGHT - if (Application.Current.RootVisual != null) { - return System.ComponentModel.DesignerProperties.GetIsInDesignMode(Application.Current.RootVisual); - } -#elif WINRT - return DesignMode.DesignModeEnabled; -#else - var designEnvironments = new[] { - "BLEND.EXE", - "XDESPROC.EXE", - }; - - var entry = Assembly.GetEntryAssembly(); - if (entry != null) { - var exeName = (new FileInfo(entry.Location)).Name.ToUpperInvariant(); - - if (designEnvironments.Any(x => x.Contains(exeName))) { - return true; - } - } -#endif - return false; - } - - static bool searchForAssembly(IEnumerable assemblyList) - { -#if SILVERLIGHT - return Deployment.Current.Parts.Any(x => assemblyList.Any(name => x.Source.ToUpperInvariant().Contains(name))); -#elif WINRT - var depPackages = Package.Current.Dependencies.Select(x => x.Id.FullName); - if (depPackages.Any(x => assemblyList.Any(name => x.ToUpperInvariant().Contains(name)))) return true; - - var fileTask = Task.Factory.StartNew(async () => { - var files = await Package.Current.InstalledLocation.GetFilesAsync(); - return files.Select(x => x.Path).ToArray(); - }, TaskCreationOptions.HideScheduler).Unwrap(); - - return fileTask.Result.Any(x => assemblyList.Any(name => x.ToUpperInvariant().Contains(name))); -#else - return AppDomain.CurrentDomain.GetAssemblies() - .Any(x => assemblyList.Any(name => x.FullName.ToUpperInvariant().Contains(name))); -#endif - } - } +using System; +using System.IO; +using System.Reflection; +using System.Collections.Generic; +using System.Linq; + +namespace Splat +{ + public class PlatformModeDetector : IModeDetector + { + public bool? InUnitTestRunner() + { + var testAssemblies = new[] { + "CSUNIT", + "NUNIT", + "XUNIT", + "MBUNIT", + "PEX.", + "NBEHAVE", + }; + + try { + return searchForAssembly(testAssemblies); + } catch (Exception) { + return null; + } + } + + public bool? InDesignMode() + { +#if SILVERLIGHT + if (Application.Current.RootVisual != null) { + return System.ComponentModel.DesignerProperties.GetIsInDesignMode(Application.Current.RootVisual); + } +#elif WINRT + return DesignMode.DesignModeEnabled; +#else + var designEnvironments = new[] { + "BLEND.EXE", + "XDESPROC.EXE", + }; + + var entry = Assembly.GetEntryAssembly(); + if (entry != null) { + var exeName = (new FileInfo(entry.Location)).Name.ToUpperInvariant(); + + if (designEnvironments.Any(x => x.Contains(exeName))) { + return true; + } + } +#endif + return false; + } + + static bool searchForAssembly(IEnumerable assemblyList) + { +#if SILVERLIGHT + return Deployment.Current.Parts.Any(x => assemblyList.Any(name => x.Source.ToUpperInvariant().Contains(name))); +#elif WINRT + var depPackages = Package.Current.Dependencies.Select(x => x.Id.FullName); + if (depPackages.Any(x => assemblyList.Any(name => x.ToUpperInvariant().Contains(name)))) return true; + + var fileTask = Task.Factory.StartNew(async () => { + var files = await Package.Current.InstalledLocation.GetFilesAsync(); + return files.Select(x => x.Path).ToArray(); + }, TaskCreationOptions.HideScheduler).Unwrap(); + + return fileTask.Result.Any(x => assemblyList.Any(name => x.ToUpperInvariant().Contains(name))); +#else + return AppDomain.CurrentDomain.GetAssemblies() + .Any(x => assemblyList.Any(name => x.FullName.ToUpperInvariant().Contains(name))); +#endif + } + } } \ No newline at end of file diff --git a/Splat/Splat-NetCore45.csproj b/Splat/Splat-NetCore45.csproj index 1643c80..f35db2b 100644 --- a/Splat/Splat-NetCore45.csproj +++ b/Splat/Splat-NetCore45.csproj @@ -104,6 +104,7 @@ + diff --git a/Splat/Splat-wp8.csproj b/Splat/Splat-wp8.csproj index 9e4ccd7..192f29c 100644 --- a/Splat/Splat-wp8.csproj +++ b/Splat/Splat-wp8.csproj @@ -83,6 +83,7 @@ 4 +