Exemple #1
0
        public void TranslateExternalDeleteCommandToAkkaMessage(HTTPSourcedCommand cmdExternal)
        {
            JObject             jo        = cmdExternal.Data as JObject;
            string              id        = jo.Value <string>("Id") ?? jo.Value <string>("id");
            ClientDeleteCommand deleteCmd = new ClientDeleteCommand(id, cmdExternal.User, cmdExternal.ConnectionId);

            SendTo.Tell(deleteCmd, ReplyTo);
        }
Exemple #2
0
        public void TranslateExternalUpsertCommandToAkkaMessage(HTTPSourcedCommand cmdExternal)
        {
            ClientState cs;

            if (ExtractStateObject(cmdExternal, out cs))
            {
                ClientUpsertCommand upsertCmd = new ClientUpsertCommand(cs, cmdExternal.User, cmdExternal.ConnectionId);
                SendTo.Tell(upsertCmd, ReplyTo);
            }
        }
Exemple #3
0
        public void TranslateExternalInsertCommandToAkkaMessage(HTTPSourcedCommand cmdExternal)
        {
            UserState cs;

            if (ExtractStateObject(cmdExternal, out cs))
            {
                UserInsertCommand insertCommand = new UserInsertCommand(cs, cmdExternal.User, cmdExternal.ConnectionId);
                SendTo.Tell(insertCommand, ReplyTo);
            }
        }
Exemple #4
0
 private bool ExtractStateObject(HTTPSourcedCommand c, out ClientState cs)
 {
     try
     {
         JObject jo = c.Data as JObject;
         cs = ClientState.InstantiateClientState(jo);
         return(true);
     }
     catch (Exception ex)
     {
         cs = null;
         Logger.Error($"During '{c.CommandType}' system was unable to handle client's information. Exception:{ex.ToString()}");
         HTTPExternalInterface.HandleFailedStateMessage(new HTTPDestinedCommandStateEvent(MicroServices.ProcessingStatus.Failed, $"During '{c.CommandType}' system was unable to handle client's information.", c), true);
     }
     return(false);
 }
Exemple #5
0
        public bool ProcessCommand(HTTPSourcedCommand externalCommand)
        {
            MicroServices.CommandType cType;

            bool ableToParseCommand = MicroServices.ParseCommandType(externalCommand.CommandType, out cType);

            // Handle Command
            if (ableToParseCommand)
            {
                Logger.Debug($"{Area}HTTP Bridge Converted Command'{ externalCommand.CommandType}' to internal value{cType.ToString()}.");
                TrackConnection(externalCommand);

                switch (cType)
                {
                //Translate and Send message to client admin actor so that he will forward it to the client actor
                case MicroServices.CommandType.Insert:
                    TranslateExternalInsertCommandToAkkaMessage(externalCommand);
                    break;

                case MicroServices.CommandType.Update:
                    TranslateExternalUpdateCommandToAkkaMessage(externalCommand);
                    break;

                case MicroServices.CommandType.Upsert:
                    TranslateExternalUpsertCommandToAkkaMessage(externalCommand);
                    break;

                case MicroServices.CommandType.Delete:
                    TranslateExternalDeleteCommandToAkkaMessage(externalCommand);
                    break;

                case MicroServices.CommandType.Undelete:
                    TranslateExternalUnDeleteCommandToAkkaMessage(externalCommand);
                    break;
                }
            }
            else
            {
                Logger.Debug($"HTTP Client Bridge received unknown string command value'{externalCommand.CommandType}'.");
                HTTPExternalInterface.HandleFailedStateMessage(new HTTPDestinedCommandStateEvent(MicroServices.ProcessingStatus.Failed, $"Unknown command:{externalCommand.CommandType}", externalCommand), true);
            }
            return(ableToParseCommand);
        }
Exemple #6
0
        /// <summary>
        /// This external command message handler parses the JSON message and attempts to determine the area to which it belongs.
        /// Once it has done that it will forward the message to the actor responsible for handling the discovered area.
        /// </summary>
        /// <param name="c"></param>
        private void ProcessExternalHTTPCommandHandler(HTTPSourcedCommand c)
        {
            MicroServices.CommandType cType;
            MicroServices.Area        area;
            bool ableToParseCommand = MicroServices.ParseCommandType(c.CommandType, out cType);
            bool ableToParseArea    = MicroServices.ParseArea(c.Area, out area);

            // Handle Area
            if (ableToParseArea)
            {
                _logger.Debug("HTTP Client Bridge Converted Area'{0}' to internal value{1}.", c.Area, area.ToString());
                _logger.Debug("Adding user '{0}' to group '{1}'", c.User, area.ToString());

                TrackConnection(c, area);

                // Now the we know the area forward it to the Area handler.  Nontice how the actor's name is dynamically constructed.
                Context.Child($"{area}{_IncomingMessageProcessorName}").Tell(c);
            }
            else
            {
                _logger.Debug("HTTP Client Bridge received unknown string area value'{0}'.", c.Area);
                _HTTPClientInterface.HandleFailedStateMessage(new HTTPDestinedCommandStateEvent(MicroServices.ProcessingStatus.Failed, "Unknown area:" + c.Area, c), true);
            }
        }
        // - Actions are abstract
        // - Commands is a kind of Action
        // - Requests is a kind of Action


        public HTTPDestinedCommandStateEvent(MicroServices.ProcessingStatus status, string message, HTTPSourcedCommand originalCommand) : base(status, message, originalCommand)
        {
            Action = originalCommand.CommandType;
            Data   = originalCommand.Data;
        }