/// <summary> /// Verifies that the given hostname is a working tv server /// </summary> /// <param name="hostname">The TV server's hostname</param> /// <param name="verbose">Indicates if a messagebox should be displayed or not</param> /// <returns></returns> private bool VerifyHostname(string hostname, bool verbose) { // See if the tv server port is accessible (with timeout) if (!CanConnect(hostname)) { Log.Debug("VerifyHostname: unable to connect to TV server on host \"{0}\"", hostname); if (verbose) { MessageBox.Show(string.Format("Unable to connect to TV server on host \"{0}\"", hostname), "TV/Radio Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(false); } // Set the hostname of the TV server TvServerRemote.HostName = hostname; // Get the database connection string from the TV server string connectionString, provider; TvServerRemote.GetDatabaseConnectionString(out connectionString, out provider); if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(provider)) { Log.Debug("VerifyHostname: unable to get data from TV server on host \"{0}\"", hostname); if (verbose) { MessageBox.Show(string.Format("Unable to get data from TV server on host \"{0}\"", hostname), "TV/Radio Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } return(false); } Log.Debug("VerifyHostname: verified a working TV server on host \"{0}\"", hostname); return(true); }
/// <summary> /// Updates the database connection string in the gentle.config file /// if the hostname has been changed or gentle.config contains "-" as server name. /// The connection string is fetched from the TV server. /// </summary> /// <param name="hostname">The TV server's hostname</param> /// <returns>Returns true, if the gentle.config file is updated</returns> private bool UpdateGentleConfig(string hostname) { Log.Debug("UpdateGentleConfig({0})", hostname); // Load the gentle.config file with the database connection string XmlNode node, nodeProvider; XmlDocument doc = new XmlDocument(); try { doc.Load(Config.GetFile(Config.Dir.Config, "gentle.config")); XmlNode nodeKey = doc.SelectSingleNode("/Gentle.Framework/DefaultProvider"); node = nodeKey.Attributes.GetNamedItem("connectionString"); nodeProvider = nodeKey.Attributes.GetNamedItem("name"); } catch (Exception ex) { Log.Error("UpdateGentleConfig: unable to open gentle.config" + Environment.NewLine + "{0}", ex.Message); MessageBox.Show(string.Format("Unable to open gentle.config" + Environment.NewLine + "{0}", ex.Message), "TV/Radio Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } // Verify tvServer (could be down at the moment) if (!VerifyHostname(hostname, verbose)) { Log.Error("UpdateGentleConfig: unable to contact TV server on host \"{0}\"", hostname); return(false); } // Get the database connection string from the TV server string connectionString, provider; TvServerRemote.GetDatabaseConnectionString(out connectionString, out provider); if (string.IsNullOrEmpty(connectionString) || string.IsNullOrEmpty(provider)) { Log.Error("UpdateGentleConfig: unable to get database connection string from TV server \"{0}\"", hostname); MessageBox.Show(string.Format("Unable to get database connection string from TV server \"{0}\"", hostname), "TV/Radio Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } // Save the gentle.config file with the database connection string try { node.InnerText = connectionString; nodeProvider.InnerText = provider; doc.Save(Config.GetFile(Config.Dir.Config, "gentle.config")); } catch (Exception ex) { Log.Error("UpdateGentleConfig: unable to modify gentle.config" + Environment.NewLine + "{0}", ex.Message); MessageBox.Show(string.Format("Unable to modify gentle.config" + Environment.NewLine + "{0}", ex.Message), "TV/Radio Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(false); } Log.Debug("UpdateGentleConfig: updated gentle.config with connectionString \"{0}\" for provider \"{1}\"", connectionString, provider); return(true); }
private void comboBoxGroups_DropDown(object sender, EventArgs e) { // Save current cursor and display wait cursor Cursor currentCursor = Cursor.Current; Cursor.Current = Cursors.WaitCursor; // Fill comboBox with radio channel names comboBoxGroups.Items.Clear(); comboBoxGroups.Items.Add("(none)"); int selectedIdx = 0; if (string.IsNullOrEmpty(TVRadio.Hostname)) { MessageBox.Show("Unable to get radio channel groups from the TV Server." + Environment.NewLine + "No valid hostname specified in the \"TV/Radio\" section.", "Radio Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { TvServerRemote.HostName = TVRadio.Hostname; List <string> groupNames = TvServerRemote.GetRadioChannelGroupNames(); if (groupNames.Count == 0) { MessageBox.Show(string.Format("Unable to get radio channel groups from the TV Server on host \"{0}\".", TVRadio.Hostname) + Environment.NewLine + "Version incompatibility of MP Client and TV Server?", "Radio Settings", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { foreach (string groupName in groupNames) { int idx = comboBoxGroups.Items.Add(groupName); if (groupName == _rootGroup) { selectedIdx = idx; } } } } comboBoxGroups.SelectedIndex = selectedIdx; // Reset cursor Cursor.Current = currentCursor; }