Changeset 136
- Timestamp:
- 03/06/07 20:48:00 (2 years ago)
- Files:
-
- dmp/trunk/Bridge/Bridge.cs (modified) (6 diffs)
- dmp/trunk/Bridge/Bridge.csproj (modified) (1 diff)
- dmp/trunk/Bridge/ServerAddedEventArgs.cs (added)
- dmp/trunk/daap-sharp/BridgeDatabase.cs (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dmp/trunk/Bridge/Bridge.cs
r134 r136 15 15 public class Bridge 16 16 { 17 public event EventHandler<ServerAddedEventArgs > ServerAdded; 18 17 19 /// <summary> 18 20 /// The dictionary of DAAP clients, since I believe each instance only connects to one server … … 20 22 /// </summary> 21 23 private System.Collections.Generic.Dictionary<int, Client> clientList; 24 25 /// <summary> 26 /// This dictionary maps a server name to the library ID found in the Bridge Database 27 /// </summary> 28 private System.Collections.Generic.Dictionary<string, int> serverNameToIdList; 22 29 23 30 private BridgeDatabase db; … … 38 45 this.myServiceLocator = new ServiceLocator(); 39 46 this.myServiceLocator.ShowLocalServices = true; 47 this.myServiceLocator.Found += ZeroConfServerFound; 40 48 this.myServiceLocatorStarted = false; 41 49 } … … 156 164 } 157 165 158 public void AddFoundHandler(ServiceHandler fun){159 myServiceLocator.Found += fun;160 }161 162 166 /// <summary> 163 167 /// Gets the list of all the songs in the collection … … 250 254 Console.WriteLine("Added libraryid to client list: " + newClient.Id); 251 255 this.clientList.Add(newClient.Id, newClient); 256 this.serverNameToIdList.Add(newClient.Name, newClient.Id); 252 257 } 253 258 else … … 264 269 } 265 270 } 271 272 /// <summary> 273 /// Runs when ZeroConf finds a new server 274 /// </summary> 275 /// <param name="o"></param> 276 /// <param name="args"></param> 277 private void ZeroConfServerFound(object o, DAAP.ServiceArgs args) { 278 Service newServer = args.Service; 279 int libraryId = this.db.getLibraryIdForName(newServer.Name); 280 if (libraryId > -1) { //Reconnect to this server 281 int addResult = this.AddServerConnection(newServer); 282 if (addResult > -1) { 283 284 this.ServerAdded(this, new ServerAddedEventArgs(newServer.Name, true)); 285 } 286 } 287 else { 288 this.ServerAdded(this, new ServerAddedEventArgs(newServer.Name, false)); 289 } 290 } 266 291 } 292 267 293 } dmp/trunk/Bridge/Bridge.csproj
r87 r136 48 48 <Compile Include="Bridge.cs" /> 49 49 <Compile Include="Properties\AssemblyInfo.cs" /> 50 <Compile Include="ServerAddedEventArgs.cs" /> 50 51 </ItemGroup> 51 52 <ItemGroup> dmp/trunk/daap-sharp/BridgeDatabase.cs
r134 r136 238 238 239 239 return theTable; 240 } 241 242 /// <summary> 243 /// Finds the library ID matching the name, if one exists 244 /// </summary> 245 /// <param name="libName">The name of the server to find an ID for</param> 246 /// <returns>The libary ID if it's in the database, -1 otherwise</returns> 247 public int getLibraryIdForName(string libName) { 248 string commandText = "SELECT id FROM libraries WHERE name = @name"; 249 SQLiteDataAdapter adapter = new SQLiteDataAdapter(commandText, this.databaseConnection); 250 adapter.SelectCommand.Parameters.Add("name", DbType.String).Value = libName; 251 DataTable tempTable = new DataTable(); 252 this.databaseConnection.Open(); 253 adapter.Fill(tempTable); 254 this.databaseConnection.Close(); 255 if (tempTable.Rows.Count <= 0) { 256 return -1; 257 } 258 else { 259 int libraryId = (int)tempTable.Rows[0]["id"]; 260 return libraryId; 261 } 240 262 } 241 263
