Example #1
0
        public static void SetDefaultEndpoint(string devId, ERole eRole)
        {
            object o = (object)null;

            try
            {
                o = GetPolicyConfig();
                IPolicyConfigX     policyConfigX     = o as IPolicyConfigX;
                IPolicyConfig      policyConfig      = o as IPolicyConfig;
                IPolicyConfigVista policyConfigVista = o as IPolicyConfigVista;
                if (policyConfig != null)
                {
                    policyConfig.SetDefaultEndpoint(devId, eRole);
                }
                else if (policyConfigVista != null)
                {
                    policyConfigVista.SetDefaultEndpoint(devId, eRole);
                }
                else
                {
                    policyConfigX?.SetDefaultEndpoint(devId, eRole);
                }
            }
            finally
            {
                if (o != null && Marshal.IsComObject(o))
                {
                    Marshal.FinalReleaseComObject(o);
                }
                GC.Collect();
            }
        }
Example #2
0
        public PolicyClient()
        {
            _policyConfig = new _PolicyConfigClient();

            _configX     = _policyConfig as IPolicyConfigX;
            _configVII   = _policyConfig as IPolicyConfig;
            _configVista = _policyConfig as IPolicyConfigVista;
        }
Example #3
0
 public PolicyTaskHandler(
     ILogger logger,
     IPolicyConfig policyConfig
     )
 {
     _logger       = logger;
     _policyConfig = policyConfig;
     _cloudBaseApp = CloudBaseApp.Init(_policyConfig.CloudBaseEnvId, 10000);
     _httpClient   = new HttpClient();
 }
Example #4
0
        public PolicyConfigClient()
        {
            _PolicyConfig = new _PolicyConfigClient() as IPolicyConfig;
            if (_PolicyConfig != null)
            {
                return;
            }


            _PolicyConfig10 = new _PolicyConfigClient() as IPolicyConfig10;
        }
        public PolicyConfigClient()
        {
            _PolicyConfig = new _PolicyConfigClient() as IPolicyConfig;
            if (_PolicyConfig != null)
                return;

            _PolicyConfigVista = new _PolicyConfigClient() as IPolicyConfigVista;
            if (_PolicyConfigVista != null)
                return;

            _PolicyConfig10 = new _PolicyConfigClient() as IPolicyConfig10;
        }
Example #6
0
        public PolicyConfigClient()
        {
            _PolicyConfig = new _PolicyConfigClient() as IPolicyConfig;
            if (_PolicyConfig != null)
                return;

            _PolicyConfigVista = new _PolicyConfigClient() as IPolicyConfigVista;
            if (_PolicyConfigVista != null)
                return;

            _PolicyConfig10 = new _PolicyConfigClient() as IPolicyConfig10;
        }
Example #7
0
        // Switches default device to current default devices. Doesn't change the device, but sends an event so the program needs to aquire the device again, this time using our hook.
        public static void switchDefaultDevice()
        {
            List <SoundInfoDevice> devices = getSoundInfo();

            if (devices.Count >= 2)
            {
                IMMDeviceEnumerator enumerator = (IMMDeviceEnumerator) new DeviceEnumerator();
                string id = enumerator.GetDefaultAudioEndpoint(EDataFlow.eRender, ERole.eMultimedia).GetId();

                IPolicyConfig policyConfig = (IPolicyConfig) new IPolicyConfigClass();
                policyConfig.SetDefaultEndpoint(id, ERole.eMultimedia);
            }
        }
Example #8
0
        public PolicyConfigClient()
        {
            _PolicyConfig = new PolicyConfigClientCom() as IPolicyConfig;
            if (_PolicyConfig != null)
            {
                return;
            }

            _PolicyConfigVista = new PolicyConfigClientCom() as IPolicyConfigVista;
            if (_PolicyConfigVista != null)
            {
                return;
            }

            _PolicyConfig10 = new PolicyConfigClientCom() as IPolicyConfig10;
        }
Example #9
0
        public PolicyConfigClient()
        {
            _PolicyConfig = new CPolicyConfigClient() as IPolicyConfig;
            if (_PolicyConfig != null)
            {
                return;
            }

            _PolicyConfigVista = new CPolicyConfigClient() as IPolicyConfigVista;
            if (_PolicyConfigVista != null)
            {
                return;
            }

            Debug.Assert(!(_PolicyConfig == null && _PolicyConfigVista == null), "Have Microsoft changed the Guid for IPolicyConfig again?");
            _PolicyConfig10 = new CPolicyConfigClient() as IPolicyConfig10;
        }
Example #10
0
        public void SetDefaultAudioDevice(AudioDevice device, AudioDeviceRole role)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            // BADNESS: The following code uses an undocumented interface provided by the Audio SDK. This is completely
            // unsupported, and should be used for amusement purposes only. This is *extremely likely* to be broken
            // in future updates and/or versions of Windows. If Larry Osterman was dead, he would be rolling over
            // in his grave if he knew you were using this for nefarious purposes.
            IPolicyConfig config = (IPolicyConfig) new PolicyConfig();
            int           hr     = config.SetDefaultEndpoint(device.Id, role);

            if (hr != HResult.OK)
            {
                throw Marshal.GetExceptionForHR(hr);
            }
        }
Example #11
0
        public static void SetDefaultEndpoint(string devId, ERole eRole)
        {
            IPolicyConfig policyConfig = null;

            try
            {
                // ReSharper disable once SuspiciousTypeConversion.Global
                policyConfig = new _PolicyConfigClient() as IPolicyConfig;
                if (policyConfig != null)
                {
                    Marshal.ThrowExceptionForHR(policyConfig.SetDefaultEndpoint(devId, eRole));
                }
            }
            finally
            {
                if (policyConfig != null && Marshal.IsComObject(policyConfig))
                {
                    Marshal.FinalReleaseComObject(policyConfig);
                }

                GC.Collect();
            }
        }
Example #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PolicyConfigClientWin10"/> class.
 /// </summary>
 /// <param name="client">The client.</param>
 public PolicyConfigClient(IPolicyConfig client)
 => this.Client = client;
 public AudioWrapper()
 {
     LoadTimeout     = 10;
     _realEnumerator = new MMDeviceEnumerator() as IMMDeviceEnumerator;
     _policyConfig   = new PolicyConfigClient() as IPolicyConfig;
 }
        public static IServiceCollection AddDemoClient(this IServiceCollection services, Uri serviceBaseAddress, IPolicyConfig policyConfig, IIdentityConfig identityConfig)
        {
            services.AddHttpClient <IDemoClientSDK, DemoClientSDK>(x =>
            {
                x.BaseAddress = serviceBaseAddress;
                x.DefaultRequestHeaders.Add("Accept", "application/json");
                x.DefaultRequestHeaders.Add("User-Agent", "HttpClientFactory-Sample");
                x.DefaultRequestVersion = new Version(2, 0);
            })
            .AddResilience(policyConfig)
            .AddIdentity(identityConfig, new TokenStrategy());

            return(services);
        }
Example #15
0
        public static IHttpClientBuilder AddResilience(this IHttpClientBuilder clientBuilder, IPolicyConfig policyConfig)
        {
            if (policyConfig.HasResilicence)
            {
                clientBuilder.AddTransientHttpErrorPolicy(builder => builder.WaitAndRetryAsync(
                                                              new[] {
                    TimeSpan.FromSeconds(1),
                    TimeSpan.FromSeconds(5),
                    TimeSpan.FromSeconds(10),
                }));

                clientBuilder.AddTransientHttpErrorPolicy(builder => builder.CircuitBreakerAsync(
                                                              handledEventsAllowedBeforeBreaking: 3,
                                                              durationOfBreak: TimeSpan.FromSeconds(30)));

                if (policyConfig.HandlerLifetime.Ticks > 0)
                {
                    clientBuilder.SetHandlerLifetime(policyConfig.HandlerLifetime);
                }
            }

            return(clientBuilder);
        }
Example #16
0
 public PolicyConfig()
 {
     _policyConfig = new PolicyConfigComObject() as IPolicyConfig;
 }