Identity.cs :  » Business-Application » DC » DCSharp » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Business Application » DC 
DC » DCSharp » Identity.cs
/* 
 * 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 UserEventArgs : EventArgs
  {
    public UserEventArgs(Identity identity)
    {
      this.identity = identity;
    }
    
    public Identity User
    {
      get { return identity; }
    }
    private Identity identity;
  }
  
  /// <summary>
  /// The identity of a user on a hub.
  /// </summary>
  /// <remarks>
  /// User information not available as properties can be handled by using the
  /// methods of this class.
  /// </remarks>
  public class Identity : ICloneable
  {
    private Dictionary<string, string> parameters;
    
    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 (cid == null)
      {
        throw new ArgumentNullException("cid");
      }
      if (nick == null)
      {
        throw new ArgumentNullException("nick");
      }
      
      this.cid = cid;
      this.nick = nick;
    }
    
    private Identity()
    {
      parameters = new Dictionary<string, string>();
    }

    #region Properties
    
    /// <summary>
    /// Gets the Cid of the user.
    /// </summary>
    /// <value>The Cid of the user</value>
    public Uid Cid
    {
      get { return cid; }
      set { cid = value; }
    }
    private Uid cid;
    
    /// <summary>
    /// Gets the user this identity is about.
    /// </summary>
    /// <value>The user this identity is about.</value>
    public User User
    {
      get
      {
        if (user == null || user.Uid != cid)
        {
          user = User.Create(cid, nick);
        }
        return user;
      }
    }
    private User user;
    
    /// <summary>
    /// Gets or sets the nickname of the user.
    /// </summary>
    /// <value>The nickname of the user.</value>
    public string Nick
    {
      get { return nick; }
      set { nick = value; }
    }
    private string nick;
    
    /// <summary>
    /// Gets or sets the user description.
    /// </summary>
    /// <value>The user description.</value>
    public string Description
    {
      get { return description; }
      set { description = value; }
    }
    private string description;
    
    /// <summary>
    /// Gets or sets the e-mail address of the user.
    /// </summary>
    /// <value>The e-mail address of the user.</value>
    public string Email
    {
      get { return email; }
      set { email = value; }
    }
    private string email;
    
    /// <summary>
    /// Gets or sets the connection of the user.
    /// </summary>
    /// <value>The connection of the user</value>
    public string Connection
    {
      get { return connection; }
      set { connection = value; }
    }
    private string connection;
    
    /// <summary>
    /// Gets or sets whether or not the user is active.
    /// </summary>
    /// <value>Whether or not the user is active.</value>
    public bool Active
    {
      get { return active; }
      set { active = value; }
    }
    private bool active;
    
    /// <summary>
    /// Gets or sets whether or not the user is an operator.
    /// </summary>
    /// <value>Whether or not the user is an operator.</value>
    public bool Op
    {
      get { return isOperator; }
      set { isOperator = value; }
    }
    private bool isOperator;
    
    /// <summary>
    /// Gets or sets the number of bytes shared by the user.
    /// </summary>
    /// <value>The number of bytes shared by the user.</value>
    public long ShareSize
    {
      get { return shareSize; }
      set { shareSize = value; }
    }
    private long shareSize;
    
    #endregion
    
    #region Methods
    
    /// <summary>
    /// Retrives a user parameter by the parameter name.
    /// </summary>
    /// <param name="name">The name of the parameter.</param>
    /// <returns>The value of the parameter, if found; otherwise, null.</returns>
    public string GetParameter(string name)
    {
      if (name == null)
      {
        throw new ArgumentNullException("name");
      }
      lock (parameters)
      {
        string value;
        if (parameters.TryGetValue(name, out value))
        {
          return value;
        }
        return null;
      }
    }
    
    /// <summary>
    /// Sets a user parameter by the parameter name.
    /// </summary>
    /// <param name="name">The name of the parameter.</param>
    /// <param name="name">The value of the parameter.</param>
    public void SetParameter(string name, string value)
    {
      if (name == null)
      {
        throw new ArgumentNullException("name");
      }
      lock (parameters)
      {
        parameters[name] = value;
      }
    }
    
    /// <summary>
    /// Removes a user parameter.
    /// </summary>
    /// <param name="name">The parameter to remove.</param>
    public void RemoveParameter(string name)
    {
      if (name == null)
      {
        throw new ArgumentNullException("name");
      }
      lock (parameters)
      {
        parameters.Remove(name);
      }
    }
    
    public object Clone()
    {
      return this.MemberwiseClone();
    }
    
    public override string ToString()
    {
      return String.Format("{0} ({1})", nick, cid);
    }
    
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.