Exemplo n.º 1
0
        public static TheRecordHolder MeshQueryRecordHolder(int idRecord, Guid node, string strEngineName, Guid cdeMIdThing)
        {
            TheRecordHolder trh = null;

            // Package up request info.
            MsgMileRecordHolder msgRequest = new MsgMileRecordHolder()
            {
                id = idRecord
            };

            // Start asynchronous task to send a message and wait for a reply.
            // Sends a message named nameof(MsgMileRecordHolder)
            // Receives a reply named nameof(MsgMileRecordHolderResponse)
            // See function "HandleMessage" for actual handling.

            Task <MsgMileRecordHolderResponse> t = null;

            try
            {
                TheMessageAddress tma = new TheMessageAddress()
                {
                    Node       = Guid.Empty,
                    EngineName = strEngineName,
                    ThingMID   = cdeMIdThing,
                    SendToProvisioningService = false,
                };
                t = TheCommRequestResponse.PublishRequestJSonAsync <MsgMileRecordHolder, MsgMileRecordHolderResponse>(tma, msgRequest);
            }
            catch (Exception ex)
            {
                string strMessage = ex.Message;
            }

            // Wait for a bit
            t.Wait(20000);
            bool bTaskCompleted = t.IsCompleted;

            // Check for success.
            if (bTaskCompleted)
            {
                MsgMileRecordHolderResponse msgResponse = t.Result;
                trh = msgResponse.data;
            }

            return(trh);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles Messages sent from a host sub-engine to its clients
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="pIncoming"></param>
        public void HandleMessage(ICDEThing sender, object pIncoming)
        {
            TheProcessMessage pMsg = pIncoming as TheProcessMessage;

            if (pMsg == null)
            {
                return;
            }

            string[] cmd = pMsg.Message.TXT.Split(':');
            switch (cmd[0])
            {
            case "CDE_INITIALIZED":
                MyBaseEngine.SetInitialized(pMsg.Message);
                break;

            case nameof(MsgMileRecordHolder):
                if (g_EnableMeshDataResponse)
                {
                    // Request from another node for mile record holder information.
                    var request     = TheCommRequestResponse.ParseRequestMessageJSON <MsgMileRecordHolder>(pMsg.Message);
                    var MsgResponse = new MsgMileRecordHolderResponse();
                    if (request != null)
                    {
                        MsgResponse.data = TheRecordHolder.QueryRecordHolder(request.id);
                    }
                    TheCommRequestResponse.PublishResponseMessageJson(pMsg.Message, MsgResponse);

                    MsgResponse = null;       // Prevent legacy response handler for being sent.
                }
                break;

            default:
                break;
            }
        }