/// <summary> /// Deserializes the <see cref="AleaSetting"/> from the given xml file. /// </summary> /// <param name="filePath">Full file path to the xml settings file.</param> /// <returns>A <see cref="AleaSetting"/> object.</returns> private AleaSetting DeserializeSettings(string filePath) { AleaSetting settings = new AleaSetting(); // Create an instance of the XmlSerializer class; // specify the type of object to be deserialized XmlSerializer serializer = new XmlSerializer(typeof(AleaSetting)); // If the XML document has been altered with unknown // nodes or attributes, handle them with the // UnknownNode and UnknownAttribute events. serializer.UnknownNode += new XmlNodeEventHandler(this.SerializerUnknownNode); serializer.UnknownAttribute += new XmlAttributeEventHandler(this.SerializerUnknownAttribute); try { // A FileStream is needed to read the XML document. FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); // Use the Deserialize method to restore the object's state with // data from the XML document. settings = (AleaSetting)serializer.Deserialize(fs); fs.Close(); } catch (Exception ex) { InformationDialog.Show( "Error occured", "Deserialization of AleaSettings failed with the following message: " + Environment.NewLine + ex.Message, false, MessageBoxIcon.Error); } return(settings); }
/// <summary> /// Sets up calibration procedure and the tracking client /// and wires the events. Reads settings from file. /// </summary> protected override void Initialize() { this.CalibrationDone += new EventHandler <CalibrationDoneEventArgs>(this.aleaInterface_CalibrationDone); this.isRecording = false; this.stopwatch = new Stopwatch(); this.timeLock = new object(); this.api = new EtApi(); APICalibrationDone += new CalibrationDoneDelegate(this.AleaInterface_APICalibrationDone); APIRawDataReceived += new RawDataDelegate(this.AleaInterface_APIRawDataReceived); // Load alea tracker settings. if (File.Exists(this.SettingsFile)) { this.settings = this.DeserializeSettings(this.SettingsFile); } else { this.settings = new AleaSetting(); this.SerializeSettings(this.settings, this.SettingsFile); } base.Initialize(); }
/// <summary> /// Raises <see cref="AleaSettingsDialog"/> to change the settings /// for this interface. /// </summary> public override void ChangeSettings() { AleaSettingsDialog dlg = new AleaSettingsDialog(); dlg.AleaSettings = this.Settings; if (dlg.ShowDialog() == DialogResult.OK) { this.settings = dlg.AleaSettings; this.SerializeSettings(this.Settings, this.SettingsFile); } }
/// <summary> /// Serializes the <see cref="AleaSetting"/> into the given file in a xml structure. /// </summary> /// <param name="settings">The <see cref="AleaSetting"/> object to serialize.</param> /// <param name="filePath">Full file path to the xml settings file.</param> private void SerializeSettings(AleaSetting settings, string filePath) { // Create an instance of the XmlSerializer class; // specify the type of object to serialize XmlSerializer serializer = new XmlSerializer(typeof(AleaSetting)); // Serialize the AleaSetting, and close the TextWriter. try { TextWriter writer = new StreamWriter(filePath, false); serializer.Serialize(writer, settings); writer.Close(); } catch (Exception ex) { InformationDialog.Show( "Error occured", "Serialization of AleaSettings failed with the following message: " + Environment.NewLine + ex.Message, false, MessageBoxIcon.Error); } }
/// <summary> /// Deserializes the <see cref="AleaSetting"/> from the given xml file. /// </summary> /// <param name="filePath">Full file path to the xml settings file.</param> /// <returns>A <see cref="AleaSetting"/> object.</returns> private AleaSetting DeserializeSettings(string filePath) { AleaSetting settings = new AleaSetting(); // Create an instance of the XmlSerializer class; // specify the type of object to be deserialized XmlSerializer serializer = new XmlSerializer(typeof(AleaSetting)); // If the XML document has been altered with unknown // nodes or attributes, handle them with the // UnknownNode and UnknownAttribute events. serializer.UnknownNode += new XmlNodeEventHandler(this.SerializerUnknownNode); serializer.UnknownAttribute += new XmlAttributeEventHandler(this.SerializerUnknownAttribute); try { // A FileStream is needed to read the XML document. FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read); // Use the Deserialize method to restore the object's state with // data from the XML document. settings = (AleaSetting)serializer.Deserialize(fs); fs.Close(); } catch (Exception ex) { InformationDialog.Show( "Error occured", "Deserialization of AleaSettings failed with the following message: " + Environment.NewLine + ex.Message, false, MessageBoxIcon.Error); } return settings; }
/// <summary> /// Sets up calibration procedure and the tracking client /// and wires the events. Reads settings from file. /// </summary> protected override void Initialize() { this.CalibrationDone += new EventHandler<CalibrationDoneEventArgs>(this.aleaInterface_CalibrationDone); this.isRecording = false; this.stopwatch = new Stopwatch(); this.timeLock = new object(); this.api = new EtApi(); APICalibrationDone += new CalibrationDoneDelegate(this.AleaInterface_APICalibrationDone); APIRawDataReceived += new RawDataDelegate(this.AleaInterface_APIRawDataReceived); // Load alea tracker settings. if (File.Exists(this.SettingsFile)) { this.settings = this.DeserializeSettings(this.SettingsFile); } else { this.settings = new AleaSetting(); this.SerializeSettings(this.settings, this.SettingsFile); } base.Initialize(); }