/* * Copyright (C) 2007 Eskil Bylund * * 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 System.Collections.Generic; namespace DCSharp { public class IdentityEventArgs : EventArgs { private Identity identity; public IdentityEventArgs(Identity identity) { this.identity = identity; } public Identity Identity { get { return identity; } } } /// /// The identity of a user on a hub. /// public class Identity : ICloneable { private Dictionary parameters; private Uid cid; private User user; private string nick; private string description; private string email; private string connection; private string client; private bool active; private bool isOperator; private long shareSize; public Identity(User user) : this(user.Uid, user.Nick) { } public Identity(User user, string nick) : this(user.Uid, nick) { } public Identity(Uid cid, string nick) : this() { if (nick == null) { throw new ArgumentNullException("nick"); } this.cid = cid; this.nick = nick; } private Identity() { parameters = new Dictionary(); } #region Properties /// /// Gets the Cid of the user. /// /// The Cid of the user public Uid Cid { get { return cid; } set { cid = value; } } /// /// Gets the user this identity is about. /// /// The user this identity is about. public User User { get { if (user == null || user.Uid != cid) { user = User.Create(cid, nick); } return user; } } /// /// Gets or sets the nickname of the user. /// /// The nickname of the user. public string Nick { get { return nick; } set { nick = value; } } /// /// Gets or sets the user description. /// /// The user description. public string Description { get { return description; } set { description = value; } } /// /// Gets or sets the e-mail address of the user. /// /// The e-mail address of the user. public string Email { get { return email; } set { email = value; } } /// /// Gets or sets the connection of the user. /// /// The connection of the user public string Connection { get { return connection; } set { connection = value; } } /// /// Gets or sets the client of the user. /// /// The client of the user public string Client { get { return client; } set { client = value; } } /// /// Gets or sets whether or not the user is active. /// /// Whether or not the user is active. public bool Active { get { return active; } set { active = value; } } /// /// Gets or sets whether or not the user is an operator. /// /// Whether or not the user is an operator. public bool Op { get { return isOperator; } set { isOperator = value; } } /// /// Gets or sets the number of bytes shared by the user. /// /// The number of bytes shared by the user. public long ShareSize { get { return shareSize; } set { shareSize = value; } } #endregion #region Methods /// /// Retrives a user parameter by the parameter name. /// /// The name of the parameter. /// The value of the parameter, if found; otherwise, null. internal string GetParameter(string name) { lock (parameters) { string value; if (parameters.TryGetValue(name, out value)) { return value; } return null; } } /// /// Sets a user parameter by the parameter name. /// /// The name of the parameter. /// The value of the parameter. internal void SetParameter(string name, string value) { lock (parameters) { parameters[name] = value; } } /// /// Removes a user parameter. /// /// The parameter to remove. internal void RemoveParameter(string name) { lock (parameters) { parameters.Remove(name); } } public object Clone() { return this.MemberwiseClone(); } public override string ToString() { return String.Format("{0} ({1})", nick, cid); } #endregion } }