Ejemplo n.º 1
0
        // 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 DEBUG
                Logger.Instance.LogMessage(TracingLevel.DEBUG, $"Plugin OnWillAppear: Context: {e.Event.Context} Action: {e.Event.Action} Payload: {e.Event.Payload?.ToStringEx()}");
#endif

                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();
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Constructor for PluginBase. Receives the communication and plugin settings
 /// Note that the settings object is not used by the base and should be consumed by the deriving class.
 /// Usually, a private class inside the deriving class is created which stores the settings
 /// Example for settings usage:
 /// * if (payload.Settings == null || payload.Settings.Count == 0)
 /// * {
 /// *         // Create default settings
 /// * }
 /// * else
 /// * {
 ///     this.settings = payload.Settings.ToObject();
 /// * }
 ///
 /// </summary>
 /// <param name="connection">Communication module with Stream Deck</param>
 /// <param name="payload">Plugin settings - NOTE: Not used in base class, should be consumed by deriving class</param>
 public PluginBase(SDConnection connection, InitialPayload payload)
 {
     Connection = connection;
 }
        /// <summary>
        /// Constructor for PluginBase. Receives the communication and plugin settings
        /// Note that the settings object is not used by the base and should be consumed by the deriving class.
        /// Usually, a private class inside the deriving class is created which stores the settings
        /// Example for settings usage:
        /// * if (payload.Settings == null || payload.Settings.Count == 0)
        /// * {
        /// *         // Create default settings
        /// * }
        /// * else
        /// * {
        ///     this.settings = payload.Settings.ToObject();
        /// * }
        ///
        /// </summary>
        /// <param name="connection">Communication module with Stream Deck</param>
        /// <param name="payload">Plugin settings - NOTE: Not used in base class, should be consumed by deriving class</param>
#pragma warning disable IDE0060 // Remove unused parameter
        public PluginBase(SDConnection connection, InitialPayload payload)
#pragma warning restore IDE0060 // Remove unused parameter
        {
            Connection = connection;
        }