Exemplo n.º 1
0
        /// <summary>
        /// Retrieve the result of the execution of a Command. Two alternative possibilities:
        /// 1) Give the result back to client.
        /// 2) Forward the command.
        /// </summary>
        /// <param name="iAsyncResult">Represent the object which is available after the
        /// asynchronous invocation of Execute(). It gives access to all state information.</param>
        public void ProcessResult(IAsyncResult iAsyncResult)
        {
            /** Retrieve the pair Command-Result. */
            Command command = (Command)iAsyncResult.AsyncState;
            Result  result  = command.EndExecute(iAsyncResult);

            /** Check if the Command has to be forwarded. */
            ForwardRequiredResult checkForward = result as ForwardRequiredResult;

            if (checkForward != null)   //Forward the command
            {
                string service = checkForward.Destination;
                ForwardCommand(command, service, receiver.BaseForwardAddress + receiver.NodeName);
            }
            else    //Give the result to client
            {
                if (debug)
                {
                    TimeSpan totalTime = DateTime.Now.Subtract(command.Timestamp);
                    Console.WriteLine("{0} Total time for {1}: {2}", LogTimestamp, command.GetType().Name, totalTime.TotalMilliseconds);
                }

                if (IsMobileCommand(command.CommandID))
                {
                    Console.WriteLine("\n{0} Ready to send the result back to Mobile", LogTimestamp);
                    mobile.AddMobileResult(command.CommandID, result);
                }
                else
                {
                    IDarPoolingCallback client = ExtractClient(command.CommandID);
                    ReturnResultToClient(result, client);
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Setup a new UserNodeCore.
 /// </summary>
 /// <param name="clientNode">represents the UserNode and its settings.</param>
 public UserNodeCore(UserNode clientNode)
 {
     results        = new List <SearchTripResult>();
     state          = new UnjointState();
     userNode       = clientNode;
     clientCallback = new ClientCallback();
     ((ClientCallback)clientCallback).Parent = this;
     resultCallback += new ResultReceiveHandler(onResultReceive);
 }
Exemplo n.º 3
0
 private void AddCommandClient(string commandID, IDarPoolingCallback client)
 {
     commandClientLock.EnterWriteLock();
     try
     {
         commandClient.Add(commandID, client);
     }
     finally
     {
         commandClientLock.ExitWriteLock();
     }
 }
Exemplo n.º 4
0
 private IDarPoolingCallback ExtractClient(string commandID)
 {
     commandClientLock.EnterWriteLock();
     try
     {
         IDarPoolingCallback client = commandClient[commandID];
         commandClient.Remove(commandID);
         return(client);
     }
     finally
     {
         commandClientLock.ExitWriteLock();
     }
 }
Exemplo n.º 5
0
        private void ReturnResultToClient(Result finalResult, IDarPoolingCallback destination)
        {
            /** Apply changes on the service. */
            RegisterResult(finalResult);

            if (debug)
            {
                Console.WriteLine("{0} {1} return a {2}", LogTimestamp, receiver.NodeName.ToUpper(), finalResult.GetType().Name);
            }

            destination.GetResult(finalResult);

            bool closeConnection = IsFinalInteraction(finalResult);

            if (closeConnection)
            {
                Console.WriteLine("{0} End of communication with client.", LogTimestamp);
                ((IClientChannel)destination).Close();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Execute request of clients.
        /// </summary>
        /// <param name="command">The Command object, sent by a client</param>
        public void HandleDarPoolingRequest(Command command)
        {
            if (debug)
            {
                Console.WriteLine("\n{0} {1} node received {2}", LogTimestamp, receiver.NodeName.ToUpper(), command.GetType());
            }

            /** Assign a GUID to the command. */
            command.CommandID = generateGUID();
            /** Save information about the client that has sent the command. */
            IDarPoolingCallback client = OperationContext.Current.GetCallbackChannel <IDarPoolingCallback>();

            commandClient.Add(command.CommandID, client);

            /** Set a ServiceNodeCore as the receiver of the command and execute the command. */
            command.Timestamp = DateTime.Now;
            command.Receiver  = receiver;
            command.Callback  = new AsyncCallback(ProcessResult);
            command.Execute();
        }
Exemplo n.º 7
0
        /// <summary>
        /// IDarPoolingForwarding method. The service node obtain the result of the forwarded command.
        /// </summary>
        /// <param name="forwardedCommand"></param>
        /// <param name="finalResult"></param>
        public void ReturnFinalResult(Result result, Command originalCommand)
        {
            if (IsFwdCommand(originalCommand.CommandID))
            {
                string senderAddress = ExtractService(originalCommand.CommandID);
                // Get ready to contact the sender Service node.
                BasicHttpBinding myBinding  = new BasicHttpBinding();
                EndpointAddress  myEndpoint = new EndpointAddress(senderAddress);
                ChannelFactory <IDarPoolingForwarding> myChannelFactory = new ChannelFactory <IDarPoolingForwarding>(myBinding, myEndpoint);
                IDarPoolingForwarding service = myChannelFactory.CreateChannel();

                // Give the result back to the the sender Service node.
                service.ReturnFinalResult(result, originalCommand);
                // Close channel.
                ((IClientChannel)service).Close();
                myChannelFactory.Close();
            }
            else
            {
                if (debug)
                {
                    TimeSpan totalTime = DateTime.Now.Subtract(originalCommand.Timestamp);
                    Console.WriteLine("{0} Total time for {1}: {2}", LogTimestamp, originalCommand.GetType().Name, totalTime.TotalMilliseconds);
                }
                if (IsMobileCommand(originalCommand.CommandID))
                {
                    Console.WriteLine("\n{0} Ready to send the result back to Mobile", LogTimestamp);
                    mobile.AddMobileResult(originalCommand.CommandID, result);
                    //mobile.
                }
                else
                {
                    IDarPoolingCallback client = ExtractClient(originalCommand.CommandID);
                    ReturnResultToClient(result, client);
                }
            }
        }
        private void ReturnResultToClient(Result finalResult, IDarPoolingCallback destination)
        {
            /** Apply changes on the service. */
            RegisterResult(finalResult);

            if (debug)
                Console.WriteLine("{0} {1} return a {2}",LogTimestamp,receiver.NodeName.ToUpper(), finalResult.GetType().Name);

            destination.GetResult(finalResult);

            bool closeConnection = IsFinalInteraction(finalResult);
            if (closeConnection)
            {
                Console.WriteLine("{0} End of communication with client.",LogTimestamp);
                ((IClientChannel)destination).Close();
            }
        }
 private void AddCommandClient(string commandID, IDarPoolingCallback client)
 {
     commandClientLock.EnterWriteLock();
     try
     {
         commandClient.Add(commandID, client);
     }
     finally
     {
         commandClientLock.ExitWriteLock();
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Setup a new UserNodeCore.
 /// </summary>
 /// <param name="clientNode">represents the UserNode and its settings.</param>
 public UserNodeCore(UserNode clientNode)
 {
     results = new List<SearchTripResult>();
     state = new UnjointState();
     userNode = clientNode;
     clientCallback = new ClientCallback();
     ((ClientCallback) clientCallback).Parent = this;
     resultCallback += new ResultReceiveHandler(onResultReceive);
 }