Example #1
0
        private ActionManager RegisterActionInstanceInternal(string instanceKey, BaseStreamDeckAction actionInstance, bool throwIfInstanceIsNull = true)
        {
            this._Logger?.LogTrace($"{nameof(ActionManager)}.{nameof(RegisterActionInstanceInternal)}(string, BaseStreamDeckAction, bool)");

            if (null == actionInstance && (!throwIfInstanceIsNull))
            {
                this._Logger?.LogDebug($"The instance to register with a key of {instanceKey} was null, but prevent raising an exception was specified.");
                return(this);
            }

            if (null == actionInstance && throwIfInstanceIsNull)
            {
                throw new ArgumentNullException($"Could not register an action instance with a key of \"{instanceKey}\"");
            }

            this._Logger?.LogDebug($"Registering an instance of {actionInstance.GetType().FullName} with a key of \"{instanceKey}\".");
            if (this._ActionInstances.ContainsKey(instanceKey))
            {
                throw new DuplicateActionInstanceRegistrationException(instanceKey);
            }

            this._ActionInstances.Add(instanceKey, actionInstance);

            return(this);
        }
        private static void ValidateActionForRegistration(BaseStreamDeckAction action)
        {
            ValidateAction(action);

            if (IsActionRegistered(action.RegistrationKey))
            {
                throw new DuplicateActionRegistrationException(action.UUID);
            }
        }
        private static void ValidateAction(BaseStreamDeckAction action)
        {
            if (null == action)
            {
                throw new ArgumentNullException(nameof(action), "No action instance was given to register.");
            }

            if (string.IsNullOrWhiteSpace(action.RegistrationKey))
            {
                throw new IncompleteActionDefinitionException($"The action of type \"{action}\" does not define a valid UUID.");
            }
        }
Example #4
0
 /// <summary>
 /// Registers the action instance.
 /// </summary>
 /// <returns>The action instance.</returns>
 /// <param name="instanceKey">The key to be used when registering the action instance.
 /// This is typically the value of the <seealso cref="StreamDeckLib.Messages.StreamDeckEventPayload.context"/>.</param>
 /// <param name="actionInstance">Action instance.</param>
 public ActionManager RegisterActionInstance(string instanceKey, BaseStreamDeckAction actionInstance)
 {
     this._Logger?.LogTrace($"{nameof(ActionManager)}.{nameof(RegisterAction)}(string, BaseStreamDeckAction)");
     return(this.RegisterActionInstanceInternal(instanceKey, actionInstance));
 }
        private static ConnectionManager RegisterActionInternal(ConnectionManager manager, BaseStreamDeckAction action)
        {
            // Cheer 100 svavablount 15/2/19

            ValidateActionForRegistration(action);

            action.Manager = manager;
            action.Logger  = _LoggerFactory.CreateLogger(action.UUID);

            try
            {
                _ActionsDictionary.Add(action.RegistrationKey, action);
            } catch (ArgumentException ex) {
                throw new DuplicateActionRegistrationException(action.UUID, ex);
            }

            return(manager);
        }
 public ConnectionManager RegisterAction(BaseStreamDeckAction action) => RegisterActionInternal(this, action);
 public ConnectionManager SetPlugin(BaseStreamDeckAction plugin) => this.RegisterAction(plugin);