Exemple #1
0
        public bool ProcessRequest(HTTPSourcedRequest externalRequest)
        {
            MicroServices.RequestType rType;
            bool ableToParseRequest = MicroServices.ParseRequestType(externalRequest.RequestType, out rType);

            // Handle Command
            if (ableToParseRequest)
            {
                Logger.Debug($"HTTP Client Bridge Converted Request'{externalRequest.RequestType}' to internal value '{rType.ToString()}'.");
                TrackConnection(externalRequest);

                switch (rType)
                {
                case MicroServices.RequestType.GetList:
                {
                    TranslateExternalGetListRequestToAkkaMessage(externalRequest);
                    break;
                }

                default:
                {
                    throw new NotImplementedException($"This request type has not been implemented:{rType.ToString()}");
                }
                }
            }
            else
            {
                Logger.Debug($"HTTP Client Bridge received unknown request value'{externalRequest.RequestType}'.");
                HTTPExternalInterface.HandleFailedStateMessage(new HTTPDestinedRequestStateEvent(MicroServices.ProcessingStatus.Failed, "Unknown request:" + externalRequest.RequestType, externalRequest), true);
            }

            return(ableToParseRequest);
        }
Exemple #2
0
        public bool TranslateAkkaGetListResponseToExternalMessage(Response akkaResponse)
        {
            UserGetListResponse response    = akkaResponse as UserGetListResponse;
            UserGetListRequest  request     = response.OriginalRequest as UserGetListRequest;
            HTTPSourcedRequest  httpRequest = request.OriginalHTTPRequest;


            HTTPExternalInterface.HandleRequestResponse(new HTTPDestinedRequestResponse(MicroServices.ProcessingStatus.Processed, response.ListOfUserStates, httpRequest), false);
            return(true);
        }
Exemple #3
0
 private void TrackConnection(HTTPSourcedAction a)
 {
     _ConnectionAreas = _ConnectionAreas ?? new Dictionary <string, List <MicroServices.Area> >();
     // Add the connection to the dict if not there
     if (!_ConnectionAreas.ContainsKey(a.ConnectionId))
     {
         _ConnectionAreas.Add(a.ConnectionId, new List <MicroServices.Area>());
     }
     // Add the area and add the user to the signal r group if not there
     if (!_ConnectionAreas[a.ConnectionId].Contains(MicroServices.Area.Client))
     {
         Logger.Debug($"Adding user '{a.User}' to group '{Area.ToString()}'");
         _ConnectionAreas[a.ConnectionId].Add(Area);
         HTTPExternalInterface.JoinGroup(Area.ToString(), a.ConnectionId);
     }
 }
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
        public bool TranslateAkkaFailedInsertEventToExternalMessage(CommandEventMessage internalCommandEvent)
        {
            UserFailedInsertEvent e = internalCommandEvent as UserFailedInsertEvent;

            HTTPExternalInterface.HandleFailedStateMessage(
                new HTTPDestinedCommandStateEvent(
                    MicroServices.ProcessingStatus.Failed,
                    e.Message,
                    new HTTPSourcedCommand(
                        e.CommandType.ToString(),
                        e.Area.ToString(),
                        null,
                        e.OriginalUserState,
                        e.User,
                        e.ConnectionId,
                        e.Id
                        )
                    ),
                true //User only?
                );
            return(true);
        }
Exemple #7
0
        public bool TranslateAkkaUnDeleteEventToExternalMessage(CommandEventMessage internalCommandEvent)
        {
            UserUnDeletedEvent e = internalCommandEvent as UserUnDeletedEvent;

            HTTPExternalInterface.HandleEDStateMessage(
                new HTTPDestinedCommandStateEvent(
                    MicroServices.ProcessingStatus.Processed,
                    e.Message,
                    new HTTPSourcedCommand(
                        e.CommandType.ToString(),
                        e.Area.ToString(),
                        null,
                        e.ResultUserState,
                        e.User,
                        e.ConnectionId,
                        e.Id
                        )
                    ),
                false //User only?
                );
            return(true);
        }