Пример #1
0
        public async Task <object> Invoke(Type grainType, object grain, GrainRouteValues grainRouteValues, HttpContext context)
        {
            var executor = _cachedExecutors.GetOrAdd($"{grainType.FullName}.{grainRouteValues.GrainMethod}",
                                                     (key) =>
            {
                var mi = Internal.ReflectionUtil.GetMethodsIncludingBaseInterfaces(grainType)
                         .FirstOrDefault(x => string.Equals(x.Name, grainRouteValues.GrainMethod));
                return(ObjectMethodExecutor.Create(mi, grainType.GetTypeInfo()));
            });

            var parameters = await GetParameters(executor, context.Request);

            return(await executor.ExecuteAsync(grain, parameters));
        }
        public async Task Invoke(HttpContext context)
        {
            var data             = context.GetRouteData();
            var grainRouteValues = new GrainRouteValues(data);
            var grainType        = _grainTypeProvider.GetGrainType(grainRouteValues.GrainInterface);
            var grain            = _grainReferenceProvider.GetGrainReference(grainType, grainRouteValues.GrainId);
            var result           = await _grainInvoker.Invoke(grainType, grain, grainRouteValues, context);

            context.Response.StatusCode  = 200;
            context.Response.ContentType = "application/json";
            using (var writer = new StreamWriter(context.Response.Body))
            {
                _serializer.Serialize(writer, result);
                await writer.FlushAsync();
            }
        }
        public async Task Invoke(HttpContext context)
        {
            var data             = context.GetRouteData();
            var grainRouteValues = new GrainRouteValues(data);

            var grainType = GetGrainType(grainRouteValues.GrainInterface);
            var grain     = GetGrainReference(grainType, grainRouteValues.GrainId);
            var result    = await _grainInvoker.Invoke(grainType, grain, grainRouteValues, context);



            context.Response.StatusCode  = 200;
            context.Response.ContentType = "application/json";
            using (var writer = new StreamWriter(context.Response.Body))
            {
                _serializer.Serialize(writer, result);

                // Perf: call FlushAsync to call WriteAsync on the stream with any content left in the TextWriter's
                // buffers. This is better than just letting dispose handle it (which would result in a synchronous
                // write).
                await writer.FlushAsync();
            }
        }