Inheritance: Message
コード例 #1
0
 private void RunProcessor(API.Request request, Processor processor, string processorName)
 {
     API.Response response = null;
     try
     {
         // Threadpooling
         response = processor.process(request);
     }
     catch (Exception e)
     {
         Logger.Error("Failed to process message with processor " + processor.GetType() + " : " + e.Message, e);
         try
         {
             Type responseType = Type.GetType("Gwupe.Cloud.Messaging.Response." + processorName + "Rs");
             response              = (API.Response)responseType.GetConstructor(Type.EmptyTypes).Invoke(new object[] {});
             response.error        = "UNKNOWN_ERROR";
             response.errorMessage = e.Message;
         }
         catch (Exception exception)
         {
             Logger.Error("Failed to determine return type for " + processorName);
             response = new ErrorRs
             {
                 errorMessage = "Failed to determine return type for " + processorName,
                 error        = "INTERNAL_SERVER_ERROR"
             };
         }
     }
     finally
     {
         SendResponse(response, request);
     }
 }
コード例 #2
0
 private void SendResponse(API.Response response, API.Request request)
 {
     response.id = request.id;
     //response.date = DateTime.Now;
     try
     {
         _messageHander.SendMessage(response);
     }
     catch (Exception e)
     {
         Logger.Info("Failed to send response for request " + request.id + " : " + e.Message);
     }
 }
コード例 #3
0
 public Response process(Request req)
 {
     var request = (PresenceChangeRq) req;
     var response = new PresenceChangeRs();
     try
     {
         _appContext.RosterManager.ProcessPresenceChange(request);
     }
     catch (Exception e)
     {
         Logger.Error("Failed to process presence change : " + e.Message,e);
         response.error = "UNKNOWN_ERROR";
         response.errorMessage = "Failed to process presence change";
     }
     return response;
 }
コード例 #4
0
        public void ProcessRequest(API.Request request)
        {
            String    requestType   = request.GetType().Name;
            String    processorName = requestType.Substring(0, requestType.Length - 2);
            Processor processor;

            if (_processors.TryGetValue(processorName, out processor))
            {
                ThreadPool.QueueUserWorkItem(delegate { RunProcessor(request, processor, processorName); });
            }
            else
            {
                Logger.Error("Failed to find a processor for " + processorName);
                SendResponse(new ErrorRs()
                {
                    error = "INTERNAL_SERVER_ERROR", errorMessage = "Failed to find a processor for " + processorName
                }, request);
            }
        }
コード例 #5
0
 public Response process(Request req)
 {
     var request = (ServerNotificationRq)req;
     var response = new ServerNotificationRs();
     try
     {
         if (ServerNotificationCode.INVALID_SESSION.ToString().Equals(request.code))
         {
             GwupeClientAppContext.CurrentAppContext.LoginManager.InvalidateSession();
         }
     }
     catch (Exception e)
     {
         Logger.Error("Failed to process server notification : " + e.Message,e);
         response.error = "UNKNOWN_ERROR";
         response.errorMessage = "Failed to process server notification";
     }
     return response;
 }
コード例 #6
0
ファイル: SubscribeProcessor.cs プロジェクト: gwupe/Gwupe
 public Response process(Request req)
 {
     SubscribeRq request = (SubscribeRq)req;
     SubscribeRs response = new SubscribeRs();
     if (request.subscribe)
     {
         TrueFalseNotification notification;
         if (request.team)
         {
             notification = new JoinTeamNotification()
             {
                 Manager = _appContext.NotificationManager,
                 Avatar =
                     request.teamElement.hasAvatar
                         ? Convert.FromBase64String(request.teamElement.avatarData)
                         : null,
                 Name = request.teamElement.name,
                 Location = request.teamElement.location,
                 Message = "Join Team?",
                 TeamUsername = request.teamElement.user,
             };
         }
         else
         {
             notification = new AddBuddyNotification()
             {
                 Manager = _appContext.NotificationManager,
                 Avatar =
                     request.userElement.hasAvatar
                         ? Convert.FromBase64String(request.userElement.avatarData)
                         : null,
                 Name = request.userElement.name,
                 Location = request.userElement.location,
                 Message = "Add Contact?",
             };
         }
         notification.AnswerHandler.Answered += delegate { ProcessAnswer(notification.AnswerHandler.Answer, request.username); };
         _appContext.NotificationManager.AddNotification(notification);
         _appContext.UIManager.Show();
     }
     return response;
 }
コード例 #7
0
ファイル: NotifyChangeProcessor.cs プロジェクト: gwupe/Gwupe
 public Response process(Request rq)
 {
     NotifyChangeRq request = (NotifyChangeRq) rq;
     NotifyChangeRs response = new NotifyChangeRs();
     if (request.changeObject.Equals(NotifyChangeRq.OBJECT_TYPE_USER))
     {
         if (request.changeType.Equals(NotifyChangeRq.CHANGE_TYPE_MOD))
         {
             try
             {
                 GwupeClientAppContext.CurrentAppContext.PartyManager.GetParty(request.changeId, true);
             }
             catch (Exception)
             {
                 Logger.Error("Failed to request a contact update for " + request.changeId);
             }
         }
     }
     return response;
 }
コード例 #8
0
ファイル: UserToUserProcessor.cs プロジェクト: gwupe/Gwupe
        public Response process(Request req)
        {
            var request = (UserToUserRequest)req;
            Engagement engagement = _appContext.EngagementManager.GetNewEngagement(request.username, request.shortCode);
            String requestTypeName = request.GetType().ToString();
            Type responseType = Type.GetType((requestTypeName.Substring(0, requestTypeName.Length - 2) + "Rs").Replace(".Request.", ".Response.") + ", Gwupe.Cloud");
            UserToUserResponse response = null;
            if (engagement == null)
            {
                try
                {
                    response = (UserToUserResponse)responseType.GetConstructor(Type.EmptyTypes).Invoke(new object[] { });
                    response.error = "INVALID_USERNAME";
                    response.errorMessage = "Username was invalid";
                }
                catch (Exception e)
                {
                    Logger.Error("Failed to instantiate a response object for " + request.GetType() + " : " + e.Message, e);
                    return new ErrorRs() { error = "INTERNAL_SERVER_ERROR", errorMessage = "Failed to determine response type" };
                }
            }
            else
            {
                // Set the interaction and shortCode
                engagement.SecondParty.ActiveShortCode = request.shortCode;
                if (engagement.Interactions.CurrentInteraction == null)
                {
                    engagement.Interactions.StartInteraction(request.interactionId);

                }
                else if (request.interactionId != null)
                {
                    engagement.Interactions.CurrentOrNewInteraction.Id = request.interactionId;
                }
                response = ProcessWithEngagement(engagement, request);
                response.shortCode = _appContext.CurrentUserManager.ActiveShortCode;
                response.username = _appContext.CurrentUserManager.CurrentUser.Username;
                response.interactionId = engagement.Interactions.CurrentInteraction.Id;
            }
            return response;
        }
コード例 #9
0
        private API.Response AwaitResponse(API.Request request)
        {
            API.Response   response;
            AutoResetEvent waitEvent = new AutoResetEvent(false);

            if (!_responseStore.ContainsKey(request.id))
            {
                _responseWaiters.Add(request.id, waitEvent);
                waitEvent.WaitOne(WaitTime);
                _responseWaiters.Remove(request.id);
            }

            if (_responseStore.ContainsKey(request.id))
            {
                response = _responseStore[request.id];
                _responseStore.Remove(request.id);
            }
            else
            {
                throw new TimeoutException("Response not received within timeout period");
            }
            return(response);
        }