Beispiel #1
0
        public CommandsManager(IEnumerable <IRemoteCommand> commands, ICommandsSettings commandsSettings)
        {
            _commandsSettings = commandsSettings;
            IEnumerable <IRemoteCommand> remoteCommands = commands as IRemoteCommand[] ?? commands.ToArray();
            List <IRemoteCommand>        clonedCommands = new List <IRemoteCommand>();

            foreach (IRemoteCommand command in remoteCommands)
            {
                Guid[] ids = commandsSettings.GetCommandIds(command.GetType());
                if (ids != null)
                {
                    foreach (Guid id in ids)
                    {
                        if (id != command.Id)
                        {
                            clonedCommands.Add(command.Create(id));
                        }
                    }
                }
            }
            _commands = new List <IRemoteCommand>(remoteCommands);
            _commands.AddRange(clonedCommands);
        }
        public ControllerApplicationContext(SettingsForm.Factory settingsFormFactory, HostHelper.Factory hostHelperFactory, ICommandsSettings commandsSettings, CommandsManager.Factory commandManagerFactory)
        {
            var catalog = new AggregateCatalog();

            var files = Directory.GetFiles($@"{Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)}\Plugins", "*.dll", SearchOption.AllDirectories);

            foreach (var dllFilePath in files)
            {
                var assembly        = Assembly.LoadFrom(Path.GetFullPath(dllFilePath));
                var assemblyCatalog = new AssemblyCatalog(assembly);
                catalog.Catalogs.Add(assemblyCatalog);
            }

            var container = new CompositionContainer(catalog);

            var commands = new List <IRemoteCommand>(container.GetExportedValues <IRemoteCommand>());

            commands.AddRange(container.GetExportedValues <IRemoteCommandContainer>().SelectMany(c => c));
            _commandsManager = commandManagerFactory.Invoke(commands, commandsSettings);
            _settingsForm    = settingsFormFactory.Invoke(_commandsManager);
            _hostHelper      = hostHelperFactory.Invoke(_commandsManager);

            // Initialize Tray Icon
            _trayIcon = new NotifyIcon
            {
                Icon             = Resources.AppIcon,
                ContextMenuStrip = GetContextMenuStrip(),
                Visible          = true
            };

            _hostHelper.SecretCode = Settings.Default.SecretCode;
            _hostHelper.CreateHostAsync(Settings.Default.RemotePort);
        }