Example #1
0
        /// <summary>
        /// Builds an return message.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="returnValue"></param>
        /// <param name="correlationId"></param>
        /// <returns></returns>
        private MethodResultMessage CreateMethodReturn(ReturnType type, object returnValue, string correlationId)
        {
            MethodResult methodResult = new MethodResult();

            methodResult.Type = type;
            methodResult.Arg  = returnValue;

            if (returnValue == null)
            {
                methodResult.ClassName = "null";
            }
            else
            {
                if (!type.Equals(ReturnType.Exception))
                {
                    methodResult.ClassName = new LocalType(returnValue.GetType()).RemoteTypeFullName;
                }
                else
                {
                    methodResult.ClassName = returnValue.GetType().ToString();
                }
            }

            methodResult.MetaData = new Dictionary <string, string>();
            return(MethodResultMessage.CreateInstance(methodResult, correlationId));
        }
Example #2
0
        /// <summary>
        /// Calls a method according to MethodCall.
        /// </summary>
        /// <param name="methodCall">Description of the call.</param>
        /// <returns></returns>
        private MethodResultMessage CallMethod(MethodCallMessage request)
        {
            object returnValue = null;

            try
            {
                returnValue = InvokeMethod(request.MethodCall);
            }
            catch (BridgeException bridgeEx)
            {
                return(CreateMethodReturn(ReturnType.Exception, bridgeEx, request.CallId));
            }

            MethodResultMessage returnMsg = null;

            if (returnValue == null)
            {
                returnMsg = CreateMethodReturn(ReturnType.Void, null, request.CallId);
            }
            else
            {
                returnMsg = CreateMethodReturn(ReturnType.Object, returnValue, request.CallId);
            }

            return(returnMsg);
        }
Example #3
0
        private MethodResultMessage WaitAndCheckAnswer(JmsDestination destinationinfo, String id)
        {
            IIncomingPort       portIn = new JmsIncomingPort(JmsDestination.CreateDestinationString(destinationinfo.Host, id), ExceptionHandler, ConnectorId);
            string              reply  = portIn.Receive();
            MethodResultMessage result = Marshaller.UnmarshallObject <MethodResultMessage>(reply);

            portIn.Close();
            if (result.Result.Type == ReturnType.Exception)
            {
                throw new OpenEngSBException("Remote Exception while Registering service proxy", new Exception(result.Result.ClassName));
            }

            return(result);
        }
Example #4
0
        /// <summary>
        /// Will be invoked when a call to the proxy has been made.
        /// </summary>
        /// <param name="msg">Message, which contains the Parameters of the Method</param>
        /// <returns>Received Method</returns>
        public override IMessage Invoke(IMessage msg)
        {
            IMethodCallMessage callMessage       = msg as IMethodCallMessage;
            MethodCallMessage  methodCallRequest = ToMethodCallRequest(callMessage);
            string             methodCallMsg     = Marshaller.MarshallObject(methodCallRequest);
            IOutgoingPort      portOut           = new JmsOutgoingPort(JmsDestination.CreateDestinationString(Host, HostQueue), Exceptionhandler, ConnectorId);

            portOut.Send(methodCallMsg, methodCallRequest.CallId);
            IIncomingPort       portIn          = new JmsIncomingPort(JmsDestination.CreateDestinationString(Host, methodCallRequest.CallId), Exceptionhandler, ConnectorId);
            string              methodReturnMsg = portIn.Receive();
            MethodResultMessage methodReturn    = Marshaller.UnmarshallObject <MethodResultMessage>(methodReturnMsg);

            return(ToMessage(methodReturn.Result, callMessage));
        }
Example #5
0
        /// <summary>
        /// Blocks an waits for messages.
        /// </summary>
        public override void Listen()
        {
            try
            {
                while (IsEnabled)
                {
                    String textMsg;
                    textMsg = PortIn.Receive();

                    if (textMsg == null)
                    {
                        continue;
                    }

                    MethodCallMessage methodCallRequest = Marshaller.UnmarshallObject <MethodCallMessage>(textMsg);
                    if (methodCallRequest.MethodCall.Args == null)
                    {
                        methodCallRequest.MethodCall.Args = new List <Object>();
                    }

                    MethodResultMessage methodReturnMessage = CallMethod(methodCallRequest);
                    if (methodCallRequest.Answer)
                    {
                        string         returnMsg = Marshaller.MarshallObject(methodReturnMessage);
                        JmsDestination dest      = new JmsDestination(Destination);
                        IOutgoingPort  portOut   = new JmsOutgoingPort(JmsDestination.CreateDestinationString(dest.Host, methodCallRequest.CallId), ExceptionHandler, ConnectorId);
                        portOut.Send(returnMsg);
                        portOut.Close();
                        if (methodReturnMessage.Result.Type.Equals(ReturnType.Exception))
                        {
                            throw new BridgeException("A exception occurs, while the message has been created", new BridgeException(methodReturnMessage.Result.Arg.ToString()));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                if (IsEnabled)
                {
                    ExceptionHandler.Changed += delegate(object[] obj)
                    {
                        Listen();
                        return(null);
                    };
                    ExceptionHandler.HandleException(e);
                }
            }
        }
Example #6
0
        /// <summary>
        /// Connect a connector to xlink
        /// </summary>
        /// <param name="ServiceId"></param>
        /// <param name="hostId"></param>
        /// <param name="toolName"></param>
        /// <param name="modelsToViews"></param>
        /// <returns></returns>
        public override XLinkUrlBlueprint ConnectToXLink(string toolName, String hostId, ModelToViewsTuple[] modelsToViews)
        {
            Logger.Info("Create a Xlink connector");
            IDictionary <string, string> metaData = new Dictionary <string, string>();

            metaData.Add("serviceId", CreationServiceId);
            metaData.Add("contextId", ContextId);

            IList <string> classes   = new List <string>();
            LocalType      localType = new LocalType(typeof(String));

            classes.Add(localType.RemoteTypeFullName);
            classes.Add(localType.RemoteTypeFullName);
            classes.Add(localType.RemoteTypeFullName);
            localType = new LocalType(modelsToViews.GetType());
            classes.Add(localType.RemoteTypeFullName);

            IList <object> args = new List <object>();

            args.Add(RegisterId);
            args.Add(hostId);
            args.Add(toolName);
            args.Add(modelsToViews);

            RemoteMethodCall creationCall = RemoteMethodCall.CreateInstance(XlinkMethodName, args, metaData, classes, null);

            JmsDestination destinationinfo = new JmsDestination(Destination);

            destinationinfo.Queue = CreationQueue;
            String          id      = Guid.NewGuid().ToString();
            BeanDescription autinfo = BeanDescription.CreateInstance(AuthentificationClass);

            autinfo.Data.Add("value", Password);
            MethodCallMessage methodCall = MethodCallMessage.CreateInstance(Username, autinfo, creationCall, id, true, String.Empty);
            IOutgoingPort     portOut    = new JmsOutgoingPort(destinationinfo.FullDestination, ExceptionHandler, ConnectorId);
            string            request    = Marshaller.MarshallObject(methodCall);

            portOut.Send(request, id);
            portOut.Close();
            MethodResultMessage result = WaitAndCheckAnswer(destinationinfo, id);

            RegistrationProcess = ERegistration.XLINK;
            Logger.Info("Create done");
            return(Marshaller.UnmarshallObject <XLinkUrlBlueprint>(result.Result.Arg.ToString()));
        }
 /// <summary>
 /// Creates a new instance of MethodResultMessage
 /// </summary>
 /// <param name="message">Message</param>
 /// <returns>Returns a new instance of MethodResultMessage</returns>
 public static MethodResultMessage CreateInstance(MessageResult message)
 {
     MethodResultMessage instance=new MethodResultMessage();
     instance.message = message;
     return instance;
 }