/// <summary> /// 增加该资源的使用者 /// </summary> /// <param name="user"></param> /// <param name="callback"></param> /// <param name="userData"></param> internal void AddUser(System.Object user, ResDataLoadedHandler callback, System.Object userData = null) { CallbackListener listener = new CallbackListener() { Callback = callback, UserData = userData }; List <CallbackListener> existList = null; if (!_userDict.TryGetValue(user, out existList)) { existList = new List <CallbackListener>(); existList.Add(listener); _userDict.Add(user, existList); _userList.Add(user); } else { if (!existList.Contains(listener)) { existList.Add(listener); } else { return;// } } }
/** * See {@link RtspServer.CallbackListener} to check out what events will be fired once you set up a listener. * @param listener The listener */ public void addCallbackListener(CallbackListener listener) { lock (mListeners) { if (mListeners.Count>0) { foreach (CallbackListener cl in mListeners) { if (cl == listener) return; } } mListeners.AddLast(listener); } }
public ResourceData(System.Object user, string key, ResourceType type, string url, ResDataLoadedHandler callback, System.Object userData = null) { this.Name = key; this.ResType = type; this.Url = url; CallbackListener listener = new CallbackListener() { Callback = callback, UserData = userData }; _callbacks.Add(listener); //_userDict.Add(user, new List<CallbackListener>() { listener }); AddCounter(user); }
private async Task <string> GetAuthentication(CancellationToken cancellation = default) { var parameters = new Dictionary <string, string> { { "client_id", _configuration.ClientId }, { "redirect_uri", _configuration.RedirectUri }, { "state", State }, { "scope", "user-read-private user-read-email user-top-read playlist-modify-public playlist-modify-private" }, { "response_type", "code" }, { "show_dialog", "false" } }; using var listener = new CallbackListener(); var response = await listener.GetCallbackAsync(CreateAuthenticationRequest(parameters, "authorize").Url, _configuration.RedirectUri); if (!string.IsNullOrEmpty(response.Error)) { _logger.LazyLog(LogLevel.Warning, () => $"Authentication Error: ${response.Error}"); return(null); } if (response.State != State) { _logger.LazyLog(LogLevel.Warning, () => $"Authentication Error: State received {response.State} does not match"); return(null); } if (string.IsNullOrEmpty(response.Code)) { _logger.LazyLog(LogLevel.Warning, () => "Authentication Error: No authentication code received"); return(null); } var tokenData = await GetCallbackAuthenticationToken(response.Code, cancellation); _cache.Set(AccessTokenCacheKey, tokenData.AccessToken, TimeSpan.FromSeconds(tokenData.ExpiresIn * 0.8)); _cache.Set(RefreshTokenCacheKey, tokenData.RefreshToken, TimeSpan.FromHours(1)); return(tokenData.AccessToken); }
/** * Removes the listener. * @param listener The listener */ public void removeCallbackListener(CallbackListener listener) { lock (mListeners) { mListeners.Remove(listener); } }
public void RaiseEvent() { CallbackListener?.Invoke(); }
public void RequestNextPage(CallbackListener <Paginator <T> > listener) { paginator.RequestNextPage(listener); }