예제 #1
0
        /// <summary>
        /// Обработка события выбора нового сценария из списка ранее открытых
        /// </summary>
        /// <param name="newScenario">Выбираемый сценарий</param>
        /// <returns>Возвращает значение, которое определяет можно ли продолжать открытие выбираемого сценария</returns>
        private async Task <bool> NewScenatioItemOnSelecting(ScenarioItem newScenario)
        {
            string key = newScenario.ScenarioInfo.Key;

            if (key.Equals(mFileName))
            {
                Scenarios.Where(s => !s.ScenarioInfo.Key.Equals(key)).ToList().ForEach(s => s.UnselecteItem());
                return(await TaskExtension.FromResult(true));
            }
            if (await CheckLoadParameter(this, key, true))
            {
                Scenarios.ToList().ForEach(s => s.UnselecteItem());
                return(await TaskExtension.FromResult(true));
            }
            return(await TaskExtension.FromResult(false));
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 /// <summary>
 /// Обработка события выбора нового сценария из списка ранее открытых
 /// </summary>
 /// <param name="newScenario">Выбираемый сценарий</param>
 /// <returns>Возвращает значение, которое определяет можно ли продолжать открытие выбираемого сценария</returns>
 private async Task<bool> NewScenatioItemOnSelecting(ScenarioItem newScenario)
 {
     string key = newScenario.ScenarioInfo.Key;
     if (key.Equals(mFileName))
     {
         Scenarios.Where(s => !s.ScenarioInfo.Key.Equals(key)).ToList().ForEach(s => s.UnselecteItem());
         return await TaskExtension.FromResult(true);
     }
     if (await CheckLoadParameter(this, key, true))
     {
         Scenarios.ToList().ForEach(s => s.UnselecteItem());
         return await TaskExtension.FromResult(true);
     }
     return await TaskExtension.FromResult(false);
 }
예제 #4
0
        /// <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);
        }