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

            // Serialize the TobiiSetting, and close the TextWriter.
            try
            {
                // Create an instance of StreamWriter to write text to a file.
                // The using statement also closes the StreamWriter.
                using (var writer = new StreamWriter(filePath))
                {
                    serializer.Serialize(writer, settings);
                }
            }
            catch (Exception ex)
            {
                InformationDialog.Show(
                    "Error occured",
                    "Serialization of MouseOnlySettings failed with the following message: " + Environment.NewLine + ex.Message,
                    false,
                    MessageBoxIcon.Error);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Deserializes the <see cref="MouseOnlySetting"/> from the given xml file.
        /// </summary>
        /// <param name="filePath">Full file path to the xml settings file.</param>
        /// <returns>A <see cref="MouseOnlySetting"/> object.</returns>
        private MouseOnlySetting DeserializeSettings(string filePath)
        {
            var settings = new MouseOnlySetting();

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

            // If the XML document has been altered with unknown
            // nodes or attributes, handle them with the
            // UnknownNode and UnknownAttribute events.
            serializer.UnknownNode      += this.SerializerUnknownNode;
            serializer.UnknownAttribute += 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 = (MouseOnlySetting)serializer.Deserialize(fs);
                fs.Close();
            }
            catch (Exception ex)
            {
                InformationDialog.Show(
                    "Error occured",
                    "Deserialization of MouseOnlySettings failed with the following message: " + Environment.NewLine + ex.Message,
                    false,
                    MessageBoxIcon.Error);
            }

            return(settings);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Show a <see cref="MouseOnlySettingsDlg"/> to change the settings
        /// for this interface.
        /// </summary>
        public override void ChangeSettings()
        {
            var dlg = new MouseOnlySettingsDlg {
                MouseOnlySettings = this.mouseOnlySettings
            };

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.mouseOnlySettings = dlg.MouseOnlySettings;
                this.UpdateSettings();
                this.SerializeSettings(this.mouseOnlySettings, this.SettingsFile);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sets up calibration procedure and the tracking client
        /// and wires the events. Then reads settings from file.
        /// </summary>
        protected override sealed void Initialize()
        {
            this.counter               = 0;
            this.trackingTimer         = new Timer();
            this.stopWatch             = new Stopwatch();
            this.multimediaTimer       = new MultimediaTimer();
            this.multimediaTimer.Tick += this.TrackingTimerTick;

            if (File.Exists(this.SettingsFile))
            {
                this.mouseOnlySettings = this.DeserializeSettings(this.SettingsFile);
            }
            else
            {
                this.mouseOnlySettings = new MouseOnlySetting();
                this.SerializeSettings(this.mouseOnlySettings, this.SettingsFile);
            }

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

      // Serialize the TobiiSetting, and close the TextWriter.
      try
      {
        // Create an instance of StreamWriter to write text to a file.
        // The using statement also closes the StreamWriter.
        using (var writer = new StreamWriter(filePath))
        {
          serializer.Serialize(writer, settings);
        }
      }
      catch (Exception ex)
      {
        InformationDialog.Show(
          "Error occured",
          "Serialization of MouseOnlySettings failed with the following message: " + Environment.NewLine + ex.Message,
          false,
          MessageBoxIcon.Error);
      }
    }
Exemplo n.º 6
0
    /// <summary>
    /// Deserializes the <see cref="MouseOnlySetting"/> from the given xml file.
    /// </summary>
    /// <param name="filePath">Full file path to the xml settings file.</param>
    /// <returns>A <see cref="MouseOnlySetting"/> object.</returns>
    private MouseOnlySetting DeserializeSettings(string filePath)
    {
      var settings = new MouseOnlySetting();

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

      // If the XML document has been altered with unknown 
      // nodes or attributes, handle them with the 
      // UnknownNode and UnknownAttribute events.
      serializer.UnknownNode += this.SerializerUnknownNode;
      serializer.UnknownAttribute += 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 = (MouseOnlySetting)serializer.Deserialize(fs);
        fs.Close();
      }
      catch (Exception ex)
      {
        InformationDialog.Show(
          "Error occured",
          "Deserialization of MouseOnlySettings failed with the following message: " + Environment.NewLine + ex.Message,
          false,
          MessageBoxIcon.Error);
      }

      return settings;
    }
Exemplo n.º 7
0
    /// <summary>
    /// Sets up calibration procedure and the tracking client
    /// and wires the events. Then reads settings from file.
    /// </summary>
    protected override sealed void Initialize()
    {
      this.counter = 0;
      this.trackingTimer = new Timer();
      this.stopWatch = new Stopwatch();
      this.multimediaTimer = new MultimediaTimer();
      this.multimediaTimer.Tick += this.TrackingTimerTick;

      if (File.Exists(this.SettingsFile))
      {
        this.mouseOnlySettings = this.DeserializeSettings(this.SettingsFile);
      }
      else
      {
        this.mouseOnlySettings = new MouseOnlySetting();
        this.SerializeSettings(this.mouseOnlySettings, this.SettingsFile);
      }

      this.UpdateSettings();
    }
Exemplo n.º 8
0
 /// <summary>
 /// Show a <see cref="MouseOnlySettingsDlg"/> to change the settings
 /// for this interface.
 /// </summary>
 public override void ChangeSettings()
 {
   var dlg = new MouseOnlySettingsDlg { MouseOnlySettings = this.mouseOnlySettings };
   if (dlg.ShowDialog() == DialogResult.OK)
   {
     this.mouseOnlySettings = dlg.MouseOnlySettings;
     this.UpdateSettings();
     this.SerializeSettings(this.mouseOnlySettings, this.SettingsFile);
   }
 }