public void DoesNotThrowWhenDisposingTwice()
        {
            var cf = new WinChromaFactory();

#pragma warning disable IDISP016, IDISP017
            cf.Dispose();
            cf.Dispose();
#pragma warning restore IDISP016, IDISP017
        }
예제 #2
0
        public AppContext(string appSettingsPath = null)
        {
            _appSettingsPath = appSettingsPath ?? AppSettings.GetDefaultPath();

            this.TrayIcon.Icon = Resources.EliteChromaIcon;

            ContextMenu.Items.Add("&Settings...", null, Settings_Click);
            ContextMenu.Items.Add("-");
            ContextMenu.Items.Add("&About...", null, About_Click);
            ContextMenu.Items.Add("-");
            ContextMenu.Items.Add("E&xit", null, Exit_Click);

            _chromaFactory = new WinChromaFactory();
        }
        public async Task WaitsForChromaSdkDeviceAccessEvent()
        {
            using var cpl = ColoreProviderLock.GetLock();

            var chromaApi = new Mock <IChromaApi>()
            {
                DefaultValue = DefaultValue.Mock
            };

            using var cf = new WinChromaFactory
                  {
                      ChromaApi     = chromaApi.Object,
                      ChromaAppInfo = null,
                  };

            Assert.Equal(TimeSpan.Zero, cf.WarmupDelay);

            var cw = GetChromaWindowInstance(cf);

            var tcs = new TaskCompletionSource <IntPtr>();

            chromaApi
            .Setup(x => x.RegisterEventNotifications(It.IsAny <IntPtr>()))
            .Callback((IntPtr hWnd) => tcs.SetResult(hWnd));

            var tChroma = cf.CreateAsync();

            var hWnd = await tcs.Task.ConfigureAwait(false);

            Assert.Equal(cw.Handle, hWnd);

            // Reference: https://assets.razerzone.com/dev_portal/C%2B%2B/html/en/_rz_chroma_s_d_k_8h.html#afc89b7127b37c6448277a2334b1e34db
            const int deviceAccess  = 2;
            const int grantedAccess = 1;

            SendChromaEventMessage(cw, deviceAccess, grantedAccess);

            var chroma = await tChroma.ConfigureAwait(false);

            Assert.NotNull(chroma);

            await chroma.UninitializeAsync().ConfigureAwait(false);
        }
 private static ChromaWindow GetChromaWindowInstance(WinChromaFactory cf)
 {
     return((ChromaWindow)cf.GetType()
            .GetField("_cw", BindingFlags.NonPublic | BindingFlags.Instance)
            .GetValue(cf));
 }