Exemplo n.º 1
0
 public SessionHandler(ICommandLoader commandLoader)
 {
     CommandLoader       = commandLoader;
     Sessions            = CommandLoader.GetCommands();
     EventCommands       = Sessions.ToDictionary(x => x.Name, x => x);
     UsersActiveSessions = new Dictionary <long, BaseBotSession>();
     UsersCommand        = new Dictionary <long, Dictionary <string, BaseBotSession> >();
 }
Exemplo n.º 2
0
        public MainWindow(ISettingsLoader settingsLoader, ISettingsSaver settingsSaver, ICommandLoader commandLoader,
                          IProgramListLoader programListLoader)
        {
            if (settingsLoader == null)
            {
                throw new ArgumentNullException(nameof(settingsLoader));
            }
            if (commandLoader == null)
            {
                throw new ArgumentNullException(nameof(commandLoader));
            }
            if (programListLoader == null)
            {
                throw new ArgumentNullException(nameof(programListLoader));
            }
            _settingsSaver = settingsSaver ?? throw new ArgumentNullException(nameof(settingsSaver));

            _validCommands    = new Dictionary <string, Command>(StringComparer.CurrentCultureIgnoreCase);
            _autocompleteList = new List <string>();
            _programPaths     = new Dictionary <string, string>(StringComparer.CurrentCultureIgnoreCase);
            //_programList = new List<string>();

            InitializeComponent();
            Activated           += CommandTb_GotFocus;
            Deactivated         += CommandTb_LostFocus;
            CommandTb.GotFocus  += CommandTb_GotFocus;
            CommandTb.LostFocus += CommandTb_LostFocus;

            try
            {
                _fUiSettings = settingsLoader.LoadSettings();
            }
            catch (SettingsLoadException e)
            {
                MessageBox.Show(
                    "Couldn't load the config/settings.json file, is it valid JSON? Re-download it or fix any JSON formatting errors.\nException: " +
                    e.BuildException());
                Application.Current.Shutdown();
            }

            foreach (var toAdd in commandLoader.GetCommands(_fUiSettings))
            {
                try
                {
                    _validCommands.Add(toAdd.Name, toAdd);
                    _autocompleteList.Add(toAdd.Name);
                }
                catch (CommandLoadException e)
                {
                    MessageBox.Show("Unable to load command.\nException is: " + e.BuildException());
                    CommandError();
                }
            }

            foreach (var cmd in _fUiSettings.Commands)
            {
                _validCommands.Add(cmd.Name, cmd);
                _autocompleteList.Add(cmd.Name);
            }

            foreach (var program in programListLoader.GetProgramList())
            {
                _programPaths[Path.GetFileNameWithoutExtension(program).Trim()] = program;
                _autocompleteList.Add(Path.GetFileNameWithoutExtension(program).Trim());
            }
        }