Changeset 124
- Timestamp:
- 03/03/07 23:34:19 (2 years ago)
- Files:
-
- dmp/trunk/BadClient/Form1.cs (modified) (3 diffs)
- dmp/trunk/Bridge/Bridge.cs (modified) (5 diffs)
- dmp/trunk/Mono.Zeroconf/BrowseService.cs (modified) (3 diffs)
- dmp/trunk/daap-sharp/BridgeDatabase.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dmp/trunk/BadClient/Form1.cs
r122 r124 29 29 { 30 30 lblStatus.Text = "Status: It connected?"; 31 DataTable theStuff = myBridge.get SongsInCollection();31 DataTable theStuff = myBridge.getAvailableSongsInCollection (); 32 32 lblStatus.Text = "Status: Found " + theStuff.Rows.Count + " rows!"; 33 33 dgvSongs.Rows.Clear(); … … 58 58 private void button2_Click(object sender, EventArgs e) 59 59 { 60 DataTable theStuff = this.myBridge.get SongsInCollection();60 DataTable theStuff = this.myBridge.getAvailableSongsInCollection (); 61 61 lblStatus.Text = "Status: This doesn't work yet!"; 62 62 foreach (DataRow row in theStuff.Rows) { … … 66 66 67 67 private void btnListServers_Click(object sender, EventArgs e) { 68 Dictionary<String, DAAP.Service> theServers = this.myBridge.get ServerList();68 Dictionary<String, DAAP.Service> theServers = this.myBridge.getZeroconfServerList(); 69 69 foreach (KeyValuePair<string, DAAP.Service> pair in theServers) { 70 70 treeView1.Nodes.Add(pair.Value.Name); dmp/trunk/Bridge/Bridge.cs
r122 r124 36 36 this.myServiceLocator = new ServiceLocator(); 37 37 this.myServiceLocator.ShowLocalServices = true; 38 //this.myServiceLocator.Start(); Putting this in the UI 38 this.myServiceLocator.Start(); 39 DataTable dbServers = db.getServersInCollection(); 40 System.Threading.Thread.Sleep(2000); 41 Dictionary<String, Service> whatDAAPFound = this.getZeroconfServerList(); 42 foreach (DataRow row in dbServers.Rows) { 43 string serverName = (string) row["name"]; 44 Console.WriteLine("Trying to connect to " + serverName); 45 if (whatDAAPFound.ContainsKey(serverName)) { 46 Service newServer = whatDAAPFound[serverName]; 47 this.AddServerConnection(newServer); 48 } 49 else { 50 Console.WriteLine("Couldn't find " + serverName); 51 } 52 } 39 53 } 40 54 /// <summary> … … 42 56 /// </summary> 43 57 /// <param name="theHostName">The host name, in some form that can be resolved</param> 44 /// <param name="thePort">The port number, the default is currently 36 90</param>58 /// <param name="thePort">The port number, the default is currently 3689</param> 45 59 /// <returns>The library id, which is referred to in the db and the 46 /// bridge's dictionary of clients </returns>60 /// bridge's dictionary of clients or -1 if the connect fails</returns> 47 61 public int AddServerConnection(string theHostName, ushort thePort){ 48 Client newClient = new Client(theHostName, thePort); 49 50 try 51 { 52 //List<TrackBase> tracks = new List<TrackBase>(); 53 //List<int> deletedTracks = new List<int>(); 54 //List<PlaylistBase> playlists = new List<PlaylistBase>(); 55 56 //setup library for this client 57 //BridgeDatabase.Library lib = new BridgeDatabase.Library(); 58 //lib.address = newClient.Address.ToString(); 59 //lib.port = newClient.Port; 60 //lib.name = newClient.Name; 61 //lib = db.addLibrary(lib); 62 if(!clientList.ContainsKey(newClient.Id)) 63 this.clientList.Add(newClient.Id, newClient); 64 65 newClient.Login(); // Passwords are for wimps 66 67 return newClient.Id; 68 } 69 catch (DAAP.LoginException ex) 70 { 71 Console.WriteLine("Bridge: " + ex.Message); 62 try { 63 Client newClient = new Client(theHostName, thePort); 64 return this.LoginAndSaveToDatabase(newClient); 65 } 66 catch { 72 67 return -1; 73 } 74 } 75 76 /* 77 * If anyone knows why I can't do this let me know, thanks, Luni. 78 * 79 * It complains that returning the type List<DMP.BridgeDatabase.Song> 80 * is less "accessible" than the method getAllSongsInCollection itself, 81 * which kinda doesn't make sense unless there is some part of namespaces 82 * in .Net I do not understand. 83 * 84 * // Gets all the songs in the *collection* 85 public List<DMP.BridgeDatabase.Song> getAllSongsInCollection() 86 { 87 return this.db.getSongsInCollection(); 88 } 89 */ 90 91 /// <summary> 92 /// 68 } 69 } 70 /// <summary> 71 /// Connects to the given server and eventually will get the songs from it 72 /// </summary> 73 /// <param name="theService">The serivce found with ZeroConf to connect to</param> 74 /// <returns>The library id, which is referred to in the db and the 75 /// bridge's dictionary of clients or -1 if the connect fails</returns> 76 public int AddServerConnection(Service theService) { 77 try { 78 Client newClient = new Client(theService); 79 return this.LoginAndSaveToDatabase(newClient); 80 } 81 catch { 82 return -1; 83 } 84 } 85 86 /// <summary> 87 /// Gets the list of all the songs in the collection that are on available servers 88 /// </summary> 89 /// <returns>A DataTable with the following columns: 90 /// id, libraryId, artist, album, title</returns> 91 public DataTable getAvailableSongsInCollection() { 92 int[] libraries = new int[this.clientList.Count]; 93 int libraryCount = 0; 94 foreach (int key in this.clientList.Keys) { 95 libraries[libraryCount] = key; 96 libraryCount++; 97 } 98 DataTable theTable = this.db.getAvailableSongsInCollection(libraries); 99 return theTable; 100 } 101 102 /// <summary> 103 /// Gets a list of servers that are discoverable at the time using Zeroconf 93 104 /// </summary> 94 105 /// <returns></returns> 95 public Dictionary<String, Service> get ServerList() {106 public Dictionary<String, Service> getZeroconfServerList() { 96 107 System.Collections.IEnumerable serverListing = this.myServiceLocator.Services; 97 108 Dictionary<String, Service> serverDict = new Dictionary<string, Service>(); … … 100 111 int duplicateCount; 101 112 Service server; 113 Console.WriteLine("Listing servers..."); 102 114 foreach (System.Collections.DictionaryEntry entry in serverListing) { 103 115 server = (Service) entry.Value; 104 116 key = server.Name; 117 Console.WriteLine("Found the server \"" + key + "\"."); 105 118 if (serverDict.ContainsKey(key)) { 106 119 duplicateCount = 1; … … 116 129 } 117 130 } 131 Console.WriteLine("Done listing servers."); 118 132 return serverDict; 119 133 } … … 200 214 return this.db.isDatabaseUp(); 201 215 } 216 217 /// <summary> 218 /// Attempts to log in and store the connection info in the database 219 /// </summary> 220 /// <param name="newClient">The client to log in to</param> 221 /// <returns>-1 on failure, the library ID on success</returns> 222 private int LoginAndSaveToDatabase(Client newClient) { 223 try { 224 225 if (!clientList.ContainsKey(newClient.Id)) 226 this.clientList.Add(newClient.Id, newClient); 227 228 newClient.Login(); // Passwords are for wimps 229 Console.WriteLine("Connected to " + newClient.Name); 230 231 return newClient.Id; 232 } 233 catch (DAAP.LoginException ex) { 234 Console.WriteLine("Bridge: " + ex.Message); 235 return -1; 236 } 237 } 202 238 } 203 239 } dmp/trunk/Mono.Zeroconf/BrowseService.cs
r118 r124 37 37 public sealed class BrowseService : Service 38 38 { 39 private Native.DNSServiceResolveReply resolveReply;40 39 private bool is_resolved = false; 41 40 private bool resolve_pending = false; … … 49 48 public BrowseService(string name, string replyDomain, string regtype) : base(name, replyDomain, regtype) 50 49 { 51 resolveReply = OnResolveReply;52 50 } 53 54 ~BrowseService()55 {56 GC.KeepAlive(resolveReply);57 }58 51 59 52 public void Resolve() … … 77 70 ServiceRef sd_ref; 78 71 ServiceError error = Native.DNSServiceResolve(out sd_ref, ServiceFlags.None, 79 InterfaceIndex, Name, RegType, ReplyDomain, resolveReply, IntPtr.Zero);72 InterfaceIndex, Name, RegType, ReplyDomain, OnResolveReply, IntPtr.Zero); 80 73 81 74 if(error != ServiceError.NoError) { dmp/trunk/daap-sharp/BridgeDatabase.cs
r110 r124 205 205 insertTrans.Commit(); 206 206 this.databaseConnection.Close(); 207 } 208 209 /// <summary> 210 /// Gets the list of all the songs in the collection 211 /// </summary> 212 /// <param name="libraries">A list of the library id's to get the songs from</param> 213 /// <returns>A DataTable with the following columns: 214 /// id, libraryId, artist, album, title</returns> 215 public DataTable getAvailableSongsInCollection(int[] libraries) { 216 StringBuilder commandText = new StringBuilder("SELECT * FROM songs WHERE "); 217 if (libraries.Length == 0) { 218 commandText.Append("libraryId = -1"); 219 } 220 else { 221 commandText.AppendFormat("libraryId = {0}", libraries[0]); 222 for (int i = 1; i < libraries.Length; i++) { 223 commandText.AppendFormat("OR libraryId = {1}", libraries[i]); 224 } 225 } 226 SQLiteDataAdapter adapter = new SQLiteDataAdapter(commandText.ToString(), 227 this.databaseConnection); 228 DataTable theTable = new DataTable(); 229 this.databaseConnection.Open(); 230 adapter.Fill(theTable); 231 this.databaseConnection.Close(); 232 233 return theTable; 234 } 235 236 /// <summary> 237 /// Returns a list of distinct libraries that the bridge has connected to before 238 /// </summary> 239 /// <returns></returns> 240 public DataTable getServersInCollection() { 241 string commandText = "SELECT id, name FROM libraries"; 242 SQLiteDataAdapter adapter = new SQLiteDataAdapter(commandText, this.databaseConnection); 243 DataTable theTable = new DataTable(); 244 this.databaseConnection.Open(); 245 adapter.Fill(theTable); 246 this.databaseConnection.Close(); 247 248 return theTable; 207 249 } 208 250
