Exemplo n.º 1
0
        protected static ServermoduleID RegisterServermoduleByTargetType(TargetType target, ConnectionInfo connInfo)
        {
            if (null == connInfo)
            {
                throw new Exception("Does not allow null");
            }

            ServerMethod method = null;

            if (TargetType.SlaveOwnerServermodule.Equals(target)) //TODO expand
            {
                method = new RegisterSlaveOwnerServermoduleMethod()
                {
                    ConnectionInfo = connInfo
                };
            }

            //socket only used for getting the servermodule ID
            var setupSocket = new RequestSocket();

            setupSocket.Connect("tcp://" + net_mq_util.NetMqUtil.SERVER_MODULE_IP + ":" + net_mq_util.NetMqUtil.SERVER_MODULE_PORT);



            var localCallID = new Random().Next();

            if (null == method)
            {
                throw new Exception();
            }
            var encodedMethod = net_mq_encoder.NetMqEncoder.GenerateServerModuleMethodMessage(new ServermoduleID()
            {
                ID = ProtocolConstants.SERVERMODULE_ID_NOT_YET_ASSIGNED
            }, new CallID()
            {
                ID = localCallID
            }, method);

            setupSocket.SendMultipartMessage(encodedMethod);

            var response = setupSocket.ReceiveMultipartMessage();

            setupSocket.Close();

            var decodedReponse = net_mq_decoder.NetMqDecoder.DecodeResponse <ServermoduleID>(response);

            if (
                ProtocolConstants.SERVERMODULE_ID_NOT_YET_ASSIGNED.Equals(decodedReponse.Item2.Item1.ID) &&
                localCallID.Equals(decodedReponse.Item2.Item2.ID)
                )
            {
                return(decodedReponse.Item1);
            }
            else
            {
                throw new MethodFailedException("The SlaveOwner Setup method failed");
            }
        }
Exemplo n.º 2
0
        protected static RegisterSlaveOwnerServermoduleMethod DecodeServerMethodRegisterSlaveOwnerServermodule(NetMQMessage message)
        {
            var result = new RegisterSlaveOwnerServermoduleMethod();

            //result.MethodId = methoId;

            if (1 != message.FrameCount)
            {
                throw new MethodFailedException("Not the right amount of frames");
            }

            var str = message.Pop().ConvertToString();

            result.ConnectionInfo = ConvertToObjectFromJsonString <ConnectionInfo>(str);

            return(result);
        }