bool ConnectAutomatically(int timeout) { var info = new ServerLocator().FindServer(); if (info != null) { var fullAddress = info.UserLinkType != null ? info.RemoteAddress : info.LocalAddress; fullAddress = fullAddress.Substring(fullAddress.IndexOf("//", StringComparison.Ordinal) + 2); var parts = fullAddress.Split(':'); var address = parts[0]; var port = parts.Length > 1 ? parts[1] : "8096"; int intPort; Int32.TryParse(port, out intPort); return Kernel.ConnectToServer(address, intPort > 0 ? intPort : 8096, timeout); } return false; }
public void OpenServerSelectionPage() { Debug.Assert(Microsoft.MediaCenter.UI.Application.ApplicationThread == Thread.CurrentThread); //Get all available servers //First the local one var info = new ServerLocator().FindServer(); if (info != null) { Kernel.AddServer(info); } //Then connect ones if (Kernel.Instance.CommonConfigData.ConnectUserToken != null) { Kernel.ConnectApiClient.SetUserToken(Kernel.Instance.CommonConfigData.ConnectUserToken); var servers = Kernel.ConnectApiClient.GetAvailableServers(Kernel.Instance.CommonConfigData.ConnectUserId); if (servers != null) { foreach (var availableServer in servers) { Kernel.AddServer(availableServer); } } } OpenMCMLPage("resx://MediaBrowser/MediaBrowser.Resources/ServerSelection", new Dictionary<string, object> { { "Application", this } }); }
private void btnSaveConnection_Click(object sender, RoutedEventArgs e) { //Validate server address if (rbServerConnectAuto.IsChecked == true) { var endpoint = new ServerLocator().FindServer(); if (endpoint == null) { MessageBox.Show("Unable to find server. Please specify an address or start the server.", "Error locating server"); return; } tbxServerAddress.Text = endpoint.Address.ToString(); tbxPort.Text = endpoint.Port.ToString(); } PopUpMsg.DisplayMessage("Attempting to contact server..."); var address = tbxServerAddress.Text; var port = 8096; try { port = Convert.ToInt32(tbxPort.Text); } catch (Exception) { //let default through } this.Cursor = Cursors.AppStarting; btnSaveConnection.IsEnabled = false; Async.Queue("ConnectionCheck", () => Kernel.ConnectToServer(address, port, 20000), () => Dispatcher.Invoke(DispatcherPriority.Background,(System.Windows.Forms.MethodInvoker)ConnectionValidationDone)); }