Esempio n. 1
0
        /// <summary>
        /// Deserializes the <see cref="EyeTechSetting"/> from the given xml file.
        /// </summary>
        /// <param name="filePath">Full file path to the xml settings file.</param>
        /// <returns>A <see cref="EyeTechSetting"/> object.</returns>
        private EyeTechSetting DeserializeSettings(string filePath)
        {
            var settings = new EyeTechSetting();

            // Create an instance of the XmlSerializer class;
            // specify the type of object to be deserialized
            var serializer = new XmlSerializer(typeof(EyeTechSetting));

            // 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.
                var 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 = (EyeTechSetting)serializer.Deserialize(fs);
                fs.Close();
            }
            catch (Exception ex)
            {
                InformationDialog.Show(
                    "Error occured",
                    "Deserialization of EyeTechSetting failed with the following message: " + Environment.NewLine + ex.Message,
                    false,
                    MessageBoxIcon.Error);
            }

            return(settings);
        }
Esempio n. 2
0
        /// <summary>
        /// Serializes the <see cref="EyeTechSetting"/> into the given file in a xml structure.
        /// </summary>
        /// <param name="settings">The <see cref="EyeTechSetting"/> object to serialize.</param>
        /// <param name="filePath">Full file path to the xml settings file.</param>
        private void SerializeSettings(EyeTechSetting settings, string filePath)
        {
            // Create an instance of the XmlSerializer class;
            // specify the type of object to serialize
            var serializer = new XmlSerializer(typeof(EyeTechSetting));

            // Serialize the EyeTechSetting, 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 EyeTechSetting failed with the following message: " + Environment.NewLine + ex.Message,
                    false,
                    MessageBoxIcon.Error);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Sets up calibration procedure and the tracking client
        /// and wires the events. Reads settings from file.
        /// </summary>
        protected override sealed void Initialize()
        {
            this.imageData = new ImageData();

            // Load eyetech tracker settings. First tries to get realtime QuickGlance
            // settings. If this fails, fallback to a settingsfile. If that fails, create
            // a default settingsfile.
            // NOTE: These settings are not always up to date as a user can just change
            // the settings through QuickGlance.
            this.eyetechSettings = new EyeTechSetting();
            if (!this.eyetechSettings.GetQuickGlanceSettings())
            {
                if (File.Exists(this.SettingsFile))
                {
                    this.eyetechSettings = this.DeserializeSettings(this.SettingsFile);
                }
                else
                {
                    this.SerializeSettings(this.eyetechSettings, this.SettingsFile);
                }
            }

            this.UpdateSettings();
        }
Esempio n. 4
0
    /// <summary>
    /// Serializes the <see cref="EyeTechSetting"/> into the given file in a xml structure.
    /// </summary>
    /// <param name="settings">The <see cref="EyeTechSetting"/> object to serialize.</param>
    /// <param name="filePath">Full file path to the xml settings file.</param>
    private void SerializeSettings(EyeTechSetting settings, string filePath)
    {
      // Create an instance of the XmlSerializer class;
      // specify the type of object to serialize 
      var serializer = new XmlSerializer(typeof(EyeTechSetting));

      // Serialize the EyeTechSetting, 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 EyeTechSetting failed with the following message: " + Environment.NewLine + ex.Message,
          false,
          MessageBoxIcon.Error);
      }
    }
Esempio n. 5
0
    /// <summary>
    /// Deserializes the <see cref="EyeTechSetting"/> from the given xml file.
    /// </summary>
    /// <param name="filePath">Full file path to the xml settings file.</param>
    /// <returns>A <see cref="EyeTechSetting"/> object.</returns>
    private EyeTechSetting DeserializeSettings(string filePath)
    {
      var settings = new EyeTechSetting();

      // Create an instance of the XmlSerializer class;
      // specify the type of object to be deserialized 
      var serializer = new XmlSerializer(typeof(EyeTechSetting));

      // 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.
        var 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 = (EyeTechSetting)serializer.Deserialize(fs);
        fs.Close();
      }
      catch (Exception ex)
      {
        InformationDialog.Show(
          "Error occured",
          "Deserialization of EyeTechSetting failed with the following message: " + Environment.NewLine + ex.Message,
          false,
          MessageBoxIcon.Error);
      }

      return settings;
    }
Esempio n. 6
0
    /// <summary>
    /// Sets up calibration procedure and the tracking client
    /// and wires the events. Reads settings from file.
    /// </summary>
    protected override sealed void Initialize()
    {
      this.imageData = new ImageData();

      // Load eyetech tracker settings. First tries to get realtime QuickGlance
      // settings. If this fails, fallback to a settingsfile. If that fails, create
      // a default settingsfile. 
      // NOTE: These settings are not always up to date as a user can just change
      // the settings through QuickGlance.
      this.eyetechSettings = new EyeTechSetting();
      if (!this.eyetechSettings.GetQuickGlanceSettings())
      {
        if (File.Exists(this.SettingsFile))
        {
          this.eyetechSettings = this.DeserializeSettings(this.SettingsFile);
        }
        else
        {
          this.SerializeSettings(this.eyetechSettings, this.SettingsFile);
        }
      }

      this.UpdateSettings();
    }