Ejemplo n.º 1
0
        private async void OpenFiles(object sender, RoutedEventArgs e)
        {
            OpenFileDialog openFileDialog = new OpenFileDialog
            {
                // Set the file dialog to filter for graphics files.
                Filter = "Text|*.txt|All|*.*",
                // Allow the user to select multiple images.
                Multiselect = true,
                Title       = "Select your TimeFrame Files..."
            };

            if (openFileDialog.ShowDialog() == true)
            {
                Task Preparation = Task.Run(() =>
                {
                    InputFile.AddFilesToList(openFileDialog);

                    foreach (InputFile file in Globals.GetFiles())
                    {
                        try
                        {
                            if (!file.Prepared)
                            {
                                file.PrepareFile();
                            }
                        }
                        catch (Exception ex)
                        {
                            file.Invalid = true;
                            if (MessageBox.Show(ex.Message + "\nError occured. Would you like to process all remaining files?", "Error occured!", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                            {
                                return;
                            }
                        }
                    }
                });

                await Preparation;

                Task Cleanup = Task.Run(() =>
                {
                    Globals.GetFiles().RemoveAll(file => file.Invalid == true);
                });

                await Cleanup;

                if (Globals.GetFiles().Count != 0)
                {
                    StatusBarLabel.Text = "Prepared all remaining files";
                }
                else
                {
                    StatusBarLabel.Text = "No files to process";
                }

                if (Globals.GetFiles().Count > 0)
                {
                    ClearButton.IsEnabled     = true;
                    CalculateButton.IsEnabled = true;
                }

                RefreshFilesDataGrid();
            }
        }