예제 #1
0
        /// <summary>
        /// Асинхронная смена сценария
        /// </summary>
        /// <returns></returns>
        private async Task ChangeScenarioAsync(string fileName, bool isQuickLoad)
        {
            if (isQuickLoad)
            {
                mFileName = fileName;
                await ProgressDialogService.ExecuteAsync(LoadAsync).ConfigureAwait(false);
            }
            else
            {
                await TaskExtension.Delay(1).ConfigureAwait(false);

                var dialog = new OpenFileDialog {
                    Filter = "Файл с описанием сценария (xmlinfo)|*.xmlinfo"
                };
                if (!string.IsNullOrEmpty(DataHolder.Instance.FullFolderPath))
                {
                    dialog.InitialDirectory = DataHolder.Instance.FullFolderPath;
                    dialog.FileName         = Path.Combine(DataHolder.Instance.FullFolderPath, Constants.cScenarioDescriptor);
                }

                if (dialog.ShowDialog() == true)
                {
                    mFileName = dialog.FileName;
                    await ProgressDialogService.ExecuteAsync(LoadAsync).ConfigureAwait(false);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Асинхронное сохранение сценария
        /// </summary>
        /// <returns></returns>
        private async Task SaveScenarioHandlerAsync(object param)
        {
            if (IndicatorSave.IsEqual(Indicators.Accept.GetColor()))
            {
                if (!DataHolder.Instance.SlideDataHolders.Any(x => (x as ISaveValidator).With(valid => valid.OwnScenarioTypes.Contains(DataHolder.Instance.ScenarioProperties.ScenarioType) && !valid.IsValid)))
                {
                    var dialog = new FolderBrowserDialog
                    {
                        SelectedPath = DataHolder.Instance.FullFolderPath
                    };
                    if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        await DataHolder.Instance.ReleaseMedia(true, null, new CancellationToken());

                        string directoryName = dialog.SelectedPath;
                        IEnumerable <string> scenarioInfos = Directory.GetFiles(directoryName)
                                                             .ToList()
                                                             .Where(x => x.Contains(".xmlinfo"))
                                                             .Select(Path.GetFileName)
                                                             .ToList();
                        if (!scenarioInfos.Any())
                        {
                            await ProgressDialogService.ExecuteAsync((cancellation, progress) => UploadScenarioAsync(dialog.SelectedPath, cancellation, progress)).ConfigureAwait(false);
                        }
                        else if (scenarioInfos.Any(x => x == Constants.cScenarioDescriptor))
                        {
                            switch (MessageBox.Show(Application.Current.MainWindow, Constants.cInsureRewriteScenario, "Сохранение сценария", MessageBoxButton.YesNo))
                            {
                            case MessageBoxResult.Yes:
                                await ProgressDialogService.ExecuteAsync(async (cancellation, progress) => await UploadScenarioAsync(dialog.SelectedPath, cancellation, progress)).ConfigureAwait(false);

                                break;

                            case MessageBoxResult.No:
                                await TaskExtension.Delay(1);

                                return;
                            }
                        }
                        else
                        {
                            await ProgressDialogService.ExecuteAsync((cancellation, progress) => UploadScenarioAsync(dialog.SelectedPath, cancellation, progress)).ConfigureAwait(false);
                        }
                    }
                }
                else
                {
                    MessageBox.Show(string.Format("Данный Сценарий нельзя сохранить. Проверьте правильность запонения следующих вкладок для корректного сохранения \n{0}",
                                                  DataHolder.Instance.SlideDataHolders.Where(x => (x as ISaveValidator).With(valid => valid.OwnScenarioTypes.Contains(DataHolder.Instance.ScenarioProperties.ScenarioType) && !valid.IsValid)).Select(x => x.Name).EnumerableToString("{0}\n")), Constants.cScenarioEditorTitle,
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            else
            {
                throw new NotImplementedException("ScenarioEditor.ViewModel.ViewModels.StartPageViewModelsSaveScenarioHandlerAsync");
            }

            await TaskExtension.Delay(1);

            CommandManager.InvalidateRequerySuggested();
        }