private void Connection_OnApplicationDidLaunch(object sender, StreamDeckEventReceivedEventArgs <ApplicationDidLaunchEvent> e) { if (e.Event.Payload.Application.Equals("mixitup.exe", StringComparison.InvariantCultureIgnoreCase)) { this.isMixItUpRunning = true; } }
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; } }
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; } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
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(); } }
// 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(); } }
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); } }
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(); } }
// 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(); } }
// 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(); } }
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(); } }
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); } }
private void OnStreamDeckTerminated(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.ApplicationDidTerminateEvent> e) { __log.DebugFormat("{0}", e.Event.Payload.Application); IsRunning = false; }
private void Connection_OnDidReceiveGlobalSettings(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.DidReceiveGlobalSettingsEvent> e) { OnReceivedGlobalSettings?.Invoke(this, JObject.FromObject(e.Event.Payload).ToObject <ReceivedGlobalSettingsPayload>()); }
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); }
private void OnStreamDeckDeviceConnected(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.DeviceDidConnectEvent> e) { __log.DebugFormat("{0}", e.Event.Device); }
private void OnStreamDeckLaunched(object sender, StreamDeckEventReceivedEventArgs <streamdeck_client_csharp.Events.ApplicationDidLaunchEvent> e) { __log.DebugFormat("{0}", e.Event.Payload.Application); }