Exemple #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            if (_pluginInfos != null)
            {
                return;
            }

            Task.Factory.StartNew(() =>
            {
                try
                {
                    using (var progress = _progressFactory.NewInstance("Loading plugins..."))
                    {
                        _pluginInfos = PluginLoader.LoadPlugins(progress);

                        this.InvokeIfRequired(RefreshUI);
                    }
                }
                catch (OperationCanceledException)
                {
                    this.InvokeIfRequired(RefreshUI);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error");
                }
            }, TaskCreationOptions.LongRunning);
        }
        private void GenerateData_GenerateDataButton_Click(object sender, EventArgs e)
        {
            var generationInfoValidationResult = _generationInfo.Validate();

            if (generationInfoValidationResult != ValidationResult.Success)
            {
                MessageBox.Show(
                    string.Join(" ", generationInfoValidationResult.Errors.Select(x => x.ErrorMessage)),
                    "Error");

                return;
            }

            if (!_project.HasMeaningEmbeddings &&
                _generationInfo.FeatureGroups
                .Any(x => x.Elements
                     .Any(y => y is MeaningEmbeddingElement)))
            {
                MessageBox.Show(
                    "Current project does not include meaning embeddings. " +
                    "Please remove all MeaningEmbedding elements or load a different project.",
                    "Error");

                return;
            }

            using (var dialog = DialogEx.SelectFolder())
            {
                var result = dialog.ShowDialog();

                if (result == CommonFileDialogResult.Ok)
                {
                    _generationInfo.DestinationFolder = dialog.FileName;

                    if (Directory.GetFiles(dialog.FileName, "*", SearchOption.AllDirectories).Length > 0)
                    {
                        MessageBox.Show("Directory must be empty.", "Error");

                        return;
                    }

                    Task.Factory.StartNew(() =>
                    {
                        try
                        {
                            using (var progress = _progressFactory.NewInstance("Generating data..."))
                            {
                                new DataGenerator(_pluginComponents)
                                .Generate(_project, _generationInfo, progress);

                                this.InvokeIfRequired(() => RefreshUI());
                            }

                            if (Directory.Exists(dialog.FileName))
                            {
                                Process.Start(dialog.FileName);
                            }
                        }
                        catch (OperationCanceledException)
                        {
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString(), "Error");
                        }
                    }, TaskCreationOptions.LongRunning);
                }
            }
        }