Esempio n. 1
0
 private void Connection_OnApplicationDidLaunch(object sender, StreamDeckEventReceivedEventArgs <ApplicationDidLaunchEvent> e)
 {
     if (e.Event.Payload.Application.Equals("mixitup.exe", StringComparison.InvariantCultureIgnoreCase))
     {
         this.isMixItUpRunning = true;
     }
 }
Esempio n. 2
0
        private void OnReceiveGlobalSettings(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.DidReceiveGlobalSettingsEvent> e)
        {
            var settings = e.Event.Payload.Settings;

            __log.Debug(settings.ToString());

            var server = settings["server"].Value <string>();
            var port   = int.Parse(settings["port"].Value <string>());

            _userId = settings["user"].Value <string>();

            if (server != _server || port != _port)
            {
                if (_channel != null)
                {
                    Task task = _channel.ShutdownAsync();
                    task.Wait();
                }

                _channel = null;
                _client  = null;
                _server  = server;
                _port    = port;
            }
        }
Esempio n. 3
0
        private async void Connection_OnSendToPlugin(object sender, StreamDeckEventReceivedEventArgs <SendToPluginEvent> e)
        {
            if (!this.isMixItUpRunning)
            {
                // Send a message explaining this
                JObject response = new JObject
                {
                    ["error"] = JValue.CreateString("mixItUpIsNotRunning")
                };
                await this.connection.SendToPropertyInspectorAsync(e.Event.Action, response, e.Event.Context);

                return;
            }

            await this.actionsLock.WaitAsync();

            try
            {
                if (this.actions.ContainsKey(e.Event.Context.ToLower()))
                {
                    await this.actions[e.Event.Context.ToLower()].ProcessPropertyInspectorAsync(e.Event);
                }
            }
            finally
            {
                this.actionsLock.Release();
            }
        }
        // Action is loaded in the Stream Deck
        private async void Connection_OnWillAppear(object sender, StreamDeckEventReceivedEventArgs <WillAppearEvent> e)
        {
            SDConnection conn = new SDConnection(connection, pluginUUID, deviceInfo, e.Event.Action, e.Event.Context, e.Event.Device);
            await instancesLock.WaitAsync();

            try
            {
                if (supportedActions.ContainsKey(e.Event.Action))
                {
                    try
                    {
                        if (instances.ContainsKey(e.Event.Context) && instances[e.Event.Context] != null)
                        {
                            Logger.Instance.LogMessage(TracingLevel.INFO, $"WillAppear called for already existing context {e.Event.Context} (might be inside a multi-action)");
                            return;
                        }
                        InitialPayload payload = new InitialPayload(GenerateKeyCoordinates(e.Event.Payload.Coordinates),
                                                                    e.Event.Payload.Settings, e.Event.Payload.State, e.Event.Payload.IsInMultiAction, deviceInfo);
                        instances[e.Event.Context] = (PluginBase)Activator.CreateInstance(supportedActions[e.Event.Action], conn, payload);
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.LogMessage(TracingLevel.FATAL, $"Could not create instance of {supportedActions[e.Event.Action]} with context {e.Event.Context} - This may be due to an Exception raised in the constructor, or the class does not inherit PluginBase with the same constructor {ex}");
                    }
                }
                else
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"No plugin found that matches action: {e.Event.Action}");
                }
            }
            finally
            {
                instancesLock.Release();
            }
        }
        // Stopwatch instance created
        private async void Connection_OnWillAppear(object sender, StreamDeckEventReceivedEventArgs <WillAppearEvent> e)
        {
            SDConnection conn = new SDConnection(connection, pluginUUID, deviceInfo, e.Event.Action, e.Event.Context, e.Event.Device);
            await instancesLock.WaitAsync();

            try
            {
                if (supportedActions.ContainsKey(e.Event.Action))
                {
                    try
                    {
                        InitialPayload payload = new InitialPayload(GenerateKeyCoordinates(e.Event.Payload.Coordinates),
                                                                    e.Event.Payload.Settings, e.Event.Payload.State, e.Event.Payload.IsInMultiAction, deviceInfo);
                        instances[e.Event.Context] = (PluginBase)Activator.CreateInstance(supportedActions[e.Event.Action], conn, payload);
                    }
                    catch (Exception ex)
                    {
                        Logger.Instance.LogMessage(TracingLevel.FATAL, $"Could not create instance of {supportedActions[e.Event.Action]} - Maybe class does not inherit PluginBase with the same constructor? {ex}");
                    }
                }
                else
                {
                    Logger.Instance.LogMessage(TracingLevel.WARN, $"No plugin found that matches action: {e.Event.Action}");
                }
            }
            finally
            {
                instancesLock.Release();
            }
        }
        private void StreamDeckConnection_OnSendToPlugin(object sender,
                                                         StreamDeckEventReceivedEventArgs <SendToPluginEvent> e)
        {
            var payload = e.Event.Payload;

            if (Connection.ContextId != e.Event.Context)
            {
                return;
            }
        }
Esempio n. 7
0
        private void OnReceiveSettings(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.DidReceiveSettingsEvent> e)
        {
            string  context   = e.Event.Context;
            JObject settings  = e.Event.Payload.Settings;
            string  soundFile = settings["soundfile"].Value <string>();

            __log.DebugFormat("{0} {1} {2}", e.Event.Device, e.Event.Action, context);
            __log.DebugFormat("{0}", settings);

            _songs.AddOrUpdate(context, soundFile, (key, old) => soundFile);
        }
        // Settings updated
        private async void Connection_OnDidReceiveSettings(object sender, StreamDeckEventReceivedEventArgs <DidReceiveSettingsEvent> e)
        {
            await instancesLock.WaitAsync();

            try
            {
                if (instances.ContainsKey(e.Event.Context))
                {
                    instances[e.Event.Context].ReceivedSettings(JObject.FromObject(e.Event.Payload).ToObject <ReceivedSettingsPayload>());
                }
            }
            finally
            {
                instancesLock.Release();
            }
        }
Esempio n. 9
0
        private async void Connection_OnTitleParametersDidChange(object sender, StreamDeckEventReceivedEventArgs <TitleParametersDidChangeEvent> e)
        {
            await this.actionsLock.WaitAsync();

            try
            {
                if (this.actions.ContainsKey(e.Event.Context.ToLower()))
                {
                    await this.actions[e.Event.Context.ToLower()].TitleParametersDidChangeAsync(e.Event);
                }
            }
            finally
            {
                this.actionsLock.Release();
            }
        }
Esempio n. 10
0
        private async void Connection_OnKeyUp(object sender, StreamDeckEventReceivedEventArgs <KeyUpEvent> e)
        {
            await m_ActionsLock.WaitAsync();

            try
            {
                if (m_Actions.ContainsKey(e.Event.Context.ToLower()))
                {
                    await m_Actions[e.Event.Context.ToLower()].KeyUpAsync();
                }
            }
            finally
            {
                m_ActionsLock.Release();
            }
        }
Esempio n. 11
0
        private async void Connection_OnSendToPlugin(object sender, StreamDeckEventReceivedEventArgs <SendToPluginEvent> e)
        {
            await m_ActionsLock.WaitAsync();

            try
            {
                if (m_Actions.ContainsKey(e.Event.Context.ToLower()))
                {
                    await m_Actions[e.Event.Context.ToLower()].ProcessPropertyInspectorAsync(e.Event);
                }
            }
            finally
            {
                m_ActionsLock.Release();
            }
        }
        private async void Connection_OnWillDisappear(object sender, StreamDeckEventReceivedEventArgs <WillDisappearEvent> e)
        {
            await instancesLock.WaitAsync();

            try
            {
                if (instances.ContainsKey(e.Event.Context))
                {
                    instances[e.Event.Context].Dispose();
                    instances.Remove(e.Event.Context);
                }
            }
            finally
            {
                instancesLock.Release();
            }
        }
Esempio n. 13
0
        private async void Connection_OnWillDisappear(object sender, StreamDeckEventReceivedEventArgs <WillDisappearEvent> e)
        {
            await m_ActionsLock.WaitAsync();

            try
            {
                if (m_Actions.ContainsKey(e.Event.Context.ToLower()))
                {
                    await m_Actions[e.Event.Context.ToLower()].SaveAsync();
                    m_Actions.Remove(e.Event.Context.ToLower());
                }
            }
            finally
            {
                m_ActionsLock.Release();
            }
        }
        // Global settings updated
        private async void Connection_OnDidReceiveGlobalSettings(object sender, StreamDeckEventReceivedEventArgs <DidReceiveGlobalSettingsEvent> e)
        {
            await instancesLock.WaitAsync();

            try
            {
                var globalSettings = JObject.FromObject(e.Event.Payload).ToObject <ReceivedGlobalSettingsPayload>();
                foreach (string key in instances.Keys)
                {
                    instances[key].ReceivedGlobalSettings(globalSettings);
                }
            }
            finally
            {
                instancesLock.Release();
            }
        }
        // Button released
        private async void Connection_OnKeyUp(object sender, StreamDeckEventReceivedEventArgs <KeyUpEvent> e)
        {
            await instancesLock.WaitAsync();

            try
            {
                if (instances.ContainsKey(e.Event.Context))
                {
                    KeyPayload payload = new KeyPayload(GenerateKeyCoordinates(e.Event.Payload.Coordinates),
                                                        e.Event.Payload.Settings, e.Event.Payload.State, e.Event.Payload.UserDesiredState, e.Event.Payload.IsInMultiAction);
                    instances[e.Event.Context].KeyReleased(payload);
                }
            }
            finally
            {
                instancesLock.Release();
            }
        }
Esempio n. 16
0
        private async void Connection_OnWillAppear(object sender, StreamDeckEventReceivedEventArgs <WillAppearEvent> e)
        {
            await m_ActionsLock.WaitAsync();

            try
            {
                if (s_ActionList.ContainsKey(e.Event.Action.ToLower()))
                {
                    ActionBase action = Activator.CreateInstance(s_ActionList[e.Event.Action.ToLower()]) as ActionBase;
                    await action.LoadAsync(m_Connection, e.Event.Action, e.Event.Context, e.Event.Payload.Settings);

                    m_Actions[e.Event.Context.ToLower()] = action;
                }
            }
            finally
            {
                m_ActionsLock.Release();
            }
        }
Esempio n. 17
0
        // Settings updated
        private async void Connection_OnDidReceiveSettings(object sender, StreamDeckEventReceivedEventArgs <DidReceiveSettingsEvent> e)
        {
            await instancesLock.WaitAsync();

            try
            {
#if DEBUG
                Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnDidReceiveSettings: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}");
#endif

                if (instances.ContainsKey(e.Event.Context))
                {
                    instances[e.Event.Context].ReceivedSettings(JObject.FromObject(e.Event.Payload).ToObject <ReceivedSettingsPayload>());
                }
            }
            finally
            {
                instancesLock.Release();
            }
        }
Esempio n. 18
0
        private void OnPropertyInspectorAppeared(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.PropertyInspectorDidAppearEvent> e)
        {
            try
            {
                __log.DebugFormat("{0} {1} {2} {3}", e.Event.Device, e.Event.Context, e.Event.Action, e.Event.Event);
                var listUsersResponse = Client.ListUsers(new ListUsersRequest {
                    OnlyOnline = true
                });
                string context = e.Event.Context;

                JObject payload = new JObject();
                JArray  array   = new JArray(Songs);
                JArray  users   = new JArray();

                payload.Add("songs", array);
                payload.Add("users", users);

                if (_songs.TryGetValue(context, out string value))
                {
                    payload.Add("soundfile", value);
                }

                foreach (var user in listUsersResponse.Users)
                {
                    JObject u = new JObject();
                    u["id"]   = user.Id;
                    u["name"] = user.Name;

                    users.Add(u);
                }

                __log.DebugFormat("Sending payload {0}", payload);

                Task task = _connection.SendToPropertyInspectorAsync(PLAY_BUTTON_ID, payload, context);
                Task.WaitAll(task);
            }
            catch (Exception ex)
            {
                __log.Fatal(ex);
            }
        }
Esempio n. 19
0
        private async void Connection_OnWillDisappear(object sender, StreamDeckEventReceivedEventArgs <WillDisappearEvent> e)
        {
            await instancesLock.WaitAsync();

            try
            {
#if DEBUG
                Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnWillDisappear: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}");
#endif

                if (instances.ContainsKey(e.Event.Context))
                {
                    instances[e.Event.Context].Destroy();
                    instances.Remove(e.Event.Context);
                }
            }
            finally
            {
                instancesLock.Release();
            }
        }
Esempio n. 20
0
        // Global settings updated
        private async void Connection_OnDidReceiveGlobalSettings(object sender, StreamDeckEventReceivedEventArgs <DidReceiveGlobalSettingsEvent> e)
        {
            await instancesLock.WaitAsync();

            try
            {
#if DEBUG
                Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnDidReceiveGlobalSettings: Settings: {e.Event.Payload?.ToStringEx()}");
#endif

                var globalSettings = JObject.FromObject(e.Event.Payload).ToObject <ReceivedGlobalSettingsPayload>();
                foreach (string key in instances.Keys)
                {
                    instances[key].ReceivedGlobalSettings(globalSettings);
                }
            }
            finally
            {
                instancesLock.Release();
            }
        }
Esempio n. 21
0
        // Button pressed
        private async void Connection_OnKeyDown(object sender, StreamDeckEventReceivedEventArgs <KeyDownEvent> e)
        {
            await instancesLock.WaitAsync();

            try
            {
#if DEBUG
                Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin Keydown: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}");
#endif

                if (instances.ContainsKey(e.Event.Context))
                {
                    KeyPayload payload = new KeyPayload(GenerateKeyCoordinates(e.Event.Payload.Coordinates),
                                                        e.Event.Payload.Settings, e.Event.Payload.State, e.Event.Payload.UserDesiredState, e.Event.Payload.IsInMultiAction);
                    instances[e.Event.Context].KeyPressed(payload);
                }
            }
            finally
            {
                instancesLock.Release();
            }
        }
Esempio n. 22
0
        private async void Connection_OnKeyDown(object sender, StreamDeckEventReceivedEventArgs <KeyDownEvent> e)
        {
            if (!this.isMixItUpRunning)
            {
                // If Mix It Up isn't running, just don't try
                return;
            }

            await this.actionsLock.WaitAsync();

            try
            {
                if (this.actions.ContainsKey(e.Event.Context.ToLower()))
                {
                    await this.actions[e.Event.Context.ToLower()].RunActionAsync();
                }
            }
            finally
            {
                this.actionsLock.Release();
            }
        }
Esempio n. 23
0
        private void OnKeyDown(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.KeyDownEvent> e)
        {
            try
            {
                string context = e.Event.Context;

                if (e.Event.Action == PLAY_BUTTON_ID)
                {
                    if (_songs.TryGetValue(context, out string value))
                    {
                        __log.DebugFormat("Play sound: \"{0}\"", value);
                        Client.PlaySong(new PlaySongRequest {
                            FileName = value
                        });
                        __log.DebugFormat("Played sound: \"{0}\"", value);
                    }
                }
            }
            catch (Exception ex)
            {
                __log.Fatal(ex);
            }
        }
Esempio n. 24
0
 private void OnStreamDeckTerminated(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.ApplicationDidTerminateEvent> e)
 {
     __log.DebugFormat("{0}", e.Event.Payload.Application);
     IsRunning = false;
 }
Esempio n. 25
0
 private void Connection_OnDidReceiveGlobalSettings(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.DidReceiveGlobalSettingsEvent> e)
 {
     OnReceivedGlobalSettings?.Invoke(this, JObject.FromObject(e.Event.Payload).ToObject <ReceivedGlobalSettingsPayload>());
 }
Esempio n. 26
0
 private void OnItemAppear(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.WillAppearEvent> e)
 {
     __log.DebugFormat("{0} {1} {2}", e.Event.Device, e.Event.Action, e.Event.Context);
 }
Esempio n. 27
0
 private void OnStreamDeckDeviceConnected(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.DeviceDidConnectEvent> e)
 {
     __log.DebugFormat("{0}", e.Event.Device);
 }
Esempio n. 28
0
 private void OnStreamDeckLaunched(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.ApplicationDidLaunchEvent> e)
 {
     __log.DebugFormat("{0}", e.Event.Payload.Application);
 }