/*
* Copyright (C) 2004-2005 Jonathan Bindel
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
using System;
using DCSharp.Backend.Connections;
using DCSharp.Backend.Objects;
using DCSharp.Xml.FileList;
namespace DCSharp.Backend.Managers{
public delegate void FileListingEventHandler(FileListing list,
Identity user);
public class Listener
{
public event EventHandler<UserEventArgs> UserAdded;
public event EventHandler<UserEventArgs> UserRemoved;
public event FileListingEventHandler ReceivedFileListing;
public Listener(HubManager hubManager)
{
if (hubManager == null)
{
throw new ArgumentNullException("hubManager");
}
hubManager.HubAdded += OnHubAdded;
hubManager.HubRemoved += OnHubRemoved;
}
#region Methods
private void OnHubAdded(object obj, ConnectionEventArgs args)
{
HubConnection hub = (HubConnection)args.Connection;
hub.Users.UserAdded += OnUserAdded;
hub.Users.UserRemoved += OnUserRemoved;
}
private void OnHubRemoved(object obj, ConnectionEventArgs args)
{
HubConnection hub = (HubConnection)args.Connection;
hub.Users.UserAdded -= OnUserAdded;
hub.Users.UserRemoved -= OnUserRemoved;
}
private void OnUserAdded(object obj, UserEventArgs args)
{
if (UserAdded != null)
{
UserAdded(this, args);
}
}
private void OnUserRemoved(object obj, UserEventArgs args)
{
if (UserRemoved != null)
{
UserRemoved(this, args);
}
}
internal void EmitReceivedFileListing(FileListing list, Identity user)
{
if (ReceivedFileListing != null)
{
ReceivedFileListing(list, user);
}
}
#endregion
}
}
|