/// <summary> /// The method is called when the interval elapsed. /// </summary> /// <param name="sender">Instance of the object that raised the event.</param> /// <param name="e">The event data.</param> private static void Timer_Elapsed(object sender, EventArgs e) { if (_Requets.Count <= 0) { // no active requests, stop the time _Timer.Stop(); return; } // lifetime request - 20 minutes // remove old requests var now = DateTime.Now; var toRemove = _Requets.Where(itm2 => now.Subtract(itm2.Value.DateCreated).TotalMinutes >= 20).ToList(); foreach (var itm in toRemove) { if (_Requets.ContainsKey(itm.Key)) { OAuthManager.RemoveRequet(itm.Key); } } // change the status of the timer _Timer.Enabled = (_Requets.Count > 0); }
/// <summary> /// Registers the specified client in the application. /// </summary> /// <param name="client">The client instance.</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 /// ( /// new GoogleClient /// ( /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// ); /// /// OAuthManager.RegisterClient /// ( /// new FacebookClient /// ( /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// ); /// </code> /// <code lang="VB"> /// OAuthManager.RegisterClient _ /// ( /// New GoogleClient _ /// ( /// "1058655871432-83b9micke7cll89jfmcno5nftha3e95o.apps.googleusercontent.com", /// "AeEbEGQqoKgOZb41JUVLvEJL" /// ) /// ) /// /// OAuthManager.RegisterClient _ /// ( /// New FacebookClient _ /// ( /// "1435890426686808", /// "c6057dfae399beee9e8dc46a4182e8fd" /// ) /// ) /// </code> /// </example> public static void RegisterClient(OAuthBase client) { if (client == null) { throw new ArgumentNullException("client"); } if (_RegisteredClients.ContainsKey(client.ProviderName)) { throw new DuplicateProviderException(client.ProviderName); } // add client _RegisteredClients.Add(client.ProviderName, client); // remove from watching OAuthManager.RemoveRequet(client.State.ToString()); }