private static DACPServer GetDACPServer(ServerConnectionInfo info) { if (BonjourManager.DiscoveredServers.ContainsKey(info.ServiceID)) { var service = BonjourManager.DiscoveredServers[info.ServiceID]; string ip; if (service.IPAddresses.Count > 0) { ip = service.IPAddresses[0].ToString(); } else { ip = info.LastIPAddress; } if (ip == null) { return(null); } return(new DACPServer(ip, service.Port, info.PairingCode)); } else if (info.LastIPAddress != null && info.LastPort > 0) { return(new DACPServer(info.LastIPAddress, info.LastPort, info.PairingCode)); } return(null); }
private static void BonjourManager_ServiceRemoved(object sender, NetServiceEventArgs e) { ServerConnectionInfo info = PairedServers.FirstOrDefault(si => si.ServiceID == e.Service.Name); if (info != null) { _log.Info("Bonjour removed service: '{0}' ({1})", info.Name, info.ServiceID); info.IsAvailable = false; } }
public static void RemoveServerInfo(ServerConnectionInfo info) { ThreadUtility.RunOnUIThread(() => { _log.Info("Removing server info: '{0}' ({1})", info.Name, info.ServiceID); if (SelectedServerInfo == info) { ChooseServer(null); } PairedServers.Remove(info); }); }
public static void AddServerInfo(ServerConnectionInfo info) { ThreadUtility.RunOnUIThread(() => { _log.Info("Saving server info: '{0}' ({1})", info.Name, info.ServiceID); var oldServerInfo = PairedServers.FirstOrDefault(si => si.ServiceID == info.ServiceID); if (oldServerInfo != null) { RemoveServerInfo(oldServerInfo); } PairedServers.Add(info); info.IsAvailable = BonjourManager.DiscoveredServers.ContainsKey(info.ServiceID); UpdateServerInfoFromBonjour(info); }); }
public static void ChooseServer(ServerConnectionInfo info) { DisconnectCurrentServer(); CurrentServer = null; ConnectionState = ServerConnectionState.NoLibrarySelected; if (!PairedServers.Contains(info)) { _log.Info("Setting current server to null..."); SelectedServerInfo = null; return; } _log.Info("Setting current server to: '{0}' ({1})", info.Name, info.ServiceID); SelectedServerInfo = info; WakeServer(); AutoConnect(); }
private static void BonjourManager_ServiceAdded(object sender, NetServiceEventArgs e) { ServerConnectionInfo info = PairedServers.FirstOrDefault(si => si.ServiceID == e.Service.Name); if (info != null) { _log.Info("Bonjour found service: '{0}' ({1})", info.Name, info.ServiceID); info.IsAvailable = true; UpdateServerInfoFromBonjour(info); // Connect to the server if necessary if (SelectedServerInfo == info) { AutoConnect(); } } }
private static void UpdateServerInfoFromBonjour(ServerConnectionInfo info) { var service = BonjourManager.DiscoveredServers.GetValueOrDefault(info.ServiceID); if (service == null) { return; } // Check whether any of the stored data for this server is out of date bool dirty = false; string serviceName = service.TXTRecordData.GetValueOrDefault("CtlN", info.Name); if (info.Name != serviceName) { info.Name = serviceName; dirty = true; } if (info.LastHostname != service.Hostname) { info.LastHostname = service.Hostname; dirty = true; } if (info.LastPort != service.Port) { info.LastPort = service.Port; dirty = true; } // Determine the server type ServerType serverType = ServerType.iTunes; string dvTy = service.TXTRecordData.GetValueOrDefault("DvTy"); if (!string.IsNullOrEmpty(dvTy)) { dvTy = dvTy.ToLower(); if (dvTy.Contains("touchremote")) { serverType = ServerType.Foobar; } else if (dvTy.Contains("monkeytunes")) { serverType = ServerType.MediaMonkey; } else if (dvTy.Contains("albumplayer")) { serverType = ServerType.AlbumPlayer; } } if (info.ServerType != serverType) { info.ServerType = serverType; dirty = true; } // Save the paired servers list if necessary if (dirty) { _pairedServers.Save(); } }
public ServerConnectionInfoEventArgs(ServerConnectionInfo info) { ConnectionInfo = info; }