Exemple #1
0
        public async Task <object> GetEntityTypes()
        {
            var result = await _dbEntityRoot.Ask <object>(new GetEntityTypes());

            return(result);
        }
Exemple #2
0
 public async Task <object> GetAllProducts()
 {
     return(await _actor.Ask(new Messages.Products.GetAllProductsCommand()));
 }
        public void Anonymous()
        {
            Receive <AuthenticateConnection>(msg =>
            {
                if (client.Connected)
                {
                    reader.ReadLineAsync().MapAsync(line => new UnauthenticatedClientRequest(JsonConvert.DeserializeObject <Request>(line)))
                    .PipeTo(Self, Self);
                }
                else
                {
                    Stop();
                }
            });

            Receive <UnauthenticatedClientRequest>(msg =>
            {
                var req = msg.Request;

                switch (req.RequestType)
                {
                case RequestType.Login:
                case RequestType.CreateAccount:
                    clients.Ask <AccountAuthenticationStatus>(new IsAuthenticated(req.ToTyped <Account>(), req.RequestType)).PipeTo(Self, Self);
                    break;

                default:
                    SendResponse(new Response
                    {
                        ResponseType = ResponseType.InvalidCommand,
                        Payload      =
                            "Invalid command - client has to be authenticated first via login or account creation"
                    });
                    accountName = null;
                    Become(Anonymous);
                    Self.Tell(new AuthenticateConnection());
                    break;
                }
            });

            Receive <AccountAuthenticationStatus>(msg =>
            {
                switch (msg.Status)
                {
                case AuthenticationStatus.Authenticated:
                    SendResponse(new Response
                    {
                        ResponseType = ResponseType.AuthenticationFailure,
                        Payload      = "Account " + msg.AccountInfo.AccountName + " is already connected and authenticated."
                    });
                    Stop();
                    return;

                case AuthenticationStatus.NotAuthenticated:
                    switch (msg.RequestType)
                    {
                    case RequestType.Login:
                        accountVerification.Tell(msg.AccountInfo, Self);
                        break;

                    case
                        RequestType.CreateAccount:
                        accountCreation.Tell(msg.AccountInfo, Self);
                        break;
                    }
                    return;
                }
            });

            Receive <AuthenticationSuccessful>(msg =>
            {
                SendResponse(new Response
                {
                    ResponseType = ResponseType.ConnectionAccepted
                });
                accountName = msg.AccountName;
                Become(Authenticated);
                clients.Tell(new AddClient(msg.AccountName));
                Self.Tell(new WaitForCommand());
            });
            Receive <AuthenticationFailed>(msg =>
            {
                SendResponse(new Response
                {
                    ResponseType = ResponseType.AuthenticationFailure,
                    Payload      = msg.Message
                });
                accountName = null;
                Become(Anonymous);
                Self.Tell(new AuthenticateConnection());
            });
        }
Exemple #4
0
 /// <summary>
 /// TBD
 /// </summary>
 /// <param name="message">TBD</param>
 /// <param name="timeout">TBD</param>
 /// <returns>TBD</returns>
 public override Task <object> Ask(object message, TimeSpan?timeout)
 {
     return(_actor.Ask(message, timeout));
 }
        public static async Task <ActorResultBuilder> Query(this ActorSelection actor, object message)
        {
            var answer = await actor.Ask(message);

            return(new ActorResultBuilder(answer));
        }
 private void HandleTryInitializeChat(Messages.TryInitializeChat tryInitiailizeChatMsg)
 {
     _chatCoordinatorActor.Ask <Messages.StartChat>(new Messages.TryInitializeChat(tryInitiailizeChatMsg.From, tryInitiailizeChatMsg.To))
     .PipeTo <Messages.StartChat>(Self);
 }
 public Task <ReplyUserFeedbacksMessage> AskUserFeedbackCollection()
 {
     return(_remotePersistenceActor.Ask <ReplyUserFeedbacksMessage>(new RequestUserFeedbacksMessage()));
 }
        // public static T SendSynchronousMessage<T>(IActorRef actorRef, object message, TimeSpan timeout)
        // {
        //     ColoredConsole.LogSendSynchronousMessage(message.GetType().Name, message.ToString(), actorRef);
        //     return actorRef.Ask<T>(message, timeout).Result;
        // }

        public static T SendSynchronousMessage <T>(ActorSelection actorSelection, object message, TimeSpan timeout)
        {
            ColoredConsole.LogSendSynchronousMessage(message.GetType().Name, message.ToString(), actorSelection);
            return(actorSelection.Ask <T>(message, timeout).Result);
        }
Exemple #9
0
        public async Task <Guid> Create()
        {
            var result = await _akkaServer.Ask <Status>(new Create(Guid.NewGuid()));

            return(result.To <Guid>());
        }