Example #1
0
        static Env()
        {
            if (PclExport.Instance == null)
            {
                throw new ArgumentException("PclExport.Instance needs to be initialized");
            }

            var platformName = PclExport.Instance.PlatformName;

            if (platformName != PclExport.Platforms.WindowsStore)
            {
                IsMono = AssemblyUtils.FindType("Mono.Runtime") != null;

                IsMonoTouch = AssemblyUtils.FindType("MonoTouch.Foundation.NSObject") != null ||
                              AssemblyUtils.FindType("Foundation.NSObject") != null;

                IsAndroid = AssemblyUtils.FindType("Android.Manifest") != null;

                //Throws unhandled exception if not called from the main thread
                //IsWinRT = AssemblyUtils.FindType("Windows.ApplicationModel") != null;

                IsWindowsPhone = AssemblyUtils.FindType("Microsoft.Phone.Info.DeviceStatus") != null;

                IsSilverlight = AssemblyUtils.FindType("System.Windows.Interop.SilverlightHost") != null;
            }
            else
            {
                IsWindowsStore = true;
            }

#if PCL
            IsUnix = IsMono;
#else
            var platform = (int)Environment.OSVersion.Platform;
            IsUnix = (platform == 4) || (platform == 6) || (platform == 128);
#endif

            ServerUserAgent = "ServiceStack/" +
                              ServiceStackVersion + " "
                              + platformName
                              + (IsMono ? "/Mono" : "/.NET");

            VersionString = ServiceStackVersion.ToString(CultureInfo.InvariantCulture);

            __releaseDate = new DateTime(2001, 01, 01);
        }
Example #2
0
File: Env.cs Project: jre08/YAFNET
        static Env()
        {
            if (PclExport.Instance == null)
            {
                throw new ArgumentException("PclExport.Instance needs to be initialized");
            }

            var platformName = PclExport.Instance.PlatformName;

            if (platformName != PclExport.Platforms.Uwp)
            {
                IsMono = AssemblyUtils.FindType("Mono.Runtime") != null;

                IsIOS = AssemblyUtils.FindType("MonoTouch.Foundation.NSObject") != null ||
                        AssemblyUtils.FindType("Foundation.NSObject") != null;

                IsAndroid = AssemblyUtils.FindType("Android.Manifest") != null;

                try
                {
                    IsOSX = AssemblyUtils.FindType("Mono.AppKit") != null;
#if NET472
                    IsWindows = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("windir"));
                    if (File.Exists(@"/System/Library/CoreServices/SystemVersion.plist"))
                    {
                        IsOSX = true;
                    }
                    string osType = File.Exists(@"/proc/sys/kernel/ostype") ? File.ReadAllText(@"/proc/sys/kernel/ostype") : null;
                    IsLinux = osType?.IndexOf("Linux", StringComparison.OrdinalIgnoreCase) >= 0;
#endif
                }
                catch (Exception) {}
            }
            else
            {
                IsUWP = true;
            }

#if NETSTANDARD2_0
            IsNetStandard = true;
            try
            {
                IsLinux   = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux);
                IsWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
                IsOSX     = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX);
            }
            catch (Exception) {} // throws PlatformNotSupportedException in AWS lambda
            IsUnix = IsOSX || IsLinux;
            HasMultiplePlatformTargets = true;
#elif NET45
            IsNetFramework = true;
            var platform = (int)Environment.OSVersion.Platform;
            IsUnix  = platform == 4 || platform == 6 || platform == 128;
            IsLinux = IsUnix;
            if (Environment.GetEnvironmentVariable("OS")?.IndexOf("Windows", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                IsWindows = true;
            }
#endif
            SupportsExpressions = true;
            SupportsEmit        = !IsIOS;

            ServerUserAgent = "ServiceStack/" +
                              ServiceStackVersion + " "
                              + platformName
                              + (IsMono ? "/Mono" : "/.NET");

            VersionString = ServiceStackVersion.ToString(CultureInfo.InvariantCulture);

            __releaseDate = new DateTime(2001, 01, 01);
        }
        static Env()
        {
            if (PclExport.Instance == null)
            {
                throw new ArgumentException("PclExport.Instance needs to be initialized");
            }

#if NETSTANDARD2_0 || NETCORE2_1
            IsNetStandard = true;
            try
            {
                IsLinux    = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux);
                IsWindows  = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
                IsOSX      = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX);
                IsNetCore3 = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription.StartsWith(".NET Core 3");

                var fxDesc = System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription;
                IsMono    = fxDesc.Contains("Mono");
                IsNetCore = fxDesc.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase);
            }
            catch (Exception) {} //throws PlatformNotSupportedException in AWS lambda
            IsUnix = IsOSX || IsLinux;
            HasMultiplePlatformTargets = true;
            IsUWP = IsRunningAsUwp();
#elif NET45
            IsNetFramework = true;
            switch (Environment.OSVersion.Platform)
            {
            case PlatformID.Win32NT:
            case PlatformID.Win32S:
            case PlatformID.Win32Windows:
            case PlatformID.WinCE:
                IsWindows = true;
                break;
            }

            var platform = (int)Environment.OSVersion.Platform;
            IsUnix = platform == 4 || platform == 6 || platform == 128;

            if (File.Exists(@"/System/Library/CoreServices/SystemVersion.plist"))
            {
                IsOSX = true;
            }
            var osType = File.Exists(@"/proc/sys/kernel/ostype")
                ? File.ReadAllText(@"/proc/sys/kernel/ostype")
                : null;
            IsLinux = osType?.IndexOf("Linux", StringComparison.OrdinalIgnoreCase) >= 0;
            try
            {
                IsMono = AssemblyUtils.FindType("Mono.Runtime") != null;
            }
            catch (Exception) {}

            SupportsDynamic = true;
#endif

#if NETCORE2_1
            IsNetStandard   = false;
            IsNetCore       = true;
            SupportsDynamic = true;
#endif

            if (!IsUWP)
            {
                try
                {
                    IsAndroid = AssemblyUtils.FindType("Android.Manifest") != null;
                    if (IsOSX && IsMono)
                    {
                        var runtimeDir = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
                        //iOS detection no longer trustworthy so assuming iOS based on some current heuristics. TODO: improve iOS detection
                        IsIOS = runtimeDir.StartsWith("/private/var") ||
                                runtimeDir.Contains("/CoreSimulator/Devices/");
                    }
                }
                catch (Exception) {}
            }

            SupportsExpressions = true;
            SupportsEmit        = !(IsUWP || IsIOS);

            if (!SupportsEmit)
            {
                ReflectionOptimizer.Instance = ExpressionReflectionOptimizer.Provider;
            }

            ServerUserAgent = "ServiceStack/" +
                              ServiceStackVersion + " "
                              + PclExport.Instance.PlatformName
                              + (IsMono ? "/Mono" : "")
                              + (IsLinux ? "/Linux" : IsOSX ? "/OSX" : IsUnix ? "/Unix" : IsWindows ? "/Windows" : "/UnknownOS")
                              + (IsIOS ? "/iOS" : IsAndroid ? "/Android" : IsUWP ? "/UWP" : "");

            VersionString = ServiceStackVersion.ToString(CultureInfo.InvariantCulture);

            __releaseDate = new DateTime(2018, 12, 16);
        }
Example #4
0
        static Env()
        {
            if (PclExport.Instance == null)
            {
                throw new ArgumentException("PclExport.Instance needs to be initialized");
            }

            var platformName = PclExport.Instance.PlatformName;

            if (platformName != PclExport.Platforms.WindowsStore)
            {
                IsMono = AssemblyUtils.FindType("Mono.Runtime") != null;

                IsMonoTouch = AssemblyUtils.FindType("MonoTouch.Foundation.NSObject") != null ||
                              AssemblyUtils.FindType("Foundation.NSObject") != null;

                IsAndroid = AssemblyUtils.FindType("Android.Manifest") != null;

                try
                {
                    IsOSX = AssemblyUtils.FindType("Mono.AppKit") != null;
#if NET45
                    IsWindows = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("windir"));
                    if (File.Exists(@"/System/Library/CoreServices/SystemVersion.plist"))
                    {
                        IsOSX = true;
                    }
                    string osType = File.Exists(@"/proc/sys/kernel/ostype") ? File.ReadAllText(@"/proc/sys/kernel/ostype") : null;
                    IsLinux = osType?.IndexOf("Linux", StringComparison.OrdinalIgnoreCase) >= 0;
#endif
                }
                catch (Exception ignore) {}

                //Throws unhandled exception if not called from the main thread
                //IsWinRT = AssemblyUtils.FindType("Windows.ApplicationModel") != null;

                IsWindowsPhone = AssemblyUtils.FindType("Microsoft.Phone.Info.DeviceStatus") != null;

                IsSilverlight = AssemblyUtils.FindType("System.Windows.Interop.SilverlightHost") != null;
            }
            else
            {
                IsWindowsStore = true;
            }

#if PCL
            IsUnix    = IsMono || IsOSX || IsLinux;
            IsWindows = !IsUnix;
#elif NETSTANDARD1_1
            IsLinux   = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Linux);
            IsWindows = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows);
            IsOSX     = System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.OSX);
            IsUnix    = IsOSX || IsLinux;
            HasMultiplePlatformTargets = true;
#elif NET45
            var platform = (int)Environment.OSVersion.Platform;
            IsUnix  = platform == 4 || platform == 6 || platform == 128;
            IsLinux = IsUnix;
            if (Environment.GetEnvironmentVariable("OS")?.IndexOf("Windows", StringComparison.OrdinalIgnoreCase) >= 0)
            {
                IsWindows = true;
            }
#endif

            ServerUserAgent = "ServiceStack/" +
                              ServiceStackVersion + " "
                              + platformName
                              + (IsMono ? "/Mono" : "/.NET");

            VersionString = ServiceStackVersion.ToString(CultureInfo.InvariantCulture);

            __releaseDate = new DateTime(2001, 01, 01);
        }