public ConnectionManager(IOptions <StreamDeckToolkitOptions> options, ActionManager actionManager, ILogger <ConnectionManager> logger, IStreamDeckProxy streamDeckProxy = null)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options", "Options cannot be null, these should be retrieved from commandline args.");
            }
            if (actionManager == null)
            {
                throw new ArgumentNullException("actionManager", "ActionManager cannot be null, these should be retrieved from commandline args.");
            }

            _ActionManager = actionManager;
            _logger        = logger;

            if (options.Value != null)
            {
                if (!string.IsNullOrEmpty(options.Value.Info))
                {
                    var myInfo = JsonConvert.DeserializeObject <Info>(options.Value.Info);
                    Info = myInfo;
                }
                _port          = options.Value.Port;
                _uuid          = options.Value.PluginUUID;
                _registerEvent = options.Value.RegisterEvent;
            }
            _proxy = streamDeckProxy ?? new StreamDeckProxy();
        }
        private ConnectionManager(StreamDeckToolkitOptions options, ILoggerFactory loggerFactory = null, IStreamDeckProxy streamDeckProxy = null) : this()
        {
            var myInfo = JsonConvert.DeserializeObject <Info>(options.Info);

            Info           = myInfo;
            _port          = options.Port;
            _uuid          = options.PluginUUID;
            _registerEvent = options.RegisterEvent;
            _proxy         = streamDeckProxy ?? new StreamDeckProxy();

            _LoggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
            _logger        = loggerFactory?.CreateLogger <ConnectionManager>();
        }
        //CHANGED
        private ConnectionManager(StreamDeckToolkitOptions options, ILoggerFactory loggerFactory = null, IActionController actionController = null, IStreamDeckProxy streamDeckProxy = null) : this()
        {
            if (actionController == null)
            {
                throw new ArgumentNullException("actionManager", "ActionManager cannot be null, these should be retrieved from commandline args."); //CHANGED
            }
            _ActionController             = actionController;                                                                                       //CHANGED
            _ActionController.DeckManager = this;

            var myInfo = JsonConvert.DeserializeObject <Info>(options.Info);

            Info           = myInfo;
            _port          = options.Port;
            _uuid          = options.PluginUUID;
            _registerEvent = options.RegisterEvent;
            _proxy         = streamDeckProxy ?? new StreamDeckProxy();

            _LoggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
            _logger        = loggerFactory?.CreateLogger <ConnectionManager>();
        }
        private static ConnectionManager Initialize(int port, string uuid,
                                                    string registerEvent, string info,
                                                    ILoggerFactory loggerFactory, IStreamDeckProxy streamDeckProxy)
        {
            // TODO: Validate the info parameter
            var myInfo = JsonConvert.DeserializeObject <Messages.Info>(info);

            _LoggerFactory = loggerFactory ?? NullLoggerFactory.Instance;
            _Logger        = loggerFactory?.CreateLogger("ConnectionManager") ?? NullLogger.Instance;

            var manager = new ConnectionManager()
            {
                _Port          = port,
                _Uuid          = uuid,
                _RegisterEvent = registerEvent,
                Info           = myInfo,
                _Proxy         = streamDeckProxy
            };

            return(manager);
        }
Exemple #5
0
        public static ConnectionManager Initialize(string[] commandLineArgs,
                                                   ILoggerFactory loggerFactory     = null,
                                                   IStreamDeckProxy streamDeckProxy = null)
        {
            using (var app = new CommandLineApplication())
            {
                app.HelpOption();

                var optionPort = app.Option <int>("-port|--port <PORT>",
                                                  "The port the Elgato StreamDeck software is listening on",
                                                  CommandOptionType.SingleValue);

                var optionPluginUUID = app.Option("-pluginUUID <UUID>",
                                                  "The UUID that the Elgato StreamDeck software knows this plugin as.",
                                                  CommandOptionType.SingleValue);

                var optionRegisterEvent = app.Option("-registerEvent <REGEVENT>", "The registration event",
                                                     CommandOptionType.SingleValue);

                var optionInfo = app.Option("-info <INFO>", "Some information", CommandOptionType.SingleValue);

                var optionBreak = app.Option("-break", "Attach the debugger", CommandOptionType.NoValue);

                app.Parse(commandLineArgs);

                try
                {
                    return(Initialize(optionPort.ParsedValue, optionPluginUUID.Values[0], optionRegisterEvent.Values[0],
                                      optionInfo.Values[0], loggerFactory,
                                      streamDeckProxy ?? new StreamDeckProxy()));
                }
                catch
                {
                    throw new ArgumentException($"{nameof(commandLineArgs)} must be the commandline args that the StreamDeck application calls this program with.");
                }
            }
        }
 public static ConnectionManager Initialize(string[] commandLineArgs, ILoggerFactory loggerFactory = null, IStreamDeckProxy streamDeckProxy = null)
 {
     try
     {
         var options = ParseCommandlineArgs(commandLineArgs);
         return(new ConnectionManager(options, loggerFactory, streamDeckProxy));
     }
     catch
     {
         throw new ArgumentException($"{nameof(commandLineArgs)} must be the commandline args that the StreamDeck application calls this program with.");
     }
 }