private async Task UpdateActivityInternal(Activity activity, IEnumerable <UpdateActivityHandler> updateHandlers, Func <Task> callAtBottom) { BotAssert.ActivityNotNull(activity); if (updateHandlers == null) { throw new ArgumentException(nameof(updateHandlers)); } if (updateHandlers.Count() == 0) // No middleware to run. { if (callAtBottom != null) { await callAtBottom(); } return; } // Default to "No more Middleware after this". async Task next() { // Remove the first item from the list of middleware to call, // so that the next call just has the remaining items to worry about. IEnumerable <UpdateActivityHandler> remaining = updateHandlers.Skip(1); await UpdateActivityInternal(activity, remaining, callAtBottom).ConfigureAwait(false); } // Grab the current middleware, which is the 1st element in the array, and execute it UpdateActivityHandler toCall = updateHandlers.First(); await toCall(this, activity, next); }
private static void UpdateActivityCallbackImpl(IntPtr ptr, Result result) { GCHandle h = GCHandle.FromIntPtr(ptr); UpdateActivityHandler callback = (UpdateActivityHandler)h.Target; h.Free(); callback(result); }
/// <summary> /// Adds a response handler for update activity operations. /// </summary> /// <param name="handler">The handler to add to the context object.</param> /// <returns>The updated context object.</returns> /// <exception cref="ArgumentNullException"><paramref name="handler"/> is <c>null</c>.</exception> /// <remarks>When the context's <see cref="UpdateActivityAsync(IActivity, CancellationToken)"/> is called, /// the adapter calls the registered handlers in the order in which they were /// added to the context object. /// </remarks> public ITurnContext OnUpdateActivity(UpdateActivityHandler handler) { if (handler == null) { throw new ArgumentNullException(nameof(handler)); } _onUpdateActivity.Add(handler); return(this); }
public async Task UpdateActivityHandlerInvokesUpdateActivityWithCorrectActivity() { var message = new UpdateActivity { Activity = new Activity() }; var dataAccess = new Mock <IAllReadyDataAccess>(); var sut = new UpdateActivityHandler(dataAccess.Object); await sut.Handle(message); dataAccess.Verify(x => x.UpdateActivity(message.Activity), Times.Once); }
public async void ReturnNull_IfExceptionIsThrown() { Exception a = null; _unitOfWork.Setup(mock => mock.ActivityRepository.Update(It.IsAny <Activity>())) .Throws(a); var command = new UpdateActivityCommand(new ActivityModel()); var handler = new UpdateActivityHandler(_unitOfWork.Object); var returnValue = await handler.Handle(command, new CancellationToken()); Assert.Null(returnValue); }
private async Task <ResourceResponse> UpdateActivityInternalAsync( Activity activity, IEnumerable <UpdateActivityHandler> updateHandlers, Func <Task <ResourceResponse> > callAtBottom, CancellationToken cancellationToken) { BotAssert.ActivityNotNull(activity); if (updateHandlers == null) { throw new ArgumentException($"{nameof(updateHandlers)} is null.", nameof(updateHandlers)); } // No middleware to run. if (!updateHandlers.Any()) { if (callAtBottom != null) { return(await callAtBottom().ConfigureAwait(false)); } return(null); } // Default to "No more Middleware after this". async Task <ResourceResponse> Next() { // Remove the first item from the list of middleware to call, // so that the next call just has the remaining items to worry about. IEnumerable <UpdateActivityHandler> remaining = updateHandlers.Skip(1); var result = await UpdateActivityInternalAsync(activity, remaining, callAtBottom, cancellationToken).ConfigureAwait(false); activity.Id = result.Id; return(result); } // Grab the current middleware, which is the 1st element in the array, and execute it UpdateActivityHandler toCall = updateHandlers.First(); return(await toCall(this, activity, Next).ConfigureAwait(false)); }
public async void ReturnActivity_IfSucceesfullyUpdated() { Activity a = new Activity() { ActivityName = "123", Id = 1 }; _unitOfWork.Setup(mock => mock.ActivityRepository.Update(It.IsAny <Activity>())) .Returns(a); var tempActivityModel = new ActivityModel() { ActivityName = "test", ActivityId = 1 }; var command = new UpdateActivityCommand(tempActivityModel); var handler = new UpdateActivityHandler(_unitOfWork.Object); var returnValue = await handler.Handle(command, new CancellationToken()); Assert.NotNull(returnValue); }
public ITurnContext OnUpdateActivity(UpdateActivityHandler handler) { return(_adapter.OnUpdateActivity(handler)); }
public ITurnContext OnUpdateActivity(UpdateActivityHandler handler) => _innerTurnContext.OnUpdateActivity(handler);
/// <summary> /// Sets a user's presence in Discord to a new activity. This has a rate limit of 5 updates per 20 seconds. /// <para> /// It is possible for users to hide their presence on Discord (User Settings -> Game Activity). Presence set /// through this SDK may not be visible when this setting is toggled off. /// </para> /// </summary> /// <param name="activity"></param> /// <param name="callback"></param> public void UpdateActivity(Activity activity, UpdateActivityHandler callback) { GCHandle wrapped = GCHandle.Alloc(callback); Methods.UpdateActivity(methodsPtr, ref activity, GCHandle.ToIntPtr(wrapped), UpdateActivityCallbackImpl); }
public ITurnContext OnUpdateActivity(UpdateActivityHandler handler) { throw new NotImplementedException(); }
public ITurnContext OnUpdateActivity(UpdateActivityHandler handler) { return(_innerTurnContext.OnUpdateActivity(handler)); }