internal void Save(string viewportSetupName, ViewportSetupFile data) { string path = LocateFile(viewportSetupName); string contents = JsonConvert.SerializeObject(data); File.WriteAllText(path, contents); }
private IEnumerable <StatusReportItem> GatherViewports(MonitorSetupTemplate template) { foreach (StatusReportItem item in UpdateLocalViewports(template)) { yield return(item); } if (!template.Combined) { _allViewports = _localViewports; } else { _allViewports = new ViewportSetupFile { MonitorLayoutKey = _parent.MonitorLayoutKey }; foreach (string name in _parent.Combined.CalculateCombinedSetupNames()) { if (name == template.ProfileName) { // this is the current profile so we take the data from where we generate it instead // of from a file foreach (StatusReportItem item in _allViewports.Merge(name, _localViewports)) { yield return(item); } continue; } ViewportSetupFile generated = _parent.Combined.Load(name); if (null == generated) { yield return(new StatusReportItem { Status = $"Could not include the viewports for Helios profile '{name}' because no generated viewport data was found", Recommendation = $"Configure DCS Monitor Setup for Helios profile '{name}', then configure DCS Monitor Setup for current Helios profile", Severity = StatusReportItem.SeverityCode.Warning, Link = StatusReportItem.ProfileEditor }); continue; } foreach (StatusReportItem item in _allViewports.Merge(name, generated)) { yield return(item); } } } }
private IEnumerable <StatusReportItem> UpdateLocalViewports(MonitorSetupTemplate template) { _localViewports = new ViewportSetupFile { MonitorLayoutKey = _parent.MonitorLayoutKey }; foreach (ShadowVisual shadow in _parent.Viewports) { string name = shadow.Viewport.ViewportName; if (_localViewports.Viewports.ContainsKey(name)) { yield return(new StatusReportItem { Status = $"The viewport '{name}' exists more than once in this profile. Each viewport must have a unique name.", Recommendation = $"Rename one of the duplicated viewports with name '{name}' in this profile", Severity = StatusReportItem.SeverityCode.Warning, Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate }); continue; } Rect rect = MonitorSetup.VisualToRect(shadow.Visual); rect.Offset(shadow.Monitor.Left, shadow.Monitor.Top); _localViewports.Viewports.Add(name, rect); } // now check against our saved state, which we also have to update ViewportSetupFile saved = _parent.Combined.Load(template.ProfileName); if (null == saved) { yield return(new StatusReportItem { Status = "The viewport data for this profile does not exist", Severity = StatusReportItem.SeverityCode.Error, Recommendation = $"Configure {_parent.Name}" }); } else if (saved.MonitorLayoutKey != _localViewports.MonitorLayoutKey || !saved.Viewports.OrderBy(e => e.Key) .SequenceEqual(_localViewports.Viewports.OrderBy(e => e.Key))) { // monitor layout key and the viewport rectangles in order must be equal yield return(new StatusReportItem { Status = "The viewport data for this profile is out of date", Severity = StatusReportItem.SeverityCode.Error, Recommendation = $"Configure {_parent.Name}" }); } }
internal IEnumerable <StatusReportItem> Merge(string name, ViewportSetupFile from) { if (MonitorLayoutKey != from.MonitorLayoutKey) { yield return(new StatusReportItem { Status = $"The stored viewport data from profile '{name}' does not match the current monitor layout", Recommendation = $"Configure DCS Monitor Setup for profile '{name}' to update the merged viewport data", Severity = StatusReportItem.SeverityCode.Warning, Link = StatusReportItem.ProfileEditor, Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate }); } foreach (KeyValuePair <string, Rect> viewport in from.Viewports) { if (!Viewports.TryGetValue(viewport.Key, out Rect existingRect)) { // just copy it Viewports.Add(viewport.Key, viewport.Value); continue; } if (existingRect.Equals(viewport.Value)) { // no problem continue; } // overwrite and warn Viewports[viewport.Key] = viewport.Value; yield return(new StatusReportItem { Status = $"profile '{name}' defines the viewport '{viewport.Key}' at a different screen location", Recommendation = $"Resolve viewport conflicts or do not include profile '{name}' in the combined monitor setup", Severity = StatusReportItem.SeverityCode.Warning, Link = StatusReportItem.ProfileEditor, Flags = StatusReportItem.StatusFlags.ConfigurationUpToDate }); } }
internal ViewportSetupFile Load(string viewportSetupName) { if (null == viewportSetupName) { return(new ViewportSetupFile()); } string path = LocateFile(viewportSetupName); if (!File.Exists(path)) { return(new ViewportSetupFile()); } string content = File.ReadAllText(path); ViewportSetupFile viewportData = JsonConvert.DeserializeObject <ViewportSetupFile>(content); viewportData.Exists = true; return(viewportData); }
public UpdatedViewportsEventArgs(ViewportSetupFile localViewports) { LocalViewports = localViewports; }