Exemplo n.º 1
0
        void ServiceRequestReceived(ObjectBusMessage message)
        {
                        #if TRACE
            Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                        #endif

            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (!(message is ServiceRequestMessage))
            {
                throw new ArgumentException(string.Format("message type is not valid, must be of type {0}", typeof(ServiceRequestMessage).FullName));
            }
            ServiceRequestMessage serviceRequest = (ServiceRequestMessage)message;
            Func <ServiceAgentMode, ObjectBusSession, Action, Byte[], ServiceAgent> agentFunc;
            lock (localServices)
                lock (localServiceAgents)
                    agentFunc = localServiceAgents [localServices [serviceRequest.ServiceID]];
            Guid                   responseID = Guid.NewGuid();
            ObjectBusSession       session    = objectBus.CreateSession(responseID, SessionDisconnected);
            ServiceResponseMessage response   = new ServiceResponseMessage(responseID, serviceRequest.ID, ServiceResponseStatus.Accepted);
            ServiceAgent           agent      = agentFunc.Invoke(ServiceAgentMode.Server, session, objectBus.Flush, serviceRequest.Parameters);
            lock (sessionAgents)
                sessionAgents.Add(session.SessionID, agent);
            objectBus.SendMessage(response);
        }
Exemplo n.º 2
0
        public ServiceAgent RequestService(ServiceAnnounceMessage remoteServiceAnnouncement, byte[] parameters, Func <ServiceAgentMode, ObjectBusSession, Action, Byte[], ServiceAgent> func, Byte[] localAgentParameters)
        {
                        #if TRACE
            Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                        #endif

            lock (remoteServices)
                if (!remoteServices.Contains(remoteServiceAnnouncement))
                {
                    throw new InvalidOperationException("The provided remoteServiceAnnouncement is not valid.");
                }
            ServiceRequestMessage             request  = new ServiceRequestMessage(Guid.NewGuid(), remoteServiceAnnouncement.ID, parameters);
            System.Threading.ManualResetEvent mre      = new System.Threading.ManualResetEvent(false);
            System.Threading.ManualResetEvent mre_done = new System.Threading.ManualResetEvent(false);

            lock (requests)
                requests.Add(request.ID, new Tuple <ServiceRequestMessage, System.Threading.ManualResetEvent, System.Threading.ManualResetEvent> (request, mre, mre_done));
            objectBus.SendMessage(request);
            mre.WaitOne();
            //todo: add exception handling here
            ServiceResponseMessage response = pendingResponses [request.ID];
            lock (pendingResponses)
                pendingResponses.Remove(response.RequestID);
            Console.WriteLine("Service request accepted, remote created a session with ID {0}", response.ID);
            ServiceAgent agent = func(ServiceAgentMode.Client, objectBus.CreateSession(response.ID, SessionDisconnected), objectBus.Flush, localAgentParameters);
            sessionAgents.Add(response.ID, agent);
            mre_done.Set();
            return(agent);
        }
Exemplo n.º 3
0
 void ServiceResponseReceived(ObjectBusMessage message)
 {
                 #if TRACE
     Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                 #endif
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     if (!(message is ServiceResponseMessage))
     {
         throw new ArgumentException(string.Format("message type is not valid, must be of type {0}", typeof(ServiceResponseMessage).FullName));
     }
     ServiceResponseMessage serviceResponse = (ServiceResponseMessage)message;
     Tuple <ServiceRequestMessage, System.Threading.ManualResetEvent, System.Threading.ManualResetEvent> requestTuple = requests [serviceResponse.RequestID];
     lock (pendingResponses)
         pendingResponses.Add(serviceResponse.RequestID, serviceResponse);
     requestTuple.Item2.Set();
     requestTuple.Item3.WaitOne();
 }
Exemplo n.º 4
0
        void ServiceRequestReceived(ObjectBusMessage message)
        {
            #if TRACE
            Console.WriteLine (new System.Diagnostics.StackTrace (true).GetFrame (0));
            #endif

            if (message == null)
                throw new ArgumentNullException ("message");
            if (!(message is ServiceRequestMessage))
                throw new ArgumentException (string.Format ("message type is not valid, must be of type {0}", typeof(ServiceRequestMessage).FullName));
            ServiceRequestMessage serviceRequest = (ServiceRequestMessage)message;
            Func<ServiceAgentMode , ObjectBusSession, Action, Byte[], ServiceAgent> agentFunc;
            lock (localServices)
            lock (localServiceAgents)
                agentFunc = localServiceAgents [localServices [serviceRequest.ServiceID]];
            Guid responseID = Guid.NewGuid ();
            ObjectBusSession session = objectBus.CreateSession (responseID, SessionDisconnected);
            ServiceResponseMessage response = new ServiceResponseMessage (responseID, serviceRequest.ID, ServiceResponseStatus.Accepted);
            ServiceAgent agent = agentFunc.Invoke (ServiceAgentMode.Server, session, objectBus.Flush, serviceRequest.Parameters);
            lock (sessionAgents)
                sessionAgents.Add (session.SessionID, agent);
            objectBus.SendMessage (response);
        }