/// <summary> /// Method executes when smart control point notices that /// a upnp media server has left the network. /// </summary> /// <param name="sender"></param> /// <param name="device"></param> private void RemoveServer(UPnPSmartControlPoint sender, UPnPDevice device) { string udn = device.UniqueDeviceName; CpMediaServer removeThis = null; lock (LockHashes) { if (UdnToInitStatus.Contains(udn)) { InitStatus status = (InitStatus)UdnToInitStatus[udn]; } if (UdnToServer.Contains(udn)) { removeThis = (CpMediaServer)UdnToServer[udn]; UdnToServer.Remove(udn); } } if (this.OnServerGone != null) { this.OnServerGone(this, device); } if (removeThis != null) { if (this.OnCpServerRemoved != null) { this.OnCpServerRemoved(this, removeThis); } } System.GC.Collect(); }
/// <summary> /// Whenever Sink_Onxxx method executes, it calls this method to /// determine whether a server has been upgraded from non-good /// to good status. /// </summary> /// <param name="udn"></param> private void ProcessInitStatusChange(string udn) { CpMediaServer addedThis = null; InitStatus status = null; lock (LockHashes) { status = (InitStatus)UdnToInitStatus[udn]; if (status != null) { if (status.ZeroMeansDone == 0) { if ( (status.EventedCD) && (status.EventedCM) && (status.SubcribeCD) && (status.SubcribeCM) ) { // We were evented for both services // and we subscribed successfully, // so we're good to go. UdnToInitStatus.Remove(udn); UdnToServer[udn] = status.Server; addedThis = status.Server; } else { // we didn't subscribe successfully // or we never got evented after // we subscribed... but this // code should never execute because // we will have never decremented // ZeroMeansDone==0 } } if (addedThis == null) { if (BadServersAreGoodServersToo) { // but since we're configured to be // nice to crappy servers that // don't event properly... we'll // promote the server to full status UdnToInitStatus.Remove(udn); UdnToServer[udn] = status.Server; addedThis = status.Server; } } } } if (addedThis != null) { if (this.OnCpServerAdded != null) { this.OnCpServerAdded(this, addedThis); } } }