/// <summary>
        /// check if viewport data is available
        /// calculate conflicts with the models currently in Combined set and report the first one
        /// </summary>
        /// <param name="model"></param>
        private void CalculateStatus(ViewportSetupFileViewModel model)
        {
            if (!model.Data.Exists)
            {
                // the local profile may not have data yet, but that is ok.  for any merged profiles, we need the data
                if (!model.IsCurrentProfile)
                {
                    model.Status = ViewportSetupFileStatus.NotGenerated;
                    model.ProblemShortDescription = "needs configuration";
                    model.ProblemNarrative        =
                        $"DCS Monitor Setup has to be configured in profile '{model.ProfileName}' before it can be combined";
                    return;
                }
            }
            else
            {
                // check compatibility
                if (model.Data.MonitorLayoutKey != Data.MonitorLayoutKey)
                {
                    model.Status = ViewportSetupFileStatus.OutOfDate;
                    model.ProblemShortDescription = "needs configuration for new monitor layout";
                    model.ProblemNarrative        =
                        $"DCS Monitor Setup should be configured in profile '{model.ProfileName}' to adjust to the current monitor layout";
                    return;
                }

                // search for conflicts
                foreach (KeyValuePair <string, Rect> viewport in model.Data.Viewports)
                {
                    foreach (ViewportSetupFileViewModel existing in Combined)
                    {
                        if (existing.Data == null)
                        {
                            continue;
                        }

                        if (!existing.Data.Viewports.TryGetValue(viewport.Key, out Rect existingRect))
                        {
                            continue;
                        }

                        if (existingRect.Equals(viewport.Value))
                        {
                            continue;
                        }

                        model.Status = ViewportSetupFileStatus.Conflict;
                        model.ProblemShortDescription = $"conflicts with {existing.ProfileName}";
                        model.ProblemNarrative        =
                            $"profile '{existing.ProfileName}' defines the viewport '{viewport.Key}' at a different screen location";
                        return;
                    }
                }
            }

            // none found, we are good
            model.Status = ViewportSetupFileStatus.OK;
            model.ProblemShortDescription = null;
            model.ProblemNarrative        = null;
        }
Example #2
0
        private IEnumerable <StatusReportItem> GatherWarnings(ViewportSetupFileViewModel model)
        {
            switch (model.Status)
            {
            case ViewportSetupFileStatus.OK:
                break;

            case ViewportSetupFileStatus.Unknown:
            case ViewportSetupFileStatus.NotGenerated:
                yield return(new StatusReportItem
                {
                    Status =
                        $"Viewport information for profile '{model.ProfileName}' will not be included because it is not available.",
                    Severity = StatusReportItem.SeverityCode.Warning
                });

                break;

            case ViewportSetupFileStatus.Conflict:
                if (!Data.GenerateCombined)
                {
                    // conflict does not matter if we have a separate file
                    break;
                }

                yield return(new StatusReportItem
                {
                    Status =
                        $"At least one viewports for profile '{model.ProfileName}' conflicts with other viewports in the combined monitor setup:",
                    Severity = StatusReportItem.SeverityCode.Warning,
                    Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate
                });

                yield return(new StatusReportItem
                {
                    Status = $"{model.ProblemNarrative}.",
                    Severity = StatusReportItem.SeverityCode.Warning,
                    Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate
                });

                break;

            case ViewportSetupFileStatus.OutOfDate:
                yield return(new StatusReportItem
                {
                    Status =
                        $"Viewports for profile '{model.ProfileName}' may be in the wrong location because the saved information is out of date.",
                    Severity = StatusReportItem.SeverityCode.Warning
                });

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
        private void Exclude(ViewportSetupFileViewModel model)
        {
            Combined.Remove(model);
            Data.Combined.SetExcluded(model.ProfileName);
            if (model == CurrentViewportSetup)
            {
                using (new HeliosUndoBatch())
                {
                    Data.GenerateCombined = false;
                    ConfigManager.UndoManager.AddUndoItem(new UndoExclude(this, model));
                }
            }

            AddExcluded(model);
            Data.InvalidateStatusReport();
        }
        /// <summary>
        /// called when the current profile has been saved under a different name
        /// </summary>
        private void HandleProfileNameChange()
        {
            string oldName = CurrentViewportSetup.ProfileName;
            string newName = Data.CurrentProfileName;

            Debug.Assert(oldName != newName);

            ResetCurrentMonitorSetupSelection();
            ViewportSetupFileViewModel model = Combined.FirstOrDefault(m => m.ProfileName == newName);

            if (model != null)
            {
                ConfigureCurrentProfile(model);

                // after fixups, check if in the correct list
                if (Data.Combined.IsCombined(model.ProfileName))
                {
                    return;
                }

                Combined.Remove(model);
                AddExcluded(model);
                return;
            }

            model = Excluded.FirstOrDefault(m => m.ProfileName == newName);
            if (model != null)
            {
                ConfigureCurrentProfile(model);

                // after fixups, check if in the correct list
                if (!Data.Combined.IsCombined(model.ProfileName))
                {
                    return;
                }

                Excluded.Remove(model);
                AddCombined(model);
                return;
            }

            // not found
            AddCurrentProfile();
        }
 private void AddCurrentProfile()
 {
     // create new item
     CurrentViewportSetup =
         new ViewportSetupFileViewModel(Data.CurrentProfileName, Data.Combined.Load(Data.CurrentProfileName))
     {
         IsCurrentProfile = true
     };
     if (Data.GenerateCombined)
     {
         Data.Combined.SetCombined(Data.CurrentProfileName);
         AddCombined(CurrentViewportSetup);
     }
     else
     {
         Data.Combined.SetExcluded(Data.CurrentProfileName);
         AddExcluded(CurrentViewportSetup);
     }
 }
        private void ConfigureCurrentProfile(ViewportSetupFileViewModel model)
        {
            model.IsCurrentProfile = true;
            CurrentViewportSetup   = model;

            // now fix up inconsistencies
            if (Data.Combined.IsCombined(model.ProfileName) == Data.GenerateCombined)
            {
                return;
            }

            if (Data.GenerateCombined)
            {
                Data.Combined.SetCombined(model.ProfileName);
            }
            else
            {
                Data.Combined.SetExcluded(model.ProfileName);
            }
        }
        public CombinedMonitorSetupViewModel(MonitorSetup data) : base(data)
        {
            Combined = new ObservableCollection <ViewportSetupFileViewModel>();
            Excluded = new ObservableCollection <ViewportSetupFileViewModel>();

            bool found = false;

            foreach (string name in Data.Combined.KnownViewportSetupNames)
            {
                ViewportSetupFileViewModel model = new ViewportSetupFileViewModel(name, Data.Combined.Load(name));
                if (model.ProfileName == Data.CurrentProfileName)
                {
                    found = true;
                    ConfigureCurrentProfile(model);
                }

                if (Data.Combined.IsCombined(model.ProfileName))
                {
                    AddCombined(model);
                }
                else
                {
                    AddExcluded(model);
                }
            }

            // add ourselves at the end of the appropriate list, if not already there
            if (!found)
            {
                AddCurrentProfile();
            }

            // register for changes
            Data.PropertyChanged  += Data_PropertyChanged;
            Data.UpdatedViewports += Data_UpdatedViewports;
        }
 private void AddCombined(ViewportSetupFileViewModel model)
 {
     Combined.Add(model);
     CalculateStatus();
 }
 private void AddExcluded(ViewportSetupFileViewModel model)
 {
     Excluded.Add(model);
     CalculateStatus();
 }
 private void Delete(ViewportSetupFileViewModel model)
 {
     Data.Combined.Delete(model.ProfileName);
     Excluded.Remove(model);
     Data.InvalidateStatusReport();
 }