Esempio n. 1
0
    public static OSPlatform GetOSPlatform()
    {
        if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
        {
            return(OSPlatform.Windows);
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
        {
            return(OSPlatform.Linux);
        }
        else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
        {
            return(OSPlatform.OSX);
        }

        return(OSPlatform.Create("Unknown"));
    }
Esempio n. 2
0
        private static Platform DetermineOSPlatform()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                return(Platform.Linux);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                return(Platform.Darwin);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")))
            {
                return(Platform.FreeBSD);
            }

            return(Platform.Unknown);
        }
        public static OSPlatform GetOS()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(OSPlatform.Windows);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                return(OSPlatform.Linux);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                return(OSPlatform.OSX);
            }

            return(OSPlatform.Create("UNKNOWN"));
        }
Esempio n. 4
0
        public static OSPlatform GetOSPlatform()
        {
            OSPlatform osPlatform = OSPlatform.Create("Other Platform");
            bool       isWindows  = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);

            osPlatform = isWindows ? OSPlatform.Windows : osPlatform;

            bool isOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);

            osPlatform = isOSX ? OSPlatform.OSX : osPlatform;

            bool isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);

            osPlatform = isLinux ? OSPlatform.Linux : osPlatform;

            return(osPlatform);
        }
        private static HttpMessageHandler CreateDefaultHandler(HttpPipelineTransportOptions?options = null)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
            {
                return(new HttpClientHandler());
            }

#if NETCOREAPP
            return(ApplyOptionsToHandler(new SocketsHttpHandler {
                AllowAutoRedirect = false
            }, options));
#else
            return(ApplyOptionsToHandler(new HttpClientHandler {
                AllowAutoRedirect = false
            }, options));
#endif
        }
Esempio n. 6
0
        [Fact, PlatformSpecific(TestPlatforms.NetBSD)]  // Tests RuntimeInformation OS platform
        public void CheckNetBSD()
        {
            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")));

            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("netbsd")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("LINUX")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("linux")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("ubuntu")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("UNIX")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.OSX));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
        }
Esempio n. 7
0
        [Fact, PlatformSpecific(TestPlatforms.tvOS)]  // Tests RuntimeInformation OS platform
        public void ChecktvOS()
        {
            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.tvOS));
            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("TVOS")));

            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("netbsd")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("osx")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("mac")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACOSX")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
        }
Esempio n. 8
0
        /// <summary>
        /// Constructs an instance of <see cref="ProtectedBrowserStorage"/>.
        /// </summary>
        /// <param name="storeName">The name of the store in which the data should be stored.</param>
        /// <param name="jsRuntime">The <see cref="IJSRuntime"/>.</param>
        /// <param name="dataProtectionProvider">The <see cref="IDataProtectionProvider"/>.</param>
        private protected ProtectedBrowserStorage(string storeName, IJSRuntime jsRuntime, IDataProtectionProvider dataProtectionProvider)
        {
            // Performing data protection on the client would give users a false sense of security, so we'll prevent this.
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
            {
                throw new PlatformNotSupportedException($"{GetType()} cannot be used when running in a browser.");
            }

            if (string.IsNullOrEmpty(storeName))
            {
                throw new ArgumentException("The value cannot be null or empty", nameof(storeName));
            }

            _storeName = storeName;
            _jsRuntime = jsRuntime ?? throw new ArgumentNullException(nameof(jsRuntime));
            _dataProtectionProvider = dataProtectionProvider ?? throw new ArgumentNullException(nameof(dataProtectionProvider));
        }
Esempio n. 9
0
 public Commands(bool delta, bool full, DirectoryInfo?outputLocation, DirectoryInfo?newVersionLocation, DirectoryInfo?oldVersionLocation, string?applicationFile,
                 bool skipVerifying, bool verify, string?applierType, string?creatorType, string?intendedOs, int?stagingPercentage)
 {
     Delta              = delta;
     Full               = full;
     OutputLocation     = outputLocation;
     NewVersionLocation = newVersionLocation;
     OldVersionLocation = oldVersionLocation;
     ApplicationFile    = applicationFile !;
     ShouldVerify       = verify;
     ApplierType        = applierType;
     CreatorType        = creatorType;
     StagingPercentage  = stagingPercentage;
     SkipVerify         = skipVerifying;
     IntendedOs         = !string.IsNullOrWhiteSpace(intendedOs)
         ? OSPlatform.Create(intendedOs)
         : null;
 }
Esempio n. 10
0
        // https://github.com/dotnet/runtime/issues/51052
        static int vsnprintf(IntPtr buffer, UIntPtr size, IntPtr format, IntPtr args)
        {
            var os = Environment.OSVersion;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(Native.vsnprintf_windows(buffer, size, format, args));
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                return(Native.vsnprintf_linux(buffer, size, format, args));
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")))
            {
                return(Native.vsprintf_linux(buffer, format, args));
            }
            return(-1);
        }
Esempio n. 11
0
        [Fact, PlatformSpecific(TestPlatforms.Android)]  // Tests RuntimeInformation OS platform
        public void CheckAndroid()
        {
            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Android));
            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")));
            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("android")));

            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("netbsd")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("osx")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("mac")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACOSX")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
        }
Esempio n. 12
0
        [Fact, PlatformSpecific(TestPlatforms.Browser)]  // Tests RuntimeInformation OS platform
        public void CheckBrowser()
        {
            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Browser));
            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")));
            Assert.True(RuntimeInformation.IsOSPlatform(OSPlatform.Create("browser")));

            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NETBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("NetBSD")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("netbsd")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("osx")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("mac")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("DARWIN")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Create("MACOSX")));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Linux));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.Windows));
            Assert.False(RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD));
        }
        /// <summary>
        /// Adds Google Tag Mananger (GTM) support. Use <see cref="IHxGoogleTagManager"/> to push data to <c>dataLayer</c> and/or <see cref="HxGoogleTagManagerPageViewTracker"/> to track page-views.
        /// </summary>
        /// <param name="services"></param>
        /// <param name="configureOptions"></param>
        /// <returns></returns>
        public static IServiceCollection AddHxGoogleTagManager(this IServiceCollection services, Action <HxGoogleTagManagerOptions> configureOptions)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("browser")))
            {
                services.AddSingleton <IHxGoogleTagManager, HxGoogleTagManager>();
            }
            else
            {
                services.AddScoped <IHxGoogleTagManager, HxGoogleTagManager>();
            }

            if (configureOptions != null)
            {
                services.Configure(configureOptions);
            }

            return(services);
        }
Esempio n. 14
0
        /// <summary>Returns OS</summary>
        public static OSPlatform GetOS()
        {
            OSPlatform OS = OSPlatform.Create("placeholder");

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                OS = OSPlatform.Windows;
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                OS = OSPlatform.Linux;
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                OS = OSPlatform.OSX;
            }

            return(OS);
        }
Esempio n. 15
0
 public void LdapConnection_Bind_Using_Sasl_DigestMd5_Proxy(string platform)
 {
     if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)))
     {
         return;
     }
     using (var connection = new LdapConnection())
     {
         connection.Connect(Config.LdapHost, Config.LdapPort);
         connection.Bind(LdapAuthType.Digest, new LdapCredential
         {
             UserName        = Config.LdapDigestMd5UserName,
             Password        = Config.LdapPassword,
             AuthorizationId = $"dn:{Config.LdapDigestMd5ProxyDn}"
         });
         var authzId = connection.WhoAmI().Result;
         Assert.Equal($"dn:{Config.LdapDigestMd5ProxyDn}", authzId);
     }
 }
        private static HttpMessageHandler CreateDefaultHandler()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
            {
                return(new HttpClientHandler());
            }

#if NETCOREAPP
            return(new SocketsHttpHandler()
            {
                AllowAutoRedirect = false
            });
#else
            return(new HttpClientHandler()
            {
                AllowAutoRedirect = false
            });
#endif
        }
Esempio n. 17
0
 static PlatformInformation()
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         Platform = OSPlatform.Windows;
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         Platform = OSPlatform.Linux;
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
     {
         Platform = OSPlatform.OSX;
     }
     else
     {
         Platform = OSPlatform.Create("Unknown");
     }
 }
Esempio n. 18
0
        public static OSPlatform Resolve()
        {
            var plat = OSPlatform.Create("Unknown");

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                return(OSPlatform.Linux);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                return(OSPlatform.OSX);
            }
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(OSPlatform.Windows);
            }

            return(plat);
        }
Esempio n. 19
0
        /// <summary>
        /// Gets the library name to use on the current platform.
        /// </summary>
        /// <returns>The library name.</returns>
        public string GetLibraryName()
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                return(RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")) ? Android : Linux);
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                return(Environment.Is64BitProcess ? Windows64 : Windows86);
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                return(RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")) ? IOS : MacOS);
            }

            throw new NotSupportedException("Invalid/unsupported operating system.");
        }
 public string GetLibraryName()
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         return(RuntimeInformation.IsOSPlatform(OSPlatform.Create("ANDROID")) ? Android : Linux);
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return(Windows);
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
     {
         return(RuntimeInformation.IsOSPlatform(OSPlatform.Create("IOS")) ? IOS : MacOS);
     }
     else
     {
         throw new NotSupportedException($"The library name couldn't be resolved for the given platform ('{RuntimeInformation.OSDescription}').");
     }
 }
Esempio n. 21
0
        public UserAgentProvider()
        {
            var executingAssembly = Assembly.GetExecutingAssembly();
            var assemblyVersion   = FileVersionInfo.GetVersionInfo(executingAssembly.Location).ProductVersion;

            var attr          = (AssemblyFileVersionAttribute)typeof(object).GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute));
            var frameworkName = "dotnet";

            if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Core", StringComparison.OrdinalIgnoreCase))
            {
                frameworkName += "Core";
            }
            else if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Native", StringComparison.OrdinalIgnoreCase))
            {
                frameworkName = "Native";
            }
            else if (RuntimeInformation.FrameworkDescription.StartsWith(".NET Framework", StringComparison.OrdinalIgnoreCase))
            {
                frameworkName = "Framework";
            }

            var osPlatform = string.Empty;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                osPlatform = " (" + OSPlatform.OSX + "/" + Environment.OSVersion.Version + ")";
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                osPlatform = " (" + OSPlatform.Windows + "/" + Environment.OSVersion.Version + ")";
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                osPlatform = " (" + OSPlatform.Linux + "/" + Environment.OSVersion.Version + ")";
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("FreeBSD")))
            {
                osPlatform = " (FreeBSD/" + Environment.OSVersion.Version + ")";
            }

            this.UserAgent = $"commercetools-sdk-dotnet-v1/{assemblyVersion} {frameworkName}/{attr.Version}{osPlatform}";
        }
Esempio n. 22
0
        public static void SetLimits(HttpMessageHandler messageHandler)
        {
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("BROWSER")))
            {
                return;
            }

            try
            {
                switch (messageHandler)
                {
                case HttpClientHandler httpClientHandler:
                    // Only change when the default runtime limit is used
                    if (httpClientHandler.MaxConnectionsPerServer == RuntimeDefaultConnectionLimit)
                    {
                        httpClientHandler.MaxConnectionsPerServer = IncreasedConnectionLimit;
                    }
                    break;

#if NETCOREAPP
                case SocketsHttpHandler socketsHttpHandler:
                    if (socketsHttpHandler.MaxConnectionsPerServer == RuntimeDefaultConnectionLimit)
                    {
                        socketsHttpHandler.MaxConnectionsPerServer = IncreasedConnectionLimit;
                    }
                    if (socketsHttpHandler.PooledConnectionLifetime == DefaultConnectionLeaseTimeoutTimeSpan)
                    {
                        socketsHttpHandler.PooledConnectionLifetime = IncreasedConnectionLeaseTimeoutTimeSpan;
                    }
                    break;
#endif
                default:
                    Debug.Assert(false, "Unknown handler type");
                    break;
                }
            }
            catch (NotSupportedException)
            {
                // Some platforms might throw NotSupportedException
                // when accessing handler options
            }
        }
Esempio n. 23
0
 static DbgOperatingSystem GetOperatingSystem()
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return(DbgOperatingSystem.Windows);
     }
     if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
     {
         return(DbgOperatingSystem.MacOS);
     }
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         return(DbgOperatingSystem.Linux);
     }
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("FREEBSD")))
     {
         return(DbgOperatingSystem.FreeBSD);
     }
     throw new InvalidOperationException("Unknown operating system");
 }
Esempio n. 24
0
 private OSPlatform DetermineOSPlatform()
 {
     if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
     {
         return(OSPlatform.Windows);
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
     {
         return(OSPlatform.Linux);
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.FreeBSD))
     {
         return(OSPlatform.FreeBSD);
     }
     else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
     {
         return(OSPlatform.OSX);
     }
     return(OSPlatform.Create("None"));
 }
Esempio n. 25
0
        /// <summary>
        /// Get OS platform
        /// </summary>
        /// <returns></returns>
        public static String GetOSPlatform()
        {
            OSPlatform osPlatform;

            try {
                osPlatform = OSPlatform.Create("Other Platform");
                // Check if it's windows
                bool isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
                osPlatform = isWindows ? OSPlatform.Windows : osPlatform;
                // Check if it's osx
                bool isOSX = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
                osPlatform = isOSX ? OSPlatform.OSX : osPlatform;
                // Check if it's Linux
                bool isLinux = RuntimeInformation.IsOSPlatform(OSPlatform.Linux);
                osPlatform = isLinux ? OSPlatform.Linux : osPlatform;
                return(osPlatform.ToString());
            }
            catch (Exception ex) {
                return(String.Format("Unable to get OS Platform. ERROR:{0} ERROR_MESSAGE:{1}", ex.HResult, ex.Message));
            }
        }
        public void LanguageWorker_HydratedWorkerPath_UnsupportedOS()
        {
            OSPlatform           bogusOS           = OSPlatform.Create("BogusOS");
            RpcWorkerDescription workerDescription = new RpcWorkerDescription()
            {
                Arguments                 = new List <string>(),
                DefaultExecutablePath     = "python",
                DefaultWorkerPath         = "{os}/worker.py",
                SupportedOperatingSystems = new List <string>()
                {
                    OSPlatform.Windows.ToString(),
                                 OSPlatform.OSX.ToString(),
                                 OSPlatform.Linux.ToString()
                },
                WorkerDirectory = string.Empty,
                Extensions      = new List <string>()
                {
                    ".py"
                },
                Language = "python",
                DefaultRuntimeVersion = "3.7"
            };
            var configBuilder = ScriptSettingsManager.CreateDefaultConfigurationBuilder()
                                .AddInMemoryCollection(new Dictionary <string, string>
            {
                ["languageWorker"] = "test"
            });
            var config = configBuilder.Build();
            var scriptSettingsManager = new ScriptSettingsManager(config);
            var testLogger            = new TestLogger("test");
            Mock <ISystemRuntimeInformation> mockRuntimeInfo = new Mock <ISystemRuntimeInformation>();

            mockRuntimeInfo.Setup(r => r.GetOSArchitecture()).Returns(Architecture.X64);
            mockRuntimeInfo.Setup(r => r.GetOSPlatform()).Returns(bogusOS);
            var configFactory = new RpcWorkerConfigFactory(config, testLogger, mockRuntimeInfo.Object, _testEnvironment, new TestMetricsLogger());

            var ex = Assert.Throws <PlatformNotSupportedException>(() => configFactory.GetHydratedWorkerPath(workerDescription));

            Assert.Equal(ex.Message, $"OS BogusOS is not supported for language {workerDescription.Language}");
        }
Esempio n. 27
0
 public static bool PlatformToSkipPredicate(SkipOnPlatform platform)
 {
     if (platform == SkipOnPlatform.All)
     {
         return(true);
     }
     if (platform == SkipOnPlatform.None)
     {
         return(false);
     }
     return(Enum.GetValues(typeof(SkipOnPlatform))
            .OfType <SkipOnPlatform>()
            .Where(z => z != SkipOnPlatform.All && z != SkipOnPlatform.None)
            .Where(z => (platform & z) == z)
            .Any(
                z => RuntimeInformation.IsOSPlatform(
                    platform switch {
         SkipOnPlatform.Linux => OSPlatform.Linux,
         SkipOnPlatform.Mac => OSPlatform.OSX,
         SkipOnPlatform.Windows => OSPlatform.Windows,
         _ => OSPlatform.Create("Unknown")
     }
Esempio n. 28
0
        public void LdapConnection_Bind_Using_Sasl_DigestMd5(string platform)
        {
            if (!RuntimeInformation.IsOSPlatform(OSPlatform.Create(platform)))
            {
                return;
            }
            using (var connection = new LdapConnection())
            {
                connection.Connect(Config.LdapHost, Config.LdapPort);

                connection.Bind(LdapAuthType.Digest, new LdapCredential
                {
                    UserName = Config.LdapDigestMd5UserName,
                    Password = Config.LdapPassword
                });
                var entries = connection.Search(Config.RootDn, $"(&(objectclass=top)(cn={Config.LdapDigestMd5UserName}))");
                Assert.True(entries.Count == 1);
                Assert.Equal("cn=digestTest,dc=example,dc=com", entries[0].Dn);
                Assert.Equal(Config.LdapDigestMd5UserName, entries[0].Attributes["cn"][0]);
                Assert.True(entries[0].Attributes["objectClass"].Any());
            }
        }
Esempio n. 29
0
        public void CheckOSPlatform()
        {
            OSPlatform winObj     = OSPlatform.Create("WINDOWS");
            OSPlatform winProp    = OSPlatform.Windows;
            OSPlatform randomObj  = OSPlatform.Create("random");
            OSPlatform defaultObj = default(OSPlatform);
            OSPlatform conObj     = new OSPlatform();

            Assert.Throws <ArgumentNullException>(() => { OSPlatform nullObj = OSPlatform.Create(null); });
            Assert.Throws <ArgumentException>(() => { OSPlatform emptyObj = OSPlatform.Create(""); });

            Assert.True(winObj == winProp);
            Assert.True(winObj != randomObj);
            Assert.True(defaultObj == conObj);

            Assert.False(winObj == defaultObj);
            Assert.False(winObj == randomObj);
            Assert.False(winObj != winProp);

            Assert.True(winObj.Equals(winProp));
            Assert.True(winObj.Equals((object)winProp));
            Assert.True(conObj.Equals(defaultObj));

            Assert.False(defaultObj.Equals(winProp));
            Assert.False(defaultObj.Equals((object)winProp));
            Assert.False(winObj.Equals(null));
            Assert.False(winObj.Equals("something"));

            Assert.Equal("WINDOWS", winObj.ToString());
            Assert.Equal("WINDOWS", winProp.ToString());
            Assert.Equal("", defaultObj.ToString());
            Assert.Equal("", conObj.ToString());
            Assert.Equal("random", randomObj.ToString());

            Assert.Equal(winObj.GetHashCode(), winProp.GetHashCode());
            Assert.Equal(0, defaultObj.GetHashCode());
            Assert.Equal(defaultObj.GetHashCode(), conObj.GetHashCode());
        }
Esempio n. 30
0
        public static async Task Main(string[] args)
        {
            var builder = WebAssemblyHostBuilder.CreateDefault(args);

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Create("WEBASSEMBLY")))
            {
                WebAssemblyHttpMessageHandlerOptions.DefaultCredentials = FetchCredentialsOption.Include;
            }

            builder.RootComponents.Add <App>("app");

            builder.Services.AddBlazoredLocalStorage();
            builder.Services.AddSingleton <IValidationService, ValidationService>();
            builder.Services.AddSingleton <IAuthenticationService, AuthenticationService>();
            builder.Services.AddSingleton <IProjectService, ProjectService>();
            builder.Services.AddSingleton <IUserAuthService, UserAuthService>();
            builder.Services.AddSingleton <IUserDataService, UserDataService>();
            builder.Services.AddSingleton <IUserService, UserService>();
            builder.Services.AddSingleton <IMessageService, MessageService>();
            builder.Services.AddSingleton <IPopupService <BlazorPopupService.Popup>, BlazorPopupService>();
            builder.Services.AddSingleton <Services.AuthenticationService>();
            builder.Services.AddBaseAddressHttpClient();

            var host = builder.Build();

            var userAuthService = host.Services.GetRequiredService <IUserAuthService>();
            var userDataService = host.Services.GetRequiredService <IUserDataService>();

            if (await userAuthService.TryLoadAuthentication())
            {
                await userDataService.LoadData();
            }

            //initialize authentication service
            var authenticationService = host.Services.GetService <Services.AuthenticationService>();

            await host.RunAsync();
        }