private void Application_Startup(object sender, StartupEventArgs e)
 {
     FileProcessor.InitializeAvailableProcessors(Settings.SettingsManager.ProcessorsCodeDirectory);
     var mainWindow = new MainWindow();
     var mainWindowViewModel = new MainWindowViewModel();
     mainWindow.DataContext = mainWindowViewModel;
     mainWindow.Show();
 }
 public static void Crawl(string directoryAbsolutePath, MainWindowViewModel viewModel)
 {
     if(Directory.Exists(directoryAbsolutePath))
     {
         DirectoryInfo di = new DirectoryInfo(directoryAbsolutePath);
         IEnumerable<FileInfo> allFiles = di.EnumerateFiles("*.*", SearchOption.TopDirectoryOnly);
         ProcessFoundedFiles(allFiles, viewModel);
     }
 }
 private static void ProcessFile(FileInfo fi, MainWindowViewModel viewModel)
 {
     IFileDataProcessor dataProcessor = FileProcessor.GetDataProcessor(fi.FullName);
     if (dataProcessor != null)
     {
         IEnumerable<IDataItem> processedItems = dataProcessor.ProcessFile(fi.FullName);
         if (alreadyProcessedData.TryAdd(fi.Name, processedItems))
         {
             UpdateViewModel(viewModel, fi.Name, processedItems.Count());
         }
     }
 }
        private static void ProcessFileList(IEnumerable<FileInfo> filesList, MainWindowViewModel viewModel)
        {
            // Get a cancellation token
            ParallelOptions loopOptions = new ParallelOptions();
            loopOptions.CancellationToken = viewModel.ProcessFileCancellationToken.Token;

            /* If the user cancels this task while in progress, the cancellation token passed
             * in will cause an OperationCanceledException to be thrown. We trap the exception
             * and set the Progress dialog view model to display a cancellation message. */

            // Process work items in parallel
            try
            {
                Parallel.ForEach(filesList, loopOptions, t => ProcessFile(t, viewModel));
            }
            catch (OperationCanceledException)
            {
                //var ShowCancellationMessage = new Action(viewModel.ShowCancellationMessage);
                //Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, ShowCancellationMessage);
            }
        }
 private static void UpdateViewModel(MainWindowViewModel viewModel, string fileName, int processedItemsCount)
 {
     Application.Current.Dispatcher.Invoke(() =>
                        viewModel.UpdateFilesFoundList(fileName), DispatcherPriority.Normal);
     Application.Current.Dispatcher.Invoke(() =>
         viewModel.UpdateFilesCount(), DispatcherPriority.Normal);
     Application.Current.Dispatcher.Invoke(() =>
         viewModel.UpdateTotalProcessedItemsCount(processedItemsCount), DispatcherPriority.Normal);
 }
        private static void ProcessFoundedFiles(IEnumerable<FileInfo> fileList, MainWindowViewModel viewModel)
        {
            Task<IEnumerable<FileInfo>> getOnlyNewFiles = Task<IEnumerable<FileInfo>>.Factory.StartNew(() => GetOnlyNewFiles(fileList));
            viewModel.ProcessFileCancellationToken = new System.Threading.CancellationTokenSource();

            var processFilesList = getOnlyNewFiles.ContinueWith((t) => ProcessFileList(t.Result, viewModel));
        }
 public ScheduleSourceFolderScan(MainWindowViewModel viewModel)
 {
     this.viewModel = viewModel;
 }