public async Task ReceiveAsync(IContext context)
        {
            switch (context.Message)
            {
            case Started _:
            {
                _inner = _grains._HelloGrainFactory();
                context.SetReceiveTimeout(TimeSpan.FromSeconds(30));
                break;
            }

            case ReceiveTimeout _:
            {
                context.Stop(context.Self);
                break;
            }

            case GrainRequest request:
            {
                switch (request.MethodIndex)
                {
                case 0:
                {
                    var r = HelloRequest.Parser.ParseFrom(request.MessageData);
                    try
                    {
                        var res = await _inner.SayHello(r);

                        var grainResponse = new GrainResponse
                        {
                            MessageData = res.ToByteString(),
                        };
                        context.Respond(grainResponse);
                    }
                    catch (Exception x)
                    {
                        var grainErrorResponse = new GrainErrorResponse
                        {
                            Err = x.ToString()
                        };
                        context.Respond(grainErrorResponse);
                    }

                    break;
                }
                }

                break;
            }
            }
        }
        public async Task ReceiveAsync(IContext context)
        {
            switch (context.Message)
            {
            case Started _:
            {
                _inner = Grains._HelloGrainFactory();
                break;
            }

            case GrainRequest request:
            {
                switch (request.Method)
                {
                case "SayHello":
                {
                    var r = HelloRequest.Parser.ParseFrom(request.MessageData);
                    try
                    {
                        var res = await _inner.SayHello(r);

                        var grainResponse = new GrainResponse
                        {
                            MessageData = res.ToByteString(),
                        };
                        context.Respond(grainResponse);
                    }
                    catch (Exception x)
                    {
                        var grainErrorResponse = new GrainErrorResponse
                        {
                            Err = x.ToString()
                        };
                        context.Respond(grainErrorResponse);
                    }

                    break;
                }
                }

                break;
            }
            }
        }
Beispiel #3
0
        public async Task <String> SayHello()
        {
            IHelloGrain helloGrain = GrainClient.GrainFactory.GetGrain <IHelloGrain>(0);

            return(await helloGrain.SayHello());
        }