Beispiel #1
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);
        }
Beispiel #2
0
 void ServiceAnnouncementReceived(ObjectBusMessage message)
 {
                 #if TRACE
     Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                 #endif
     if (message == null)
     {
         throw new ArgumentNullException("message");
     }
     if (!(message is ServiceAnnounceMessage))
     {
         throw new ArgumentException(string.Format("message type is not valid, must be of type {0}", typeof(ServiceAnnounceMessage).FullName));
     }
     ServiceAnnounceMessage serviceAnnouncement = (ServiceAnnounceMessage)message;
     lock (remoteServices)
         remoteServices.Add(serviceAnnouncement);
 }
Beispiel #3
0
        public void AnnounceService(ServiceAnnounceMessage serviceAnnouncement, Func <ServiceAgentMode, ObjectBusSession, Action, byte[], ServiceAgent> func)
        {
                        #if TRACE
            Console.WriteLine(new System.Diagnostics.StackTrace(true).GetFrame(0));
                        #endif

            if (serviceAnnouncement == null)
            {
                throw new ArgumentNullException("serviceAnnouncement");
            }
            if (func == null)
            {
                throw new ArgumentNullException("func");
            }
            lock (localServices)
                lock (localServiceAgents) {
                    localServices.Add(serviceAnnouncement.ID, serviceAnnouncement);
                    localServiceAgents.Add(serviceAnnouncement, func);
                }
            objectBus.SendMessage(serviceAnnouncement);
        }
Beispiel #4
0
        public void AnnounceService(ServiceAnnounceMessage serviceAnnouncement, Func<ServiceAgentMode , ObjectBusSession, Action, byte[], ServiceAgent> func)
        {
            #if TRACE
            Console.WriteLine (new System.Diagnostics.StackTrace (true).GetFrame (0));
            #endif

            if (serviceAnnouncement == null)
                throw new ArgumentNullException ("serviceAnnouncement");
            if (func == null)
                throw new ArgumentNullException ("func");
            lock (localServices)
            lock (localServiceAgents) {
                localServices.Add (serviceAnnouncement.ID, serviceAnnouncement);
                localServiceAgents.Add (serviceAnnouncement, func);
            }
            objectBus.SendMessage (serviceAnnouncement);
        }
Beispiel #5
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;
        }