public static Configuration LoadConfigurationFromString(string configurationString, IGame game) { XmlSerializer confSerializer = new XmlSerializer(typeof(XmlSerializableConfiguration)); try { using (TextReader reader = new StringReader(configurationString)) { InputAnalyzerManager.CurrentGame = game; Configuration conf = confSerializer.Deserialize(reader) as Configuration; return(conf); } } catch (XmlException e) { UIThread.ShowMessage("", "Xml File cannot be parsed: " + e.Message + "" + "\n" + e.StackTrace + (e.InnerException == null ? "InnerException is null." : "InnerException: " + e.InnerException.Message + "\n" + e.InnerException.StackTrace)); return(null); } catch (Exception e) { UIThread.ShowMessage("", e.Message + "" + "\n" + e.StackTrace + (e.InnerException == null ? "InnerException is null." : "InnerException: " + e.InnerException.Message + "\n" + e.InnerException.StackTrace)); return(null); } }
public static Configuration LoadConfiguration(string configurationFile, IGame game) { if (!File.Exists(configurationFile)) { return(null); } _currentConfigurationFile = configurationFile; XmlSerializer confSerializer = new XmlSerializer(typeof(XmlSerializableConfiguration)); FileStream confFileStream = new FileStream(configurationFile, FileMode.Open); try { InputAnalyzerManager.CurrentGame = game; Configuration conf = confSerializer.Deserialize(confFileStream) as Configuration; confFileStream.Close(); return(conf); } catch (XmlException e) { UIThread.ShowMessage("", "Xml File cannot be parsed " + configurationFile + "" + e.Message + "" + "\n" + e.StackTrace + (e.InnerException == null ? "InnerException is null." : "InnerException: " + e.InnerException.Message + "\n" + e.InnerException.StackTrace)); return(null); } catch (Exception e) { UIThread.ShowMessage("", e.Message + "" + "\n" + e.StackTrace + (e.InnerException == null ? "InnerException is null." : "InnerException: " + e.InnerException.Message + "\n" + e.InnerException.StackTrace)); return(null); } }
private void ConfigureDevices(XPathNavigator navigator, Dictionary <string, IDevice> devices) { XPathNodeIterator deviceIt = navigator.Select("/Configuration/devices/device[@name]"); while (deviceIt.MoveNext()) { // parsing of attributes string deviceName = deviceIt.Current.GetAttribute("name", ""); ObservableDictionary <string, string> parametersGroup = ParseParams(deviceIt.Current); if (!devices.ContainsKey(deviceName)) { string strDevices = ""; foreach (string str in devices.Keys) { strDevices += (str == "" ? "" : ",") + str; } UIThread.ShowMessage("", "Device " + deviceName + " was not found on this computer!\n " + devices.Count + " devices installed. \n(" + strDevices + ")"); continue; } IDevice d = devices[deviceName]; if (!d.IsLoaded) { try { d.LoadDriver(parametersGroup); } catch (InitializationFailedException ex) { // MessageBox.Show(ex.Message, "ConfigureDevices: Unable to load driver", MessageBoxButton.OK, MessageBoxImage.Error); continue; } catch (Exception ex) { UIThread.ShowMessage("", ex.Message); continue; } } _deviceParameters.Add(deviceName, parametersGroup); if (Configuration.RegisteredInputs.Count == 0) { continue; } ObservableDictionary <string, ObservableDictionary <string, string> > parameters = ParseAnalyzersParams(deviceIt.Current); foreach (string analyzerFile in parameters.Keys) { if (d.GamingInput is ISkeletonInput) { ISkeletonAnalyzer analyzer = InputAnalyzerManager.GetSkeletonAnalyzer(analyzerFile); if (analyzer == null) { Console.Error.WriteLine("ERROR: Analyzer " + analyzerFile + " could not be loaded!!!"); } else { _inputAnalyzers.Add(new InputAnalyzer(parameters[analyzerFile], d, analyzer)); } } else if (d.GamingInput is IAccelerometerInput) { _inputAnalyzers.Add(new InputAnalyzer(parameters[analyzerFile], d, InputAnalyzerManager.GetAccelerometerAnalyzer(analyzerFile))); } else if (d.GamingInput is IBalanceBoardInput) { _inputAnalyzers.Add(new InputAnalyzer(parameters[analyzerFile], d, InputAnalyzerManager.GetBalanceBoardAnalyzer(analyzerFile))); } else if (d.GamingInput is IEmgSensorInput) { _inputAnalyzers.Add(new InputAnalyzer(parameters[analyzerFile], d, InputAnalyzerManager.GetEmgSignalAnalyzer(analyzerFile))); } } } }
private void ConfigureBindings(XPathNavigator navigator, Dictionary <string, IDevice> devices) { XPathNodeIterator bindingIt = navigator.Select( "/Configuration/bindings/binding[@device and @point and @sensitivity]"); while (bindingIt.MoveNext()) { string deviceName = bindingIt.Current.GetAttribute("device", ""); if (!devices.ContainsKey(deviceName)) { UIThread.ShowMessage("", "Device " + deviceName + " was not found on this computer!"); continue; } IDevice device = devices[deviceName]; if (!device.IsLoaded) { try { device.LoadDriver(null); } catch (InitializationFailedException ex) { // MessageBox.Show(ex.Message, "ConfigureBindings: Unable to load driver", MessageBoxButton.OK, MessageBoxImage.Error); continue; } } IGamingInput gamingInput = device.GamingInput; InputBinding binding = null; string point = bindingIt.Current.GetAttribute("point", ""); if (Configuration.GetHandle(point) == null) { continue; } if (device.GamingInput is ISkeletonInput) { binding = ConfigureSkeleton(navigator, bindingIt, (ISkeletonInput)device.GamingInput); ObservableDictionary <string, ObservableDictionary <string, string> > analyzersParams = ParseAnalyzersParams(bindingIt.Current); foreach (string analyzerFile in analyzersParams.Keys) { if (binding is SkeletonBinding) { (binding as SkeletonBinding).AddAnalyzer( InputAnalyzerManager.GetSkeletonAnalyzer(analyzerFile), analyzersParams[analyzerFile]); } else if (binding is AbsoluteSkeletonBinding) { (binding as AbsoluteSkeletonBinding).AddAnalyzer( InputAnalyzerManager.GetSkeletonAnalyzer(analyzerFile), analyzersParams[analyzerFile]); } } } else if (gamingInput is IAccelerometerInput) { binding = ConfigureAccelerometer(navigator, bindingIt, (IAccelerometerInput)device.GamingInput); ObservableDictionary <string, ObservableDictionary <string, string> > analyzersParams = ParseAnalyzersParams(bindingIt.Current); foreach (string analyzerFile in analyzersParams.Keys) { if (binding is AccelerometerBinding) { (binding as AccelerometerBinding).AddAnalyzer( InputAnalyzerManager.GetAccelerometerAnalyzer(analyzerFile), analyzersParams[analyzerFile]); } } } else if (gamingInput is IBalanceBoardInput) { binding = ConfigureBalanceBoard(navigator, bindingIt, (IBalanceBoardInput)device.GamingInput); ObservableDictionary <string, ObservableDictionary <string, string> > analyzersParams = ParseAnalyzersParams(bindingIt.Current); // // TODO add balance board analyzers processing // //foreach (string analyzerFile in analyzersParams.Keys) //{ // if (binding is BalanceBoardBinding) // (binding as BalanceBoardBinding).AddAnalyzer( // AnalysisManager.GetBAccelerometerAnalyzer(analyzerFile), analyzersParams[analyzerFile]); //} } else if (gamingInput is IEmgSensorInput) { binding = ConfigureEmgSensor(navigator, bindingIt, (IEmgSensorInput)device.GamingInput); //ObservableDictionary<string, ObservableDictionary<string, string>> analyzerParams = // ParseAnalyzersParams(bindingIt.Current); } if (binding != null) { this.AddOrReplace(binding); } } }