Esempio n. 1
0
 /// <summary>
 /// Receive request from the worker on either :Peek event or Receive event
 /// </summary>
 /// <param name="request"></param>
 /// <returns></returns>
 private Response HandleIncomingRequest(RequestReceive request)
 {
     ResultModel resultModel = Converter.FromByteArray(request.Body) as ResultModel;
     switch (request.Metadata)
     {
         case "PeekOK":
             PeekCompletedEventArgs PeekArgs = new PeekCompletedEventArgs();
             PeekArgs.Message = resultModel.message;
             peekCompleted?.Invoke(this, PeekArgs);
             break;
         case "RecieveOK":
             ReceiveCompletedEventArgs receiveCompletedEventArgs = new ReceiveCompletedEventArgs();
             receiveCompletedEventArgs.Message= resultModel.message;
             receiveCompleted?.Invoke(this, receiveCompletedEventArgs);
             break;
         default:
             break;
     }
     return new Response(request)
     {
         Metadata = "OK",
         Body = Converter.ToByteArray("OK"),
         CacheHit = false,
         ClientID = $"MSMQWorker{Path}",
         Timestamp=DateTime.UtcNow,
         Executed=true,
         Error=""
     };
 }
        //การตรวจสอบเวลา
        public static string RequestTimeCheck(RequestReceive source)
        {
            XNamespace soap = "http://schemas.xmlsoap.org/soap/envelope/";
            XNamespace wsa  = "http://www.w3.org/2005/08/addressing";


            XElement soapElement = new XElement(soap + "Envelope", new XAttribute(XNamespace.Xmlns + "SOAP-ENV", soap),
                                                new XElement(soap + "Header",
                                                             new XElement(wsa + "MessageID", source.MessageID ?? "", new XAttribute(XNamespace.Xmlns + "wsa", wsa)),
                                                             new XElement(wsa + "To", source.To ?? "http://dev.scp1.ecms.dga.or.th/ecms-ws01/service2", new XAttribute(XNamespace.Xmlns + "wsa", wsa))),
                                                new XElement(soap + "Body",
                                                             new XElement("TimeCheckRequest")));

            return(Util.ConvertXmlFormat(soapElement));
        }
Esempio n. 3
0
        private Response HandleRpcRequest(RequestReceive eventReceive, string id)
        {
            try
            {
                if (OnRpcRequest != null)
                {
                    foreach (var inv in OnRpcRequest.GetInvocationList())
                    {
                        var result = ((Task <string>)inv
                                      .DynamicInvoke(Encoding.UTF8.GetString(eventReceive.Body),
                                                     eventReceive.Channel))?.ConfigureAwait(false)
                                     .GetAwaiter()
                                     .GetResult();
                        if (result != null)
                        {
                            return(new Response(eventReceive)
                            {
                                Body = Encoding.UTF8.GetBytes(result),
                                CacheHit = false,
                                ClientID = $"{id}{Guid.NewGuid()}",
                                Error = "",
                                Executed = true,
                                Timestamp = DateTime.Now
                            });
                        }
                    }
                }

                return(new Response(eventReceive)
                {
                    Error = "Cant find rpc agent",
                    ClientID = $"{id}{Guid.NewGuid()}",
                    Body = new byte[0]
                });
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Can`t process incoming event");
                return(new Response(eventReceive)
                {
                    Error = e.ToString(),
                    ClientID = $"{id}{Guid.NewGuid()}",
                    Body = new byte[0]
                });
            }
        }
        //การขอข้อมูลหน่วยงาน
        public static string RequestGetOrganizationList(RequestReceive source)
        {
            XNamespace soap = "http://schemas.xmlsoap.org/soap/envelope/";
            XNamespace wsa  = "http://www.w3.org/2005/08/addressing";

            XNamespace rsm = "urn:th:gov:egif:data:standard:ReuseableAggregateBusinessInformaionEntity:1";
            XNamespace ram = "urn:th:gov:egif:data:standard:GovernmentDocument:1.0";

            XElement soapElement = new XElement(soap + "Envelope", new XAttribute(XNamespace.Xmlns + "SOAP-ENV", soap),
                                                new XElement(soap + "Header",
                                                             new XElement(wsa + "MessageID", source.MessageID ?? "", new XAttribute(XNamespace.Xmlns + "wsa", wsa)),
                                                             new XElement(wsa + "To", source.To ?? "http://dev.scp1.ecms.dga.or.th/ecms-ws01/service2", new XAttribute(XNamespace.Xmlns + "wsa", wsa))),
                                                new XElement(soap + "Body",
                                                             new XElement("GetOrganizationList")));

            return(Util.ConvertXmlFormat(soapElement));
        }
Esempio n. 5
0
        private Response HandleIncomingRequests(RequestReceive request)
        {
            if (request != null)
            {
                string strMsg = string.Empty;
                object body   = KubeMQ.SDK.csharp.Tools.Converter.FromByteArray(request.Body);

                logger.LogInformation($"Subscriber Received request: Metadata:'{request.Metadata}', Channel:'{request.Channel}', Body:'{strMsg}'");
            }
            Response response = new Response(request)
            {
                Body      = Converter.ToByteArray("OK"),
                CacheHit  = false,
                Error     = "None",
                ClientID  = this.ClientID,
                Executed  = true,
                Metadata  = "OK",
                Timestamp = DateTime.UtcNow,
            };

            return(response);
        }
Esempio n. 6
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);
            }
        }