/// <summary> /// Dumps the contents of the mNexus.mSensorIDDict into a .xml configuration file /// </summary> private void SaveConfigFile() { StreamWriter fileStream; /** Generate the config file **/ try { fileStream = new StreamWriter(ConfigFilePath, false, Encoding.ASCII); } catch (DirectoryNotFoundException) { Directory.CreateDirectory(Path.Combine(AppDataDirPath, CFG_DIR)); fileStream = new StreamWriter(ConfigFilePath, false, Encoding.ASCII); } BoneLabelPair[] tmpArray = new BoneLabelPair[mSensorMappings.Count]; int count = 0; foreach (String t in this.mValidSensors) //(BoneType t in mSensorMappings.Keys) { tmpArray[count] = new BoneLabelPair(t, BoneType.None); tmpArray[count].Bone = mSensorMappings[t]; ++count; } XmlSerializer serializer = new XmlSerializer(tmpArray.GetType()); serializer.Serialize(fileStream, tmpArray); fileStream.Flush(); fileStream.Close(); this.bSaved = true; }
/// <summary> /// Reads the config file at %APPDATA%/Sensor-Aware-PT/config.xml /// </summary> public bool ReadConfigFile() { bool retval = true; StreamReader fileStream = null; try { // Get an array of sensor IDs from the xml file fileStream = new StreamReader(ConfigFilePath); BoneLabelPair[] tmpArray = new BoneLabelPair[1] { null }; XmlSerializer serializer = new XmlSerializer(tmpArray.GetType()); // Take each array object and insert it into the id dictionary tmpArray = serializer.Deserialize(fileStream) as BoneLabelPair[]; foreach (BoneLabelPair pair in tmpArray) { //Sensor currentSensor = null; //if (pair.SensorLabel != null) //{ // currentSensor = mNexus.GetSensor(pair.SensorLabel); // if (currentSensor != null && mSensorMappings.Keys.Contains(currentSensor.Id)) // { // throw new ArgumentOutOfRangeException(String.Format("There is already a sensor with ID \"{0}\"", pair.SensorLabel)); // } //} mSensorMappings[pair.SensorLabel] = pair.Bone; } } catch (System.InvalidOperationException e) { if (e.Message.StartsWith("There is an error in XML document")) { Logger.Warning(String.Format("{0}- {1}", e.GetType().ToString(), e.Message)); retval = false; } } catch (FileNotFoundException exc) { Logger.Warning("FileNotFoundException- {0}", exc.FileName); retval = false; } catch (Exception) { throw; } finally { if (fileStream != null) { fileStream.Close(); } } return(retval); }
/// <summary> /// Reads the config file at %APPDATA%/Sensor-Aware-PT/config.xml /// </summary> public bool ReadConfigFile() { bool retval = true; StreamReader fileStream = null; try { // Get an array of sensor IDs from the xml file fileStream = new StreamReader(ConfigFilePath); BoneLabelPair[] tmpArray = new BoneLabelPair[1] { null }; XmlSerializer serializer = new XmlSerializer(tmpArray.GetType()); // Take each array object and insert it into the id dictionary tmpArray = serializer.Deserialize(fileStream) as BoneLabelPair[]; foreach (BoneLabelPair pair in tmpArray) { //Sensor currentSensor = null; //if (pair.SensorLabel != null) //{ // currentSensor = mNexus.GetSensor(pair.SensorLabel); // if (currentSensor != null && mSensorMappings.Keys.Contains(currentSensor.Id)) // { // throw new ArgumentOutOfRangeException(String.Format("There is already a sensor with ID \"{0}\"", pair.SensorLabel)); // } //} mSensorMappings[pair.SensorLabel] = pair.Bone; } } catch (System.InvalidOperationException e) { if (e.Message.StartsWith("There is an error in XML document")) { Logger.Warning(String.Format("{0}- {1}", e.GetType().ToString(), e.Message)); retval = false; } } catch (FileNotFoundException exc) { Logger.Warning("FileNotFoundException- {0}", exc.FileName); retval = false; } catch (Exception) { throw; } finally { if (fileStream != null) fileStream.Close(); } return retval; }