///// <summary> ///// The event handler for the error occured event of the haytham tracker client. ///// Displays the error message. ///// </summary> ///// <param name="sender"> ///// The source of the event ///// </param> ///// <param name="e"> ///// A StringEventArgs with the error message. ///// </param> //private void ClientErrorOccured(object sender, StringEventArgs e) //{ // this.DisplayMessage(e.Param); //} /// <summary> /// Deserializes the <see cref="HaythamSetting"/> from the given xml file. /// </summary> /// <param name="filePath"> /// Full file path to the xml settings file. /// </param> /// <returns> /// A <see cref="HaythamSetting"/> object. /// </returns> private HaythamSetting DeserializeSettings(string filePath) { var clientSettings = new HaythamSetting(); // Create an instance of the XmlSerializer class; // specify the type of object to be deserialized var serializer = new XmlSerializer(typeof(HaythamSetting)); // 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. clientSettings = (HaythamSetting)serializer.Deserialize(fs); fs.Close(); } catch (Exception ex) { InformationDialog.Show( "Error occured", "Deserialization of HaythamIPSetting failed with the following message: " + Environment.NewLine + ex.Message, false, MessageBoxIcon.Error); } return(clientSettings); }
/// <summary> /// Reads settings from file. Then checks for existing haytham servers on /// the network to set the IP in the settings. /// </summary> protected override sealed void Initialize() { // Load haytham tracker settings. if (File.Exists(this.SettingsFile)) { this.settings = this.DeserializeSettings(this.SettingsFile); } else { this.settings = new HaythamSetting(); this.SerializeSettings(this.settings, this.SettingsFile); } Task.Factory.StartNew( () => { // find haytham hosts on network Uri hostUri = Client.getActiveHosts().FirstOrDefault(); while (hostUri == null) { // wait 5 seconds before next try Thread.Sleep(5000); // it has 2seconds timeout hostUri = Client.getActiveHosts().FirstOrDefault(); } // show IPv4 address if exists IPAddress server = Dns.GetHostAddresses(hostUri.DnsSafeHost) .FirstOrDefault(adr => adr.AddressFamily == AddressFamily.InterNetwork); if (server != null) { this.settings.HaythamServerIPAddress = server.ToString(); } }); this.lastTime = 0; this.launchButton.Click += this.LaunchButtonClick; this.statusUpdateTimer = new Timer { Interval = 100 }; this.statusUpdateTimer.Tick += this.StatusUpdateTimerTick; this.statusUpdateTimer.Start(); this.clientStatus = 0; this.trackControlsSplitContainer.Panel1Collapsed = false; this.trackControlsSplitContainer.Panel2Collapsed = true; ThreadSafe.EnableDisableButton(this.ConnectButton, false); }
/// <summary> /// Raises SettingsWindow to change the network settings for the haytham tracker /// </summary> public override void ChangeSettings() { var dlg = new HaythamSettingsDialog { HaythamSetting = this.Settings }; if (dlg.ShowDialog() == DialogResult.OK) { this.settings = dlg.HaythamSetting; this.SerializeSettings(this.Settings, this.SettingsFile); if (this.haythamClient != null) { this.haythamClient.ServerIPAddress = IPAddress.Parse(this.settings.HaythamServerIPAddress); } } }
/// <summary> /// Serializes the <see cref="HaythamSetting"/> into the given file in a xml structure. /// </summary> /// <param name="clientSettings"> /// The <see cref="HaythamSetting"/> object to serialize. /// </param> /// <param name="filePath"> /// Full file path to the xml settings file. /// </param> private void SerializeSettings(HaythamSetting clientSettings, string filePath) { // Create an instance of the XmlSerializer class; // specify the type of object to serialize var serializer = new XmlSerializer(typeof(HaythamSetting)); // Serialize the HaythamIPSetting, and close the TextWriter. try { TextWriter writer = new StreamWriter(filePath, false); serializer.Serialize(writer, clientSettings); writer.Close(); } catch (Exception ex) { InformationDialog.Show( "Error occured", "Serialization of HaythamSetting failed with the following message: " + Environment.NewLine + ex.Message, false, MessageBoxIcon.Error); } }
///// <summary> ///// The event handler for the error occured event of the haytham tracker client. ///// Displays the error message. ///// </summary> ///// <param name="sender"> ///// The source of the event ///// </param> ///// <param name="e"> ///// A StringEventArgs with the error message. ///// </param> //private void ClientErrorOccured(object sender, StringEventArgs e) //{ // this.DisplayMessage(e.Param); //} /// <summary> /// Deserializes the <see cref="HaythamSetting"/> from the given xml file. /// </summary> /// <param name="filePath"> /// Full file path to the xml settings file. /// </param> /// <returns> /// A <see cref="HaythamSetting"/> object. /// </returns> private HaythamSetting DeserializeSettings(string filePath) { var clientSettings = new HaythamSetting(); // Create an instance of the XmlSerializer class; // specify the type of object to be deserialized var serializer = new XmlSerializer(typeof(HaythamSetting)); // 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. clientSettings = (HaythamSetting)serializer.Deserialize(fs); fs.Close(); } catch (Exception ex) { InformationDialog.Show( "Error occured", "Deserialization of HaythamIPSetting failed with the following message: " + Environment.NewLine + ex.Message, false, MessageBoxIcon.Error); } return clientSettings; }