Exemple #1
0
        /// <summary>
        /// Creates new plan, from filter or from collection of items.
        /// </summary>
        private void CreateNewPlan(PlanImportData data)
        {
            var planFilterVM = ViewManager.CreateViewModel <PlanningFilterVM>();
            var defaults     = settings.Get("PlannerDefaultSettings", new PlanningFilter());

            planFilterVM.Title     = Text.Get("Planner.PlanningFilter.CreateNew.Title");
            planFilterVM.Filter    = defaults;
            planFilterVM.JulianDay = sky.Context.JulianDayMidnight;
            planFilterVM.TimeFrom  = TimeSpan.FromHours(22);
            planFilterVM.TimeTo    = TimeSpan.FromHours(0);

            // create filter window with list of celestial objects
            if (data != null && data.Objects.Any())
            {
                planFilterVM.CelestialObjects = data.Objects;
                if (data.Date != null)
                {
                    planFilterVM.JulianDay = new Date(data.Date.Value).ToJulianEphemerisDay();
                }
                if (data.Begin != null)
                {
                    planFilterVM.TimeFrom = data.Begin.Value;
                }
                if (data.End != null)
                {
                    planFilterVM.TimeTo = data.End.Value;
                }
                if (data.FilePath != null)
                {
                    planFilterVM.Title = Text.Get("Planner.PlanningFilter.Import.Title");
                }
            }

            if (ViewManager.ShowDialog(planFilterVM) ?? false)
            {
                var planListVM = ViewManager.CreateViewModel <PlanningListVM>();
                ViewManager.ShowWindow(planListVM);
                planListVM.CreatePlan(planFilterVM.Filter);
                AddActivePlan(planListVM);
                planListVM.Closing += x => RemoveActivePlan(planListVM);
            }
        }
Exemple #2
0
        private async void LoadPlan(string filePath, PlanType fileFormat)
        {
            IPlanManager reader = planManagerFactory.Create(fileFormat);

            PlanImportData plan        = null;
            var            tokenSource = new CancellationTokenSource();
            var            progress    = new Progress <double>();

            ViewManager.ShowProgress("$Planner.Importing.WaitTitle", "$Planner.Importing.WaitText", tokenSource, progress);

            try
            {
                plan = await Task.Run(() => reader.Read(filePath, tokenSource.Token, progress));
            }
            catch (Exception ex)
            {
                tokenSource.Cancel();
                recentPlansManager.RemoveFromRecentList(new RecentPlan(filePath, fileFormat));
                Log.Error($"Unable to import observation plan: {ex}");
                ViewManager.ShowMessageBox("$Error", $"{Text.Get("Planner.Importing.Error")}: {ex.Message}");
            }

            if (!tokenSource.IsCancellationRequested)
            {
                tokenSource.Cancel();
                if (plan?.Objects.Any() == true)
                {
                    CreateNewPlan(plan);
                    recentPlansManager.AddToRecentList(new RecentPlan(filePath, fileFormat));
                }
                else if (ViewManager.ShowMessageBox("$Warning", Text.Get("Planner.Importing.NoCelestialObjectImported"), System.Windows.MessageBoxButton.YesNo) == System.Windows.MessageBoxResult.Yes)
                {
                    CreateNewPlan(null);
                }
            }
        }