/// <summary> /// Асинхронная загрузка сценария /// </summary> /// <param name="cancellation"></param> /// <param name="progress"></param> /// <returns></returns> private async Task LoadAsync(CancellationToken cancellation, IProgress <string> progress) { await await Task.Factory.StartNew(async() => { await DataHolder.Instance.ReleaseMedia(false, progress, cancellation); progress.Report("Загрузка данных"); Thread.Sleep(3000); if (DataHolder.Instance.LoadAllData(mFileName, progress, cancellation)) { Debug.Assert(Path.GetDirectoryName(mFileName) != null, "Path.GetDirectoryName(mFileName) != null"); } else { while (true) { if (cancellation.IsCancellationRequested) { break; } Thread.Sleep(100); } } if (cancellation.IsCancellationRequested) { await DataHolder.Instance.ClearAllData(); return(TaskExtension.Delay(1)); } DispatcherServices.BeginInvoke(() => { DynamicText = Constants.cChangeScenarioText; IndicatorLoad = Indicators.Warn.GetColor(); IndicatorCreate = Indicators.Warn.GetColor(); IndicatorSave = Indicators.Accept.GetColor(); ScenarioItem loadedScenario = Scenarios.FirstOrDefault(s => s.ScenarioInfo.Key.Equals(mFileName)); if (loadedScenario == null) { loadedScenario = new ScenarioItem(new KeyValuePair <string, string>(mFileName, DataHolder.Instance.ScenarioProperties.ScenarioName)); loadedScenario.Selecting += NewScenatioItemOnSelecting; Scenarios.Add(loadedScenario); } loadedScenario.SelecteItem(); }); return(TaskExtension.Delay(1)); }, cancellation).ConfigureAwait(false); }
/// <summary> /// Асинхронная выгрузка сценария /// </summary> /// <param name="path">путь к выгрузки</param> /// <param name="cancellation"></param> /// <param name="progress"></param> /// <param name="rewrite">True-перезаписать старые данные</param> /// <returns></returns> private async Task UploadScenarioAsync(string path, CancellationToken cancellation, IProgress <string> progress, bool rewrite = true) { await Task.Factory.StartNew(async() => { progress.Report("Сохранение сценария"); Thread.SpinWait(1000); DataHolder.Instance.TargetDirectory = path; if (rewrite) { progress.Report("Очистка старых данных"); DataHolder.Instance.PrepareForRewriteScenario(); } if (!DataHolder.Instance.UpLoadData(path, progress, cancellation)) { // DataHolder.Instance.ScenarioProperties.Folder = Path.GetDirectoryName(mFileName); //else while (true) { if (cancellation.IsCancellationRequested) { break; } Thread.Sleep(100); } } if (cancellation.IsCancellationRequested) { await DataHolder.Instance.ClearAllData(); return(TaskExtension.Delay(1)); } DispatcherServices.BeginInvoke(() => { DynamicText = Constants.cChangeScenarioText; IndicatorLoad = Indicators.Warn.GetColor(); IndicatorCreate = Indicators.Warn.GetColor(); IndicatorSave = Indicators.Accept.GetColor(); }); return(TaskExtension.Delay(1)); }, cancellation).Unwrap().ConfigureAwait(false); }