/// <summary> /// Registers the specified client in the application. (the main method) /// </summary> /// <param name="client">The client instance.</param> /// <param name="clientName">The any name of the client. For example: Test, Release, Project #1, Ku!, Example.org etc.</param> /// <exception cref="ArgumentNullException"><paramref name="client"/> is <b>null</b> or <b>empty</b>.</exception> /// <exception cref="DuplicateProviderException">If you attempt to register the already registered client.</exception> /// <example> /// <code lang="C#"> /// OAuthManager.RegisterClient /// ( /// "Test", /// new GoogleClient /// ( /// "00000000000000.apps.googleusercontent.com", /// "000000000000000000000000" /// ) /// ); /// /// OAuthManager.RegisterClient /// ( /// "Test", /// new FacebookClient /// ( /// "00000000000000", /// "000000000000000000000000" /// ) /// ); /// /// OAuthManager.RegisterClient /// ( /// "Release", /// new GoogleClient /// ( /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// ); /// /// OAuthManager.RegisterClient /// ( /// "Release", /// new FacebookClient /// ( /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// ); /// </code> /// <code lang="VB"> /// OAuthManager.RegisterClient _ /// ( /// "Test", /// New GoogleClient _ /// ( /// "00000000000000.apps.googleusercontent.com", /// "000000000000000000000000" /// ) /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "Test", /// New FacebookClient _ /// ( /// "00000000000000", /// "000000000000000000000000" /// ) /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "Release", /// New GoogleClient _ /// ( /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// ) /// /// OAuthManager.RegisterClient _ /// ( /// "Release", /// New FacebookClient _ /// ( /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// ) /// </code> /// </example> public static void RegisterClient(string clientName, OAuthBase client) { if (client == null) { throw new ArgumentNullException("client"); } /*if (client.ProviderName.Equals(ClientName.Parse(clientName).ProviderName, StringComparison.InvariantCultureIgnoreCase)) * { * // contains provider name * clientName = ClientName.Escape(ClientName.Parse(clientName).Key); * } * else * { * clientName = ClientName.Escape(clientName); * } * * var name = ClientName.Create(ClientName.Parse(clientName).Key ?? ClientName.Unescape(clientName), client.ProviderName); */ var name = ClientName.Create(clientName, client.ProviderName); if (OAuthManager.RegisteredClients.ContainsKey(name)) { throw new DuplicateProviderException(name); } // add client OAuthManager.RegisteredClients.Add(name, client); // remove from watching // OAuthManager.RemoveRequest(client.State.ToString()); // -- // if this is a new client if (!OAuthManager.AllClients.ContainsKey(client.ProviderName)) { // add to list OAuthManager.AllClients.Add(client.ProviderName, client.GetType()); } /*else * { * // check namespace * if (!client.GetType().Namespace.Equals("Nemiro.OAuth.Clients", StringComparison.InvariantCultureIgnoreCase)) * { * // overwrite * OAuthManager.AllClients[client.ProviderName] = client.GetType(); * } * }*/ }
/// <summary> /// Determines whether two object instances are equal. /// </summary> /// <param name="o">The object to compare with the current instance of the <see cref="ClientName"/>.</param> /// <returns><b>true</b> if the specified object is equal to the current <see cref="ClientName"/>; otherwise, <b>false</b>.</returns> public override bool Equals(object o) { if (o == null || (o.GetType() == typeof(string) && String.IsNullOrEmpty(o.ToString()))) { return(false); } if (o.GetType() == typeof(ClientName)) { return(this.Equals((ClientName)o)); } else { return(this.Equals(ClientName.Create(o.ToString()))); } }