Example #1
0
        public override async Task <GetAllTopicsResult> GetAllTopics(
            Empty request,
            ServerCallContext context)
        {
            var topics =
                await _executor
                .ExecuteAsync <GetAllTopicsParameters, GetAllTopicsResults>(
                    new GetAllTopicsParameters())
                .ConfigureAwait(false);

            return(new GetAllTopicsResult
            {
                Topics =
                {
                    topics.Topics.Select(
                        topic => new TopicResult
                    {
                        Description = topic.Description,
                        Name = topic.Name,
                        TopicId = topic.Id,
                        ImageUrl = topic.ImageUrl
                    })
                }
            });
        }
        public async Task <object> ExecuteAsync(IRequestReader reader, ResponseBuilder response)
        {
            switch (reader.RequestMethod)
            {
            case "POST":
            case "PUT":
            case "PATCH":
                return(await ExecuteWithRequeryAsync(reader, response));

            default:
                return(_executor.ExecuteAsync(reader, response));
            }
        }
Example #3
0
        public async Task <Guid> AddStudentAsync(Guid classId, UpsertStudentDto studentDto)
        {
            var student = await _executor.ExecuteAsync(new AddStudentCommand(classId, studentDto));

            if (!await _context.CommitAsync())
            {
                throw new Exception("Creating an student failed on save.");
            }
            if (student.StudentId != null)
            {
                await _hubContext.Clients.All.InvokeAsync("refresh");
            }
            return(student.StudentId);
        }
Example #4
0
        public async Task <Guid> AddClassAsync(UpsertClassDto classDto)
        {
            var @class = await _executor.ExecuteAsync(new AddClassCommand(classDto));

            if (!await _context.CommitAsync())
            {
                throw new Exception("Creating an class failed on save.");
            }
            if (@class.ClassId != null)
            {
                await _hubContext.Clients.All.InvokeAsync("refresh");
            }
            return(@class.ClassId);
        }
Example #5
0
        /// <summary>Sends a message.</summary>
        /// <param name="message">The message to send.</param>
        public async Task SendAsync(object message)
        {
            if (message is null)
            {
                throw new ArgumentNullException(nameof(message));
            }

            var registrations = await items
                                .GetMatchingAsync(k => discriminator.IsCompatible(message.GetType(), k))
                                .ConfigureAwait(false);

            // Copy the handlers to make sure additional registrations and unregistrations can occur
            // inside the handlers' execution without affecting the executor
            var handlers = registrations.Select(r => r.MessageHandler).ToList().AsReadOnly();

            if (handlers.Count > 0)
            {
                Log.Info($"Broadcasting {message} to {handlers.Count} handlers using {executor}");
                await executor.ExecuteAsync(message, handlers).ConfigureAwait(false);
            }
            else
            {
                Log.Debug($"{message} has no handlers, ignoring");
            }
        }
        /// <summary>
        /// Finds the endpoint and executes the request onto it.
        /// Handles errors and disposes of the endpoint when completed.
        /// </summary>
        public async Task InvokeAsync(IHttpRequestReader requestReader, IHttpRequestResponder responder, IRequestContext context)
        {
            var response = new Response(requestReader.ResourcePath);
            var builder  = new ResponseBuilder(response, _services.Modifiers);

            var reader = new RequestReader(requestReader, _services.NameSwitcher, _services.QueryCreator);
            var writer = new ResponseWriter(responder, response, _services.NameSwitcher);

            try
            {
                var           navigator = new EndpointNavigator(context, _startResourceFactory, _services);
                IRestEndpoint endpoint  = navigator.GetEndpointFromPath(requestReader.ResourcePath);
                IExecutor     executor  = _services.ExecutorFactory.GetExecutor(endpoint);

                await executor.ExecuteAsync(reader, builder);

                await writer.WriteAsync();
            }
            catch (Exception ex)
            {
                var errorInfo = new ExceptionErrorInfo(ex);
                builder.AddError(errorInfo);

                await writer.WriteAsync();
            }
            finally
            {
                context.Dispose();
            }
        }
Example #7
0
        public static async Task WorkAsync(this IExecutable executable)
        {
            IExecutable current = executable;

            while (current != null)
            {
                IExecutor executor = current.GetExecutor();
                current = await executor.ExecuteAsync();
            }
        }
Example #8
0
        public override async Task <GetUserByUserIdResult> GetUserByUserId(
            GetUserByUserIdParameter request,
            ServerCallContext context)
        {
            if (string.IsNullOrWhiteSpace(request.UserId) || !Guid.TryParse(request.UserId, out var userId))
            {
                throw new RpcException(new Status(StatusCode.InvalidArgument, "username"));
            }

            var user =
                await _executor
                .ExecuteAsync <GetUserByExternalIdParameters, GetUserByExternalIdResults>(
                    new GetUserByExternalIdParameters(userId))
                .ConfigureAwait(false);

            return(new GetUserByUserIdResult {
                Email = user.Email,
                Username = user.Username
            });
        }
        private async Task <TResponse> ExecuteAsync <TResponse>(HttpRequestMessage requestMessage, CancellationToken cancellationToken = default)
            where TResponse : class
        {
            var context  = new Contracts.ExecutionContext(requestMessage);
            var response = await _executor.ExecuteAsync(async() => await _client.SendAsync(requestMessage, cancellationToken), context);

            if (!response.IsSuccessStatusCode)
            {
                throw new RestClientException(await response.Content.ReadAsStringAsync(), (int)response.StatusCode);
            }

            return(_serializer.Deserialize <TResponse>(await response.Content.ReadAsStringAsync()));
        }
Example #10
0
        private void StartExecution()
        {
            // Reset environment
            _executionEnvironment.Reset();

            // Manipulate memory
            foreach (var memoryManipulation in _memoryManipulations)
            {
                memoryManipulation.Execute(_executionEnvironment.MemoryMap);
            }

            // Execute instructions async
            _executor.ExecuteAsync(_executionEnvironment, _instructions, 0);
        }
Example #11
0
        public override async Task <GetQuizzesPagedResult> GetQuizzesPaged(
            GetPagedParameter request,
            ServerCallContext context)
        {
            var quizzes =
                await _executor
                .ExecuteAsync <GetQuizzesPagedParameters, GetQuizzesPagedResults>(
                    new GetQuizzesPagedParameters(
                        request.StartIndex,
                        request.ItemCount))
                .ConfigureAwait(false);

            return(new GetQuizzesPagedResult
            {
                PageInfo = new GetPagedResult
                {
                    EndIndex = quizzes.EndIndex,
                    ItemCount = quizzes.ItemCount,
                    StartIndex = quizzes.StartIndex,
                    TotalCount = quizzes.TotalCount
                },
                Quizzes = { GetQuizzes(quizzes.List) }
            });
        }
 public async Task <object> ExecuteAsync(IRequestReader reader, ResponseBuilder response)
 {
     return(await CheckPreconditions(reader, response)
         ? await _executor.ExecuteAsync(reader, response)
         : null);
 }
Example #13
0
 public async Task <ActionResult <IEnumerable <ManagedItem> > > SyncItems()
 {
     return(Ok(await executor.ExecuteAsync()));
 }
Example #14
0
 public Task ExecuteAsync(Action op)
 {
     return(_internalExecutor.ExecuteAsync(op));
 }