Example #1
0
        /// <summary>
        ///   This dispatcher wraps the dispatch of the remote call in a Task (by continuing on the Connect()) which allows the client to continue working asynchronously while the service is doing it's thing.
        /// </summary>
        /// <param name="binder"> </param>
        /// <param name="args"> </param>
        /// <param name="result"> </param>
        /// <returns> </returns>
        public override bool TryInvokeMember(InvokeMemberBinder binder, object[] args, out object result)
        {
            if (PackageManagerResponseImpl.EngineRestarting)
            {
                // don't send more calls until it's back.
                EngineServiceManager.WaitForStableMoment();
            }

            result = Connect().Continue(() => PerformCall(binder, args));
            return(true);
        }
Example #2
0
        private PackageManagerResponseImpl PerformCall(InvokeMemberBinder binder, object[] args)
        {
            using (var eventQueue = new ManualEventQueue()) {
                // create return message handler
                var responseHandler = new PackageManagerResponseImpl();
                CurrentTask.Events += new GetCurrentRequestId(() => "" + Task.CurrentId);
                // unhook the old one if it's there.
                responseHandler.Clear();

                // send OG message here!
                object callResult;
                base.TryInvokeMember(binder, args, out callResult);

                // will return when the final message comes thru.
                eventQueue.StillWorking = true;

                while (eventQueue.StillWorking && eventQueue.ResetEvent.WaitOne())
                {
                    eventQueue.ResetEvent.Reset();
                    while (eventQueue.Count > 0)
                    {
                        if (!Event <GetResponseDispatcher> .RaiseFirst().DispatchSynchronous(eventQueue.Dequeue()))
                        {
                            eventQueue.StillWorking = false;
                        }
                    }
                }

                if (PackageManagerResponseImpl.EngineRestarting)
                {
                    Logger.Message("Going to try and re issue the call.");
                    // Disconnect();
                    // the service is going to restart, let's call TryInvokeMember again.
                    EngineServiceManager.WaitForStableMoment();
                    Connect().Wait();
                    return(PerformCall(binder, args));
                }

                // this returns the final response back via the Task<*>
                return(responseHandler);
            }
        }