Beispiel #1
0
 private void Send(ApplicationPort fromPort, ApplicationPort toPort, string toServerIP, string toSiteQueueName, string jsonMsg, bool multicast = false)
 {
     if (this.client != null)
     {
         this.client.Send(fromPort, toPort, toServerIP, toSiteQueueName, jsonMsg, multicast);
     }
 }
Beispiel #2
0
        internal override void Receive(ApplicationPort listenPort, string listenSiteName)
        {
            this.InitQueueReceiveLocal();

            if (this.queueReceiveLocal != null)
            {
                string path = string.Empty;

                if (listenPort == ApplicationPort.Manager)
                {
                    path = this.queuePathReceiveLocal_Manager;
                }
                else if (listenPort == ApplicationPort.PhysicalHost)
                {
                    // 實體機的 Queue 命名與通路端不同
                    // 通路端 : Agent_站台名稱
                    // 實體機 : 站台名稱 (給一個固定值就可以)
                    path = string.Format(this.queuePathReceiveLocal_PhysicalHost, listenSiteName);
                }
                else
                {
                    path = string.Format(this.queuePathReceiveLocal, listenPort.ToString(), listenSiteName);
                }


                if (MessageQueue.Exists(path))
                {
                    this.queueReceiveLocal.Path = path;
                    this.queueReceiveLocal.BeginReceive();
                }
            }
        }
Beispiel #3
0
 public void Receive(ApplicationPort listenPort, string listenSiteName)
 {
     if (this.client != null)
     {
         this.client.SetReceivingVariable(false);
         this.client.Receive(listenPort, listenSiteName);
     }
 }
Beispiel #4
0
        internal override void Send(ApplicationPort fromPort, ApplicationPort toPort, string toSiteName, string jsonMsg, bool multicast = false)
        {
            //this.isMulticast = multicast;
            //this.msgToSend.Body = jsonMsg;
            this.isMulticast = multicast;

            MQMsgModel msg = JSON.Deserialize <MQMsgModel>(jsonMsg);

            msg.SentTime = DateTime.Now;

            this.msgToSend.Body = JSON.SerializeDynamic(msg);

            if (this.isMulticast == false)
            {
                // 2018/08/16, 避免 foreach 在多執行緒可能發生的問題, 加上 lock
                lock (thisLock)
                {
                    this.GetTargetPorts(toPort, toSiteName);

                    foreach (KeyValuePair <MessageQueue, string> item in this.dicQueueAndPath)
                    {
                        // 發送之前檢查下是否有設定 IP,因為是內部主機,所以直接寫死192.168
                        if (item.Value.IndexOf("192.168") > -1)
                        {
                            item.Key.Path = item.Value;
                            item.Key.Send(this.msgToSend);
                        }
                        else
                        {
                            throw new Exception("MQ 主機的相關 IP 未設定,請確認");
                        }
                    }
                }
            }
            else
            {
                if (!string.IsNullOrEmpty(this.multicastIP))
                {
                    // 改用 Message 物件來傳送
                    this.queueMulticast.Path = string.Format(this.queuePathMulticast, this.multicastIP);
                    this.queueMulticast.Send(this.msgToSend);
                }
                else
                {
                    throw new Exception("Message Queue 主機的 Multicast IP 未設定");
                }
            }
        }
Beispiel #5
0
        private void GetTargetPorts(ApplicationPort toPorts, string toSiteName, string toServerIP = "")
        {
            this.dicQueueAndPath.Clear();

            if (toPorts == ApplicationPort.Member)
            {
                this.dicQueueAndPath.Add(this.queueSendRemote_Member, string.Format(this.queuePathSendRemote_Member, this.sendRemoteIP_Member, ApplicationPort.Member.ToString(), toSiteName));
            }
            else if (toPorts == ApplicationPort.Agent)
            {
                this.dicQueueAndPath.Add(this.queueSendRemote_Agent, string.Format(this.queuePathSendRemote_Agent, this.sendRemoteIP_Agent, ApplicationPort.Agent.ToString(), toSiteName));
            }
            else if (toPorts == ApplicationPort.Manager)
            {
                this.dicQueueAndPath.Add(this.queueSendRemote_Manager, string.Format(this.queuePathSendRemote_Manager, this.sendRemoteIP_Manager, ApplicationPort.Manager.ToString()));
            }
            else if (toPorts == ApplicationPort.PhysicalHost)
            {
                this.dicQueueAndPath.Add(this.queueSendRemote_PhysicalHost, string.Format(this.queuePathSendRemote_PhysicalHost, this.sendRemoteIP_PhysicalHost, toSiteName));
            }
            else if (toPorts == ApplicationPort.Custom)
            {
                this.dicQueueAndPath.Add(this.queueSendRemote_Custom, string.Format(this.queuePathSendRemote_Custom, toServerIP, toSiteName));
            }
            else if (toPorts == ApplicationPort.MemberAndAgent)
            {
                this.dicQueueAndPath.Add(this.queueSendRemote_Member, string.Format(this.queuePathSendRemote_Member, this.sendRemoteIP_Member, ApplicationPort.Member.ToString(), toSiteName));
                this.dicQueueAndPath.Add(this.queueSendRemote_Agent, string.Format(this.queuePathSendRemote_Agent, this.sendRemoteIP_Agent, ApplicationPort.Agent.ToString(), toSiteName));
            }
            else if (toPorts == ApplicationPort.MemberAndManager)
            {
                this.dicQueueAndPath.Add(this.queueSendRemote_Member, string.Format(this.queuePathSendRemote_Member, this.sendRemoteIP_Member, ApplicationPort.Member.ToString(), toSiteName));
                this.dicQueueAndPath.Add(this.queueSendRemote_Manager, string.Format(this.queuePathSendRemote_Manager, this.sendRemoteIP_Manager, ApplicationPort.Manager.ToString()));
            }
            else if (toPorts == ApplicationPort.AgentAndManager)
            {
                this.dicQueueAndPath.Add(this.queueSendRemote_Agent, string.Format(this.queuePathSendRemote_Agent, this.sendRemoteIP_Agent, ApplicationPort.Agent.ToString(), toSiteName));
                this.dicQueueAndPath.Add(this.queueSendRemote_Manager, string.Format(this.queuePathSendRemote_Manager, this.sendRemoteIP_Manager, ApplicationPort.Manager.ToString()));
            }
            else if (toPorts == ApplicationPort.All)
            {
                // 當接收端是 All 時, 不需要發給實體機的 Queue, 以及 Custom 的主機
                this.dicQueueAndPath.Add(this.queueSendRemote_Member, string.Format(this.queuePathSendRemote_Member, this.sendRemoteIP_Member, ApplicationPort.Member.ToString(), toSiteName));
                this.dicQueueAndPath.Add(this.queueSendRemote_Agent, string.Format(this.queuePathSendRemote_Agent, this.sendRemoteIP_Agent, ApplicationPort.Agent.ToString(), toSiteName));
                this.dicQueueAndPath.Add(this.queueSendRemote_Manager, string.Format(this.queuePathSendRemote_Manager, this.sendRemoteIP_Manager, ApplicationPort.Manager.ToString()));
            }
        }
Beispiel #6
0
 /// <summary>
 /// 接收訊息
 /// </summary>
 /// <param name="listenPort">要接收的端口</param>
 /// <param name="listenSiteName">要接收的站台名稱</param>
 internal virtual void Receive(ApplicationPort listenPort, string listenSiteName)
 {
 }
Beispiel #7
0
 internal virtual void Send(ApplicationPort fromPort, ApplicationPort toPort, string toServerIP, string toSiteName, string jsonMsg, bool multicast = false)
 {
 }