Esempio n. 1
0
        /// <summary>
        /// Convert TMessage.
        /// Input: TMessage Out: System Message
        /// </summary>
        /// <param name="TMessage">kubemq Message</param>
        /// <returns>System.Messaging.Message</returns>
        public static System.Messaging.Message ConvertToSystemMessage(KubeMQ.MSMQSDK.Messages.Message Tmessage)
        {
            string FormatterType = string.Empty;

            System.Messaging.Message InnerMessage = new System.Messaging.Message(Tmessage.Body);
            InnerMessage.Label = Tmessage.Label ?? string.Empty;

            InnerMessage.BodyType = Tmessage.BodyType;

            if (Tmessage.Formatter != null)
            {
                MicrosoftFormatter microsoftFormatter = Tmessage.Formatter as MicrosoftFormatter;
                if (microsoftFormatter != null)
                {
                    FormatterType = microsoftFormatter.FormatterName ?? string.Empty;
                }
            }
            switch (FormatterType)
            {
            case "ActiveXMessageFormatter":
                InnerMessage.Formatter = new System.Messaging.ActiveXMessageFormatter();
                break;

            case "BinaryMessageFormatter":
                InnerMessage.Formatter = new System.Messaging.BinaryMessageFormatter();
                break;

            default:
                InnerMessage.Formatter = new System.Messaging.XmlMessageFormatter();
                break;
            }
            return(InnerMessage);
        }
Esempio n. 2
0
 /// <summary>
 /// Convert SystemMessage.
 /// Input: SystemMessage Out: TMessage
 /// </summary>
 /// <param name="systemMessage"></param>
 /// <returns></returns>
 public static KubeMQ.MSMQSDK.Messages.Message ConvertFromSystemMessage(System.Messaging.Message systemMessage)
 {
     KubeMQ.MSMQSDK.Messages.Message TMessage = new KubeMQ.MSMQSDK.Messages.Message();
     byte[] myBinary = new byte[systemMessage.BodyStream.Length];
     systemMessage.BodyStream.Read(myBinary, 0, (int)systemMessage.BodyStream.Length);
     TMessage.BodyStream = myBinary;
     //  TMessage.Body = systemMessage.Body ?? string.Empty;
     TMessage.Label     = systemMessage.Label ?? string.Empty;
     TMessage.Formatter = SetFormatter(systemMessage.Formatter != null ? systemMessage.Formatter.ToString() : "XmlMessageFormatter");
     TMessage.Id        = systemMessage.Id ?? "0";
     return(TMessage);
 }
Esempio n. 3
0
        /// <summary>
        /// Get request from KubeMQ and run the appropriate method
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        private Response HandleIncomingRequest(RequestReceive request)
        {
            ResultModel result = new ResultModel();

            KubeMQ.MSMQSDK.Messages.Message MessageBody = null;
            _logger.LogDebug("Received Message from {0} for: {1} ", request.ReplyChannel, request.Metadata);
            try
            {
                _logger.LogInformation("Started Converting Object to request Message");
                MSMQMeta meta = new MSMQMeta();
                meta = meta.FromString(request.Metadata);
                switch (meta.ActionType)
                {
                case "Exists":
                    result = common.Exists(meta.Path);
                    break;

                case "Create":
                    result = common.CreateQueue(meta.Path);
                    break;

                case "Purge":
                    result = common.PurgeQueue(meta.Path);
                    break;

                case "Delete":
                    result = common.DeleteQueue(meta.Path);
                    break;

                case "Send":
                    MessageBody = Converter.FromByteArray(request.Body) as KubeMQ.MSMQSDK.Messages.Message;
                    result      = common.SendToQueue(meta, MessageBody);
                    break;

                case "Peek":
                    result = common.PeekQueue(meta.Path);
                    break;

                case "RegisterPeek":
                    result = common.PeekEvent(meta.Path, meta.ChannelToReturn);
                    break;

                case "UnRegisterPeek":
                    result = common.UnregisterPeek(meta.Path);
                    break;

                case "BeginPeek":
                    result = common.BeginPeek(meta.Path);
                    break;

                case "RegisterReceive":
                    result = common.EventReceive(meta.Path, meta.ChannelToReturn);
                    break;

                case "UnRegisterRecieve":
                    result = common.UnregisterReceive(meta.Path);
                    break;

                case "BeginReceive":
                    result = common.BeginRecieve(meta.Path);
                    break;

                case "SendJson":
                    string str = System.Text.Encoding.Default.GetString(request.Body);
                    result = common.SendJsonRequestToQueue(meta, str);
                    break;
                }
                if (result.exception != null)
                {
                    return(new Response(request)
                    {
                        Metadata = "Error",
                        Body = Converter.ToByteArray(result),
                        CacheHit = false,
                        ClientID = clientID,
                        Error = result.exception.ToString(),
                        Executed = false
                    });
                }
                else
                {
                    return(new Response(request)
                    {
                        Metadata = "Ok",
                        Body = Converter.ToByteArray(result),
                        CacheHit = false,
                        ClientID = clientID,
                        Executed = true,
                        Error = "none"
                    });
                }
            }
            catch (ArgumentException ex)
            {
                _logger.LogCritical(ex.ToString());
                return(null);
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex.ToString());
                return(null);
            }
        }