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

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

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

            return(settings);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets up calibration procedure and the tracking client
        /// and wires the events. Reads settings from file.
        /// </summary>
        protected override void Initialize()
        {
            // Load Gazepoint tracker settings.
            if (File.Exists(this.SettingsFile))
            {
                this.memSettings = this.DeserializeSettings(this.SettingsFile);
            }
            else
            {
                this.memSettings = new GazepointSetting();
                this.SerializeSettings(this.memSettings, this.SettingsFile);
            }

            // We just need one connection for now. Maybe for subsequent development, we will be able to connect to many trackers
            this.memNetworkManager = new ClientNetworkManager(this.memSettings.ServerAddress, this.memSettings.ServerPort, out this.memConnectionsIds);
            this.memNetworkManager.MessageReceived += this.ProcessReceivedMessage;
            this.memIsCalibrating = false;
            this.memIsRecording   = false;
            //this.memXmlDocument = new XmlDocument();
            //this.memTimeOfRecordingStart = new Stopwatch();

            // Check the screen size, in ProcessReceivedMessage we receive the answer
            // and set the correct size
            this.memNetworkManager.Connect();
            this.memNetworkManager.SendMessage("<GET ID=\"SCREEN_SIZE\" />\r\n");

            // Get the timer tick frequency default value
            QueryPerformanceFrequency(out this.tickFrequency);

            // Get the timer tick frequency for high resolution timing from the Gazepoint API
            this.memNetworkManager.SendMessage("<GET ID=\"TIME_TICK_FREQUENCY\" />\r\n");
            this.memNetworkManager.Disconnect();
            base.Initialize();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Serializes the <see cref="GazepointSetting"/> into the given file in a xml structure.
        /// </summary>
        /// <param name="settings">The <see cref="GazepointSetting"/> object to serialize.</param>
        /// <param name="filePath">Full file path to the xml settings file.</param>
        private void SerializeSettings(GazepointSetting settings, string filePath)
        {
            // Create an instance of the XmlSerializer class;
            // specify the type of object to serialize
            XmlSerializer serializer = new XmlSerializer(typeof(GazepointSetting));

            // Serialize the GazepointSetting, 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 GazepointSettings failed with the following message: " + Environment.NewLine + ex.Message,
                    false,
                    MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Raises GazepointSettingDialog to change the settings
        /// for this interface.
        /// </summary>
        public override void ChangeSettings()
        {
            var dlg = new GazepointSettingsDialog {
                GazepointSetting = this.memSettings
            };
            string prevAdd  = this.memSettings.ServerAddress;
            int    prevPort = this.memSettings.ServerPort;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                // If settings has changed, and we where connected, we need to disconnect
                if (!prevAdd.Equals(this.memSettings.ServerAddress) ||
                    !prevPort.Equals(this.memSettings.ServerPort))
                {
                    this.CleanUp();
                    this.memNetworkManager.ChangePort(this.memConnectionsIds[0], dlg.GazepointSetting.ServerPort);
                    this.memNetworkManager.ChangeAddress(this.memConnectionsIds[0], dlg.GazepointSetting.ServerAddress);
                }

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

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

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

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

      return settings;
    }
Ejemplo n.º 7
0
    /// <summary>
    /// Sets up calibration procedure and the tracking client
    /// and wires the events. Reads settings from file.
    /// </summary>
    protected override void Initialize()
    {
      // Load Gazepoint tracker settings.
      if (File.Exists(this.SettingsFile))
      {
        this.memSettings = this.DeserializeSettings(this.SettingsFile);
      }
      else
      {
        this.memSettings = new GazepointSetting();
        this.SerializeSettings(this.memSettings, this.SettingsFile);
      }

      // We just need one connection for now. Maybe for subsequent development, we will be able to connect to many trackers
      this.memNetworkManager = new ClientNetworkManager(this.memSettings.ServerAddress, this.memSettings.ServerPort, out this.memConnectionsIds);
      this.memNetworkManager.MessageReceived += this.ProcessReceivedMessage;
      this.memIsCalibrating = false;
      this.memIsRecording = false;
      //this.memXmlDocument = new XmlDocument();
      //this.memTimeOfRecordingStart = new Stopwatch();

      // Check the screen size, in ProcessReceivedMessage we receive the answer
      // and set the correct size
      this.memNetworkManager.Connect();
      this.memNetworkManager.SendMessage("<GET ID=\"SCREEN_SIZE\" />\r\n");

      // Get the timer tick frequency default value
      QueryPerformanceFrequency(out this.tickFrequency);

      // Get the timer tick frequency for high resolution timing from the Gazepoint API
      this.memNetworkManager.SendMessage("<GET ID=\"TIME_TICK_FREQUENCY\" />\r\n");
      this.memNetworkManager.Disconnect();
      base.Initialize();
    }
Ejemplo n.º 8
0
    /// <summary>
    /// Raises GazepointSettingDialog to change the settings
    /// for this interface.
    /// </summary>
    public override void ChangeSettings()
    {
      var dlg = new GazepointSettingsDialog { GazepointSetting = this.memSettings };
      string prevAdd = this.memSettings.ServerAddress;
      int prevPort = this.memSettings.ServerPort;
      if (dlg.ShowDialog() == DialogResult.OK)
      {
        // If settings has changed, and we where connected, we need to disconnect
        if (!prevAdd.Equals(this.memSettings.ServerAddress) ||
            !prevPort.Equals(this.memSettings.ServerPort))
        {
          this.CleanUp();
          this.memNetworkManager.ChangePort(this.memConnectionsIds[0], dlg.GazepointSetting.ServerPort);
          this.memNetworkManager.ChangeAddress(this.memConnectionsIds[0], dlg.GazepointSetting.ServerAddress);
        }

        this.memSettings = dlg.GazepointSetting;
        this.SerializeSettings(this.Settings, this.SettingsFile);
      }
    }