コード例 #1
0
        private async Task ImportAsync <TProblemData, TImportType>(DataAnalysisInstanceProvider <TProblemData, TImportType> instanceProvider, DataAnalysisImportDialog importDialog,
                                                                   Func <DataAnalysisImportDialog, TImportType> getImportType)
            where TProblemData : class, IDataAnalysisProblemData
            where TImportType : DataAnalysisImportType
        {
            if (importDialog.ShowDialog() == DialogResult.OK)
            {
                await Task.Run(() => {
                    TProblemData instance;
                    // lock active view and show progress bar

                    try {
                        var progress = Progress.Show(Content, "Loading problem instance.");
                        instanceProvider.ProgressChanged += (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; };

                        instance = instanceProvider.ImportData(importDialog.Path, getImportType(importDialog), importDialog.CSVFormat);
                    } catch (IOException ex) {
                        MessageBox.Show(string.Format("There was an error parsing the file: {0}", Environment.NewLine + ex.Message), "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        Progress.Hide(Content);
                        return;
                    }
                    try {
                        Content.Import(instance);
                    } catch (IOException ex) {
                        MessageBox.Show(string.Format("This problem does not support loading the instance {0}: {1}", Path.GetFileName(importDialog.Path), Environment.NewLine + ex.Message), "Cannot load instance");
                    } finally {
                        Progress.Hide(Content);
                    }
                });
            }
        }
コード例 #2
0
        private void Import <TProblemData, TImportType>(DataAnalysisInstanceProvider <TProblemData, TImportType> instanceProvider, DataAnalysisImportTypeDialog importTypeDialog,
                                                        Func <DataAnalysisImportTypeDialog, TImportType> getImportType)
            where TProblemData : class, IDataAnalysisProblemData
            where TImportType : DataAnalysisImportType
        {
            if (importTypeDialog.ShowDialog() == DialogResult.OK)
            {
                Task.Run(() => {
                    TProblemData instance;
                    var mainForm = (MainForm.WindowsForms.MainForm)MainFormManager.MainForm;
                    // lock active view and show progress bar
                    var activeView = (IContentView)MainFormManager.MainForm.ActiveView;

                    try {
                        var progress = mainForm.AddOperationProgressToContent(activeView.Content, "Loading problem instance.");

                        instanceProvider.ProgressChanged += (o, args) => { progress.ProgressValue = args.ProgressPercentage / 100.0; };

                        instance = instanceProvider.ImportData(importTypeDialog.Path, getImportType(importTypeDialog), importTypeDialog.CSVFormat);
                    } catch (IOException ex) {
                        MessageBox.Show(string.Format("There was an error parsing the file: {0}", Environment.NewLine + ex.Message), "Error while parsing", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        mainForm.RemoveOperationProgressFromContent(activeView.Content);
                        return;
                    }
                    try {
                        Content.Import(instance);
                    } catch (IOException ex) {
                        MessageBox.Show(string.Format("This problem does not support loading the instance {0}: {1}", Path.GetFileName(importTypeDialog.Path), Environment.NewLine + ex.Message), "Cannot load instance");
                    } finally {
                        mainForm.RemoveOperationProgressFromContent(activeView.Content);
                    }
                });
            }
        }