示例#1
0
        public MainWindow(IServiceProvider services,
                          IWritableOptions <AppSettings> settings,
                          ILogger <MainWindow> logger,
                          IList <CultureInfo> allCultureInfos,
                          ObservableCollection <PluginStatus> pluginStatus,
                          IFilenameProcessor filenameProcessor)
        {
            InitializeComponent();

            _allCultureInfos = allCultureInfos;
            _logger          = logger;
            _appSettings     = settings.Value;
            _vm = services.GetRequiredService <MainWindowViewModel>();

            _vm.Scheduler = services.GetRequiredService <Scheduler>();
            _vm.Scheduler.SetQueueItemStatusChangeEventHandler(QueueItemStatusChangeEventHandler);

            //_vm.Scheduler = new Scheduler(QueueItemStatusChangeEventHandler);
            //_vm = new MainWindowViewModel(QueueItemStatusChangeEventHandler, filenameProcessor);
            _services            = services;
            _vm.PluginStatusList = pluginStatus;

            // Global failsafe for unhandled exceptions
            Application.Current.DispatcherUnhandledException += new DispatcherUnhandledExceptionEventHandler(Current_DispatcherUnhandledException);

            // Add test items to queue
            Random rand = new Random();

            for (int x = 1; x <= 1; x++)
            {
                _vm.Scheduler.AddItem($"Test #{x}", (item, cancellationToken) =>
                {
                    while (item.ProgressPercentage < 1)
                    {
                        Thread.Sleep(rand.Next(10, 50));

                        if (cancellationToken.IsCancellationRequested)
                        {
                            cancellationToken.ThrowIfCancellationRequested();
                        }

                        item.ProgressPercentage += rand.NextDouble() * (.01 - .0001) + .0001;
                    }

                    item.ProgressPercentage = 1;

                    return(true);
                });
            }

            DataContext = _vm;

            RefreshTVFromPath(_appSettings.RootDirectory);
        }
示例#2
0
        public PreferencesWindow(IWritableOptions <AppSettings> appSettingsOpt,
                                 IList <CultureInfo> allCultureInfos,
                                 ObservableCollection <PluginStatus> pluginStatus,
                                 IFilenameProcessor filenameProcessor)
        {
            InitializeComponent();

            _vm             = new PreferencesViewModel();
            _appSettingsOpt = appSettingsOpt;

            // Settings
            _vm.RootDirectory = _appSettingsOpt.Value.RootDirectory;

            // Language list
            _vm.LanguageList = allCultureInfos;

            // Plugin status
            _vm.PluginList = pluginStatus;

            // Regular expressions
            _vm.RegExList = new ObservableCollection <RegExTVItem>();
            foreach (var expr in _appSettingsOpt.Value.RegExTV)
            {
                _vm.RegExList.Add(new RegExTVItem()
                {
                    Expression = expr
                });
            }

            // Filename processor
            _filenameProcessor = filenameProcessor;

            _vm.SampleText = "In Living Color - S01E01 - Pilot [Unknown] [1990-04-15]";

            DataContext = _vm;
        }