private InputGraphWindow(IHOTASCollection deviceList, Action <EventHandler <AxisChangedEventArgs> > handler, Action <EventHandler <AxisChangedEventArgs> > callBackRemoveHandler) { InitializeComponent(); DataContext = this; foreach (var d in deviceList.Devices.Where(x => x.IsDeviceLoaded)) { if (d.Capabilities.AxeCount <= 0) { continue; } if (_axisDeviceList == null) { _axisDeviceList = new List <IHOTASDevice>(); } _axisDeviceList.Add(d); //todo: grab capabilities from device so we know what axes are available } //todo: bind the names to a checkbox control and draw a canvas for each device selected? //the devices in _axisDeviceList will have the names of the true axis that are actually on the device handler(AxisChangedHandler); _callBackRemoveHandler = callBackRemoveHandler; Loaded += InputGraphWindow_Loaded; SizeChanged += InputGraphWindow_OnSizeChanged; CalculateScale((int)LineGraphCanvas.Height); _dispatcherTimer = new DispatcherTimer(new TimeSpan(0, 0, 0, 0, 25), DispatcherPriority.Send, DrawLoop, Dispatcher.CurrentDispatcher); }
public void FileSave(IHOTASCollection deviceList) { if (string.IsNullOrWhiteSpace(LastSavedFileName)) { FileSaveAs(deviceList); } else { BaseSave(LastSavedFileName, deviceList); } }
public static void CreateWindow(Window parent, IHOTASCollection deviceList, Action <EventHandler <AxisChangedEventArgs> > handler, Action <EventHandler <AxisChangedEventArgs> > callBackRemoveHandler) { if (_thisWindow != null) { _thisWindow.Show(); return; } _thisWindow = new InputGraphWindow(deviceList, handler, callBackRemoveHandler) { Owner = parent }; _thisWindow.Show(); }
private static void BaseSave(string fileName, IHOTASCollection deviceList) { Logging.Log.Debug($"Saving profile as :{fileName}"); try { _fileIo.WriteAllText(fileName, JsonConvert.SerializeObject(deviceList, Formatting.Indented, new CustomJsonConverter())); } catch (Exception e) { Logging.Log.Debug(e); throw; } }
public void FileSaveAs(IHOTASCollection deviceList) { var dlg = _fileDialogFactory.CreateSaveFileDialog(); dlg.FileName = "New Mapping"; dlg.DefaultExt = ".json"; dlg.Filter = "Sierra Hotel (.json)|*.json"; var result = dlg.ShowDialog(); if (result != true) { return; } LastSavedFileName = dlg.FileName; BaseSave(LastSavedFileName, deviceList); }
public IHOTASCollection FileOpen(string path) { if (string.IsNullOrWhiteSpace(path)) { return(null); } using (var file = _fileIo.OpenText(path)) { Logging.Log.Info($"Reading profile from :{path}"); var serializer = new JsonSerializer(); serializer.Converters.Add(new CustomJsonConverter()); IHOTASCollection collection = null; try { var o = (JObject)JToken.ReadFrom(new JsonTextReader(file)); var version = (string)o["JsonFormatVersion"]; if (version == HOTASCollection.FileFormatVersion) { collection = (HOTASCollection)serializer.Deserialize(new JTokenReader(o), typeof(HOTASCollection)); } //else - based on version, use factory to get old version and convert/map to latest version, then re-save } catch (JsonReaderException readerException) { Logging.Log.Error($"Could not deserialize {file}\nPlease verify this a SierraHOTAS compatible JSON file.\n\nStack:{readerException}"); return(null); } catch (Exception e) { Logging.Log.Error($"Could not deserialize {file}\nStack:{e}"); return(null); } LastSavedFileName = path; return(collection); } }
public ShowInputGraphWindowEvent(IHOTASCollection deviceList, Action <EventHandler <AxisChangedEventArgs> > axisChangedHandler, Action <EventHandler <AxisChangedEventArgs> > cancelCallbackRemoveHandler) { DeviceList = deviceList; AxisChangedHandler = axisChangedHandler; CancelCallbackRemoveHandler = cancelCallbackRemoveHandler; }