private void RemoveInnerContainers(DvMediaContainer container)
        {
            foreach (DvMediaContainer c in container.Containers)
            {
                InnerMediaDirectory mediadir = c.Tag as InnerMediaDirectory;
                if (mediadir != null)
                {
                    mediadir.watcher.EnableRaisingEvents = false;
                    watcherTable.Remove(mediadir.watcher);
                    mediadir.watcher.Changed -= new FileSystemEventHandler(OnDirectoryChangedSink);
                    mediadir.watcher.Created -= new FileSystemEventHandler(OnDirectoryCreatedSink);
                    mediadir.watcher.Deleted -= new FileSystemEventHandler(OnDirectoryDeletedSink);
                    mediadir.watcher.Renamed -= new RenamedEventHandler(OnFileSystemRenameSink);
                    mediadir.watcher.Dispose();
                    mediadir.watcher = null;
                    mediadir.directory = null;

                    RemoveInnerContainers(c);
                    totalFileCount -= c.Items.Count;
                    container.RemoveBranch(c);
                    totalDirectoryCount--;
                    if (OnStatsChanged != null) OnStatsChanged(this);
                }
                else if (c.Tag.GetType() == typeof(FileInfo))
                {
                    // this is a playlist container, so decrement
                    // the file count
                    totalFileCount--;
                }
            }
        }
 private void Handle_OnRequestRemoveBranch(MediaServerDevice sender, DvMediaContainer parentContainer, IDvMedia removeThisBranch)
 {
     Exception error = null;
     this.m_LockRoot.WaitOne();
     try
     {
         parentContainer.RemoveBranch(removeThisBranch);
     }
     catch (Exception e)
     {
         error = e;
     }
     this.m_LockRoot.ReleaseMutex();
     if (error != null)
     {
         throw new ApplicationException("Handle_OnRequestRemoveBranch()", error);
     }
 }