Esempio n. 1
0
        public void TestRemoteMethodCallSerialization()
        {
            var call = new RemoteMethodCall();

            call.ComponentName = "component";
            call.CallId        = Guid.NewGuid();
            call.MethodName    = "sampleMethod";
            call.Parameters    = new List <object> {
                1, 2, 3
            };

            var xml = call.Serialize();


            var roundtrip = new RemoteMethodCall();

            Assert.IsTrue(roundtrip.Validate(xml));
            roundtrip.Deserialize(xml);


            Assert.IsNotNull(roundtrip);
            Assert.AreEqual <Guid>(call.CallId, roundtrip.CallId);
            Assert.AreEqual <string>(call.ComponentName, roundtrip.ComponentName);
            Assert.AreEqual <string>(call.MethodName, roundtrip.MethodName);
            Assert.AreEqual <int>(call.Parameters.Count(), roundtrip.Parameters.Count());

            int count = call.Parameters.Count();

            for (int i = 0; i < count; i++)
            {
                Assert.AreEqual <int>((int)call.Parameters.Skip(i).First(), (int)roundtrip.Parameters.Skip(i).First());
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Builds an MethodCall using IMethodCallMessage.
        /// </summary>
        /// <param name="msg">Information, to create a MethodCallRequest</param>
        /// <returns>A new instance of methodCallrequest</returns>
        private MethodCallMessage ToMethodCallRequest(IMethodCallMessage msg)
        {
            Guid id = Guid.NewGuid();

            string methodName = msg.MethodName;
            Dictionary <string, string> metaData = new Dictionary <string, string>();

            // The structure is always domain.DOMAINTYPE.events
            metaData.Add("serviceId", "domain." + DomainName + ".events");

            // Arbitrary string, maybe not necessary
            metaData.Add("contextId", ContextId);
            List <string> classes = new List <string>();

            foreach (object arg in msg.Args)
            {
                if (arg != null)
                {
                    LocalType type = new LocalType(arg.GetType());
                    classes.Add(type.RemoteTypeFullName);
                }
                else
                {
                    classes.Add(null);
                }
            }

            RemoteMethodCall call             = RemoteMethodCall.CreateInstance(methodName, msg.Args, metaData, classes, null);
            BeanDescription  authentification = BeanDescription.CreateInstance(AuthenificationClass);

            authentification.Data.Add("value", Password);
            MethodCallMessage message = MethodCallMessage.CreateInstance(Username, authentification, call, id.ToString(), true, String.Empty);

            return(message);
        }
Esempio n. 3
0
 /// <summary>
 /// Creates a new instance of Message
 /// </summary>
 /// <param name="methodCall">MethodCall</param>
 /// <param name="callId">CallId</param>
 /// <param name="answer">Answer</param>
 /// <param name="destination">Destination</param>
 /// <returns>returns a new Message of CreateInstance</returns>
 public static Message createInstance(RemoteMethodCall methodCall, string callId, bool answer, string destination)
 {
     Message instance = new Message();
     instance.methodCall = methodCall;
     instance.callId = callId;
     instance.answer = answer;
     instance.destination = destination;
     return instance;
 }
Esempio n. 4
0
        public void TestMarshallingListThatImplementsICollection()
        {
            String           value       = "Foo bar";
            RemoteMethodCall description = new RemoteMethodCall();

            description.Classes = new List <String>()
            {
                value
            };
            RemoteMethodCall descriptionUnmarshalled = marshaller.UnmarshallObject <RemoteMethodCall>(marshaller.MarshallObject(description));

            Assert.IsTrue(descriptionUnmarshalled.Classes.Contains(value));
        }
Esempio n. 5
0
        /// <summary>
        /// Creates an Proxy on the bus.
        /// </summary>
        public override void CreateRemoteProxy()
        {
            Logger.Info("Create a new connector");
            IDictionary <string, string> metaData = new Dictionary <string, string>();

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

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

            classes.Add(localType.RemoteTypeFullName);
            classes.Add("org.openengsb.core.api.model.ConnectorDescription");

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

            Org.Openengsb.Loom.CSharp.Bridge.OpenEngSB300.Remote.RemoteObjects.ConnectorDescription connectorDescription = new Org.Openengsb.Loom.CSharp.Bridge.OpenEngSB300.Remote.RemoteObjects.ConnectorDescription();
            connectorDescription.Attributes.Add("serviceId", ConnectorId);
            connectorDescription.Attributes.Add("portId", CreationPort);
            connectorDescription.Attributes.Add("destination", Destination);
            connectorDescription.ConnectorType = CreationConnectorType;
            connectorDescription.DomainType    = DomainName;

            args.Add(RegisterId);
            args.Add(connectorDescription);

            RemoteMethodCall creationCall = RemoteMethodCall.CreateInstance(CreationMethodName, 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 secureRequest = MethodCallMessage.CreateInstance(Username, autinfo, creationCall, id, true, String.Empty);
            IOutgoingPort     portOut       = new JmsOutgoingPort(destinationinfo.FullDestination, ExceptionHandler, ConnectorId);
            string            request       = Marshaller.MarshallObject(secureRequest);

            portOut.Send(request, id);
            WaitAndCheckAnswer(destinationinfo, id);
            RegistrationProcess = ERegistration.CREATED;
            portOut.Close();
            Logger.Info("Create done");
        }
Esempio n. 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()));
        }
Esempio n. 7
0
        /// <summary>
        /// Creates an Proxy on the bus.
        /// </summary>
        public override void UnRegisterConnector()
        {
            if (!RegistrationProcess.Equals(ERegistration.REGISTERED))
            {
                return;
            }

            Logger.Info("Unregister the connector with ID: " + ConnectorId);
            IDictionary <string, string> metaData = new Dictionary <string, string>();

            metaData.Add("serviceId", CreationRegistration);
            metaData.Add("contextId", ContextId);
            LocalType      localType = new LocalType(typeof(String));
            IList <string> classes   = new List <string>();

            classes.Add(localType.RemoteTypeFullName);

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

            args.Add(ConnectorId);

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

            JmsDestination destinationinfo = new JmsDestination(Destination);

            destinationinfo.Queue = CreationQueue;

            BeanDescription autinfo = BeanDescription.CreateInstance(AuthentificationClass);

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

            portOut.Send(request, id);
            WaitAndCheckAnswer(destinationinfo, id);
            if (RegistrationProcess.Equals(ERegistration.REGISTERED))
            {
                RegistrationProcess = ERegistration.CREATED;
            }

            portOut.Close();
            Logger.Info("Unregister done");
        }
Esempio n. 8
0
        public void TestRemoteMethodCallSerialization_MissingCallIdElement()
        {
            var call = new RemoteMethodCall();

            call.ComponentName = "component";
            call.CallId        = Guid.NewGuid();
            call.MethodName    = "sampleMethod";
            call.Parameters    = new List <object> {
                1, 2, 3
            };

            var xml = call.Serialize();

            xml.Element(XName.Get("CallId", xml.Name.NamespaceName)).Remove();

            var roundtrip = new RemoteMethodCall();

            Assert.IsFalse(roundtrip.Validate(xml));
        }
Esempio n. 9
0
        public void TestRemoteMethodCallSerialization_NoParameters()
        {
            var call = new RemoteMethodCall();

            call.ComponentName = "component";
            call.CallId        = Guid.NewGuid();
            call.MethodName    = "sampleMethod";

            var xml = call.Serialize();


            var roundtrip = new RemoteMethodCall();

            Assert.IsTrue(roundtrip.Validate(xml));
            roundtrip.Deserialize(xml);


            Assert.IsNotNull(roundtrip);
            Assert.AreEqual <Guid>(call.CallId, roundtrip.CallId);
            Assert.AreEqual <string>(call.ComponentName, roundtrip.ComponentName);
            Assert.AreEqual <string>(call.MethodName, roundtrip.MethodName);
        }
        private string GetJsonExampleString()
        {
            BeanDescription  bean     = BeanDescription.CreateInstance("classname");
            RemoteMethodCall remoteMC = RemoteMethodCall.CreateInstance(
                "methodName",
                new List <Object>()
            {
                "Test1"
            },
                new Dictionary <String, String>(),
                new List <String>()
            {
                "Classes"
            },
                new List <String>
            {
                "Real"
            });
            MethodCallMessage message = MethodCallMessage.CreateInstance("principal", bean, remoteMC, "123", false, "TestCase");

            return(marshaller.MarshallObject(message));
        }
Esempio n. 11
0
        /// <summary>
        /// Disconnect the Connector from XLink
        /// </summary>
        public override void DisconnectFromXLink(String hostId)
        {
            Logger.Info("Disconnect connector from xlink with the serviceId: " + ConnectorId);
            IDictionary <string, string> metaData = new Dictionary <string, string>();

            metaData.Add("serviceId", CreationServiceId);
            metaData.Add("contextId", ContextId);
            LocalType      localType = new LocalType(typeof(String));
            IList <String> classes   = new List <String>();

            classes.Add(localType.RemoteTypeFullName);
            classes.Add(localType.RemoteTypeFullName);
            IList <object> args = new List <object>();

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

            RemoteMethodCall deletionCall = RemoteMethodCall.CreateInstance(RemoveXlinkConnectorMethodName, args, metaData, classes, null);

            String          id = Guid.NewGuid().ToString();
            BeanDescription authentification = BeanDescription.CreateInstance(AuthentificationClass);

            authentification.Data.Add("value", Password);
            MethodCallMessage callRequest = MethodCallMessage.CreateInstance(Username, authentification, deletionCall, id, true, String.Empty);

            JmsDestination destinationinfo = new JmsDestination(Destination);

            destinationinfo.Queue = CreationQueue;

            IOutgoingPort portOut = new JmsOutgoingPort(destinationinfo.FullDestination, ExceptionHandler, ConnectorId);
            string        request = Marshaller.MarshallObject(callRequest);

            portOut.Send(request, id);
            WaitAndCheckAnswer(destinationinfo, id);
            portOut.Close();
            RegistrationProcess = ERegistration.REGISTERED;
            Logger.Info("XLink is disconnected");
        }
Esempio n. 12
0
        public void CallFunction(RemoteMethodCall call)
        {
            var message = MessageBuilder.GetMessage(call, call.AssociatedNetworkGuid);

            UdpConnectHandler.SendMessage(message);
        }