public void msgReceivedHandler(MsgObj msg, String deviceId, string payload)
        {
            eMsgType type = msg.mType;

            switch (type)
            {
            case eMsgType.Meausurements:
                Console.WriteLine($"Got Measurement msg from device ID: '{deviceId}'");
                break;

            case eMsgType.BTscan:
                Console.WriteLine($"Got BT scan msg from device ID: '{deviceId}'");
                break;

            case eMsgType.MeasurementsAndBT:
                Console.WriteLine($"Got Measurement and BT scan msg from device ID: '{deviceId}'");
                break;

            default:
                Console.WriteLine("ERROR - message is of unknown Type");
                break;
            }

            //MsgReceivedEvent.OnMsgReceived(msg); // Raise event msgReceived
            //GetAsync(Configs.AZURE_WEB_API + @"/Device/msg_handler").Wait(); // try call controller
            Post(Configs.AZURE_WEB_API + @"/Device/msg_handler", "=" + payload, "application/x-www-form-urlencoded");
        }
Exemple #2
0
    public void SetMsgType(eMsgType type)
    {
        bool visible  = false;
        bool visible2 = false;
        bool visible3 = false;

        if (type == eMsgType.MB_OK)
        {
            visible = true;
        }
        else if (type == eMsgType.MB_OK_CANCEL)
        {
            visible2 = true;
        }
        else if (type == eMsgType.MB_CHECK_OK)
        {
            visible  = true;
            visible3 = true;
        }
        else if (type == eMsgType.MB_CHECK_OK_CANCEL)
        {
            visible2 = true;
            visible3 = true;
        }
        this.m_btnOK.Visible      = visible2;
        this.m_btnCancel.Visible  = visible2;
        this.m_btnCancel2.Visible = visible;
        this.m_CheckBox.Visible   = visible3;
        this.m_LbCheckBox.Visible = visible3;
    }
Exemple #3
0
        public string GetConvertMessageTitle(eMsgType eMsg, string title = "")
        {
            string strTitle = "";

            switch (eMsg)
            {
            case eMsgType.eMsgBoardNoti:
                strTitle = title;                                               // 공지사항 제목
                break;

            case eMsgType.eMsgFileTrans:
                strTitle = xconf.GetTitle("T_MESSAGE_FILETRANS");               // 파일전송 완료
                break;

            case eMsgType.eMsgFileRecv:
                strTitle = xconf.GetTitle("T_MESSAGE_FILERECV");                // 파일수신 완료
                break;

            case eMsgType.eMsgClipSend:
                strTitle = xconf.GetTitle("T_MESSAGE_CLIPSEND");                // 클립보드 전송
                break;

            case eMsgType.eMsgClipRecv:
                strTitle = xconf.GetTitle("T_MESSAGE_CLIPRECV");                // 클립보드 수신
                break;

            case eMsgType.eMsgFileCancel:
                strTitle = xconf.GetTitle("T_MESSAGE_TRANSCANCLE");                 // 파일 전송취소
                break;

            case eMsgType.eMsgApprConfirm:
                strTitle = xconf.GetTitle("T_MESSAGE_APPRCONFIRM");                 // 결재 승인완료
                break;

            case eMsgType.eMsgApprReject:
                strTitle = xconf.GetTitle("T_MESSAGE_APPRREJECT");                  // 결재 반려완료
                break;

            case eMsgType.eMsgEmailApprConfirm:
                strTitle = xconf.GetTitle("T_MESSAGE_MAILAPPRCONFIRM");             // 메일결재 승인완료
                break;

            case eMsgType.eMsgEmailApprReject:
                strTitle = xconf.GetTitle("T_MESSAGE_MAILAPPRREJECT");              // 메일결재 반려완료
                break;

            case eMsgType.eMsgEmailCancel:
                strTitle = xconf.GetTitle("T_MESSAGE_MAILCANCEL");                  // 메일 발송취소
                break;

            default:
                break;
            }

            return(strTitle);
        }
Exemple #4
0
 public void ShowMessageBox(string strTitle, string strMessage, eMsgType eMessageType, YesDelegate a_deYes = null, object obj = null)
 {
     MsgHandler.Handle("SetMsgBox", new object[]
     {
         a_deYes,
         obj,
         strTitle,
         strMessage,
         eMessageType
     });
 }
        public bool SendMessage(eMsgType msgType, ulong msgId, byte[] msg, ulong responseMsgId = 0)
        {
            switch (ProtocolVersion)
            {
            case tiesky.com.SharmIpc.eProtocolVersion.V1:
                return(this.rwh.SendMessage(msgType, msgId, msg, responseMsgId));

            case tiesky.com.SharmIpc.eProtocolVersion.V2:
                return(this.rwh.SendMessageV2(msgType, msgId, msg, responseMsgId));
            }

            return(false);
        }
Exemple #6
0
    public void SetMsgType(eMsgType type)
    {
        bool visible  = false;
        bool visible2 = false;

        if (type == eMsgType.MB_OK)
        {
            visible = true;
        }
        else if (type == eMsgType.MB_OK_CANCEL)
        {
            visible2 = true;
        }
        else
        {
            visible = true;
        }
        this.m_Button_ok.Visible     = visible2;
        this.m_Button_cancel.Visible = visible2;
        this.m_Button_ok1.Visible    = visible;
    }
Exemple #7
0
    public void SetMsgType(eMsgType type)
    {
        bool visible  = false;
        bool visible2 = false;
        bool visible3 = false;

        switch (type)
        {
        case eMsgType.MB_OK_CANCEL:
            visible = true;
            break;

        case eMsgType.MB_CHECK_OK:
            visible2 = true;
            break;

        case eMsgType.MB_CHECK_OK_CANCEL:
            visible  = true;
            visible2 = true;
            break;

        case eMsgType.MB_CHECK12_OK:
            visible  = true;
            visible2 = true;
            visible3 = true;
            break;

        case eMsgType.MB_CHECK12_OK_CANCEL:
            visible  = true;
            visible2 = true;
            visible3 = true;
            break;
        }
        this.m_btnOK.Visible       = visible;
        this.m_btnCancel.Visible   = visible;
        this.m_CheckBox1.Visible   = visible2;
        this.m_CheckBox2.Visible   = visible3;
        this.m_LbCheckBox1.Visible = visible2;
        this.m_LbCheckBox2.Visible = visible3;
    }
Exemple #8
0
        //async Task CallAsyncRemoteHandler(ulong msgId, byte[] bt)
        //{
        //    AsyncRemoteCallHandler(msgId, bt);
        //}

        /// <summary>
        /// Any incoming data from remote partner is accumulated here
        /// </summary>
        /// <param name="msgType"></param>
        /// <param name="msgId"></param>
        /// <param name="bt"></param>
        internal void InternalDataArrived(eMsgType msgType, ulong msgId, byte[] bt)
        {
            ResponseCrate rsp = null;

            switch (msgType)
            {
            case eMsgType.Request:

                Task.Run(() =>
                {
                    if (AsyncRemoteCallHandler != null)
                    {
                        //CallAsyncRemoteHandler(msgId, bt);
                        AsyncRemoteCallHandler(msgId, bt);
                        //Answer must be supplied via AsyncAnswerOnRemoteCall
                    }
                    else
                    {
                        this.remoteCallHandler(bt);
                    }
                });

                break;

            case eMsgType.RpcRequest:

                Task.Run(() =>
                {
                    if (AsyncRemoteCallHandler != null)
                    {
                        AsyncRemoteCallHandler(msgId, bt);
                        //Answer must be supplied via AsyncAnswerOnRemoteCall
                    }
                    else
                    {
                        var res = this.remoteCallHandler(bt);
                        sm.SendMessage(res.Item1 ? eMsgType.RpcResponse : eMsgType.ErrorInRpc, sm.GetMessageId(), res.Item2, msgId);
                    }
                });

                break;

            case eMsgType.ErrorInRpc:
            case eMsgType.RpcResponse:

                if (df.TryGetValue(msgId, out rsp))
                {
                    rsp.res      = bt;
                    rsp.IsRespOk = msgType == eMsgType.RpcResponse;

                    if (rsp.callBack == null)
                    {
                        //rsp.mre.Set();  //Signalling, to make waiting in parallel thread to proceed
                        rsp.Set_MRE();
                    }
                    else
                    {
                        df.TryRemove(msgId, out rsp);
                        //Calling callback in parallel thread, quicly to return to ReaderWriterhandler.Reader procedure
                        Task.Run(() =>
                        {
                            rsp.callBack(new Tuple <bool, byte[]>(rsp.IsRespOk, bt));
                        });
                    }
                }

                break;
            }
        }
Exemple #9
0
 public void SetMsg(YesDelegate a_deYes, object a_oObject, string title, string message, eMsgType type, int _ShowSceneType = 2)
 {
     if (a_deYes != null)
     {
         this.m_YesDelegate = (YesDelegate)Delegate.Combine(this.m_YesDelegate, new YesDelegate(a_deYes.Invoke));
     }
     if (a_oObject != null)
     {
         this.m_oYesObject = a_oObject;
     }
     this.SetMsgType(type);
     this.m_LbTitle.Text = title;
     this.m_LbNote.SetText(message);
     this.Show();
     base.ShowSceneType = _ShowSceneType;
 }
Exemple #10
0
 public void SetMsg(YesDelegate a_deYes, object a_oObject, string title, string message, string checkboxText, eMsgType type)
 {
     if (a_deYes != null)
     {
         this.m_YesDelegate = (YesDelegate)Delegate.Combine(this.m_YesDelegate, new YesDelegate(a_deYes.Invoke));
     }
     if (a_oObject != null)
     {
         this.m_oYesObject = a_oObject;
     }
     this.SetMsgType(type);
     this.m_LbTitle.Text = title;
     this.m_LbNote.SetText(message);
     this.m_LbCheckBox.SetText(checkboxText);
     this.Show();
 }
Exemple #11
0
 public void SetMsg(YesDelegate a_deYes, object a_oObject, NoDelegate b_deNo, object b_oObject, string title, string message, eMsgType type)
 {
     if (a_deYes != null)
     {
         this.m_YesDelegate = (YesDelegate)Delegate.Combine(this.m_YesDelegate, new YesDelegate(a_deYes.Invoke));
     }
     if (a_oObject != null)
     {
         this.m_oYesObject = a_oObject;
     }
     if (b_deNo != null)
     {
         this.m_NoDelegate = (NoDelegate)Delegate.Combine(this.m_NoDelegate, new NoDelegate(b_deNo.Invoke));
     }
     if (b_oObject != null)
     {
         this.m_oNoObject = b_oObject;
     }
     this.SetMsgType(type);
     this.m_LbTitle.Text = title;
     this.m_LbNote.SetText(message);
     this.Show();
 }
Exemple #12
0
        /// <summary>
        /// Any incoming data from remote partner is accumulated here
        /// </summary>
        /// <param name="msgType"></param>
        /// <param name="msgId"></param>
        /// <param name="bt"></param>
        void InternalDataArrived(eMsgType msgType, ulong msgId, byte[] bt)
        {
            ResponseCrate rsp = null;

            switch (msgType)
            {
            case eMsgType.Request:

                Task.Run(() =>
                {
                    if (AsyncRemoteCallHandler != null)
                    {
                        AsyncRemoteCallHandler(msgId, bt);
                        //Answer must be supplied via AsyncAnswerOnRemoteCall
                    }
                    else
                    {
                        this.remoteCallHandler(bt);
                    }
                });

                break;

            case eMsgType.RpcRequest:

                Task.Run(() =>
                {
                    if (AsyncRemoteCallHandler != null)
                    {
                        AsyncRemoteCallHandler(msgId, bt);
                        //Answer must be supplied via AsyncAnswerOnRemoteCall
                    }
                    else
                    {
                        var res = this.remoteCallHandler(bt);
                        sm.SendMessage(res.Item1 ? eMsgType.RpcResponse : eMsgType.ErrorInRpc, sm.GetMessageId(), res.Item2, msgId);
                    }
                });

                break;

            case eMsgType.ErrorInRpc:
            case eMsgType.RpcResponse:

                if (df.TryGetValue(msgId, out rsp))
                {
                    rsp.res      = bt;
                    rsp.IsRespOk = msgType == eMsgType.RpcResponse;

                    if (rsp.callBack == null)
                    {
                        rsp.mre.Set();
                    }
                    else
                    {
                        df.TryRemove(msgId, out rsp);
                        rsp.callBack(new Tuple <bool, byte[]>(rsp.IsRespOk, bt));
                    }
                }

                break;
            }
        }
Exemple #13
0
 public void SetMsg(Action <IntroMsgBoxDlg, object> a_deYes, object a_oObject, string title, string message, eMsgType type)
 {
     if (a_deYes != null)
     {
         this.m_deYes = new Action <IntroMsgBoxDlg, object>(a_deYes.Invoke);
     }
     if (a_oObject != null)
     {
         this.m_oYesObject = a_oObject;
     }
     this.SetMsgType(type);
     this.m_Label_title.Text = title;
     this.m_Label_Note.Text  = message;
     this.Show();
 }
Exemple #14
0
 public void SetMsg(YesDelegate a_deYes, object a_oObject, NoDelegate b_deNo, object b_oObject, string title, string message, string checkbox1Text, CheckBox1Delegate a_deCheck1, string checkbox2Text, CheckBox2Delegate a_deCheck2, eMsgType type)
 {
     if (a_deYes != null)
     {
         this.m_YesDelegate = (YesDelegate)Delegate.Combine(this.m_YesDelegate, new YesDelegate(a_deYes.Invoke));
     }
     if (a_oObject != null)
     {
         this.m_oYesObject = a_oObject;
     }
     if (b_deNo != null)
     {
         this.m_NoDelegate = (NoDelegate)Delegate.Combine(this.m_NoDelegate, new NoDelegate(b_deNo.Invoke));
     }
     if (b_oObject != null)
     {
         this.m_oNoObject = b_oObject;
     }
     this.SetMsgType(type);
     this.m_LbTitle.Text = title;
     this.m_LbNote.SetText(message);
     this.m_LbCheckBox1.SetText(checkbox1Text);
     if (a_deCheck1 != null)
     {
         this.m_Check1Delegate = (CheckBox1Delegate)Delegate.Combine(this.m_Check1Delegate, new CheckBox1Delegate(a_deCheck1.Invoke));
     }
     this.m_LbCheckBox2.SetText(checkbox2Text);
     if (a_deCheck2 != null)
     {
         this.m_Check2Delegate = (CheckBox2Delegate)Delegate.Combine(this.m_Check2Delegate, new CheckBox2Delegate(a_deCheck2.Invoke));
     }
     this.Show();
 }
Exemple #15
0
        /// <summary>
        /// Returns false if buffer threshold is reached
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool SendMessage(eMsgType msgType, ulong msgId, byte[] msg, ulong responseMsgId = 0)
        {
            if (totalBytesInQUeue > sm.maxQueueSizeInBytes)
            {
                //Cleaning queue
                lock (lock_q)
                {
                    totalBytesInQUeue = 0;
                    q.Clear();
                }
                //Generating exception
                throw new Exception("tiesky.com.SharmIpc: ReaderWriterHandler max queue treshold is reached " + sm.maxQueueSizeInBytes);
                //return false;
            }

            lock (lock_q)
            {
                //Splitting message
                int i    = 0;
                int left = msg == null ? 0 : msg.Length;

                byte[] pMsg = null;

                ushort totalChunks  = msg == null ? (ushort)1 : (msg.Length == 0) ? Convert.ToUInt16(1) : Convert.ToUInt16(Math.Ceiling((double)msg.Length / (double)bufferLenS));
                ushort currentChunk = 1;

                while (true)
                {
                    if (left > bufferLenS)
                    {
                        pMsg = new byte[bufferLenS + protocolLen];

                        //Writing protocol header
                        Buffer.BlockCopy(new byte[] { (byte)msgType }, 0, pMsg, 0, 1);          //MsgType (1 for standard message)
                        Buffer.BlockCopy(BitConverter.GetBytes(msgId), 0, pMsg, 1, 8);          //msgId_Sending
                        Buffer.BlockCopy(BitConverter.GetBytes(bufferLenS), 0, pMsg, 9, 4);     //payload len
                        Buffer.BlockCopy(BitConverter.GetBytes(currentChunk), 0, pMsg, 13, 2);  //current chunk
                        Buffer.BlockCopy(BitConverter.GetBytes(totalChunks), 0, pMsg, 15, 2);   //total chunks
                        Buffer.BlockCopy(BitConverter.GetBytes(responseMsgId), 0, pMsg, 17, 8); //total chunks


                        //Writing payload
                        if (msg != null && msg.Length > 0)
                        {
                            Buffer.BlockCopy(msg, i, pMsg, protocolLen, bufferLenS);
                        }

                        left -= bufferLenS;
                        i    += bufferLenS;
                        q.Enqueue(pMsg);
                        totalBytesInQUeue += pMsg.Length;
                    }
                    else
                    {
                        pMsg = new byte[left + protocolLen];

                        //Writing protocol header
                        Buffer.BlockCopy(new byte[] { (byte)msgType }, 0, pMsg, 0, 1);                                                    //MsgType (1 for standard message)
                        Buffer.BlockCopy(BitConverter.GetBytes(msgId), 0, pMsg, 1, 8);                                                    //msgId_Sending
                        Buffer.BlockCopy(BitConverter.GetBytes((msg != null && msg.Length == 0) ? Int32.MaxValue : left), 0, pMsg, 9, 4); //payload len
                        Buffer.BlockCopy(BitConverter.GetBytes(currentChunk), 0, pMsg, 13, 2);                                            //current chunk
                        Buffer.BlockCopy(BitConverter.GetBytes(totalChunks), 0, pMsg, 15, 2);                                             //total chunks
                        Buffer.BlockCopy(BitConverter.GetBytes(responseMsgId), 0, pMsg, 17, 8);                                           //total chunks

                        //Writing payload
                        if (msg != null && msg.Length > 0)
                        {
                            Buffer.BlockCopy(msg, i, pMsg, protocolLen, left);
                        }

                        q.Enqueue(pMsg);
                        totalBytesInQUeue += pMsg.Length;
                        break;
                    }

                    currentChunk++;
                }

                ////For SendProcedure1
                //mreSmthToSend.Set();
            }//eo lock


            StartSendProcedure();

            return(true);
        }
Exemple #16
0
 public bool SendMessage(eMsgType msgType, ulong msgId, byte[] msg, ulong responseMsgId = 0)     
 {
     return this.rwh.SendMessage(msgType, msgId, msg, responseMsgId);
 }
Exemple #17
0
        /// <summary>
        /// Any incoming data from remote partner is accumulated here
        /// </summary>
        /// <param name="msgType"></param>
        /// <param name="msgId"></param>
        /// <param name="bt"></param>
        void InternalDataArrived(eMsgType msgType, ulong msgId, byte[] bt)
        {   
            ResponseCrate rsp = null;

            switch (msgType)
            {
                case eMsgType.Request:

                    Task.Run(() =>
                    {
                        if (AsyncRemoteCallHandler != null)
                        {
                            AsyncRemoteCallHandler(msgId, bt);
                            //Answer must be supplied via AsyncAnswerOnRemoteCall
                        }
                        else
                        {
                            this.remoteCallHandler(bt);
                        }
                    });   

                    break;
                case eMsgType.RpcRequest:
                                        
                    Task.Run(() =>
                    {
                        if (AsyncRemoteCallHandler != null)
                        {
                            AsyncRemoteCallHandler(msgId, bt);
                            //Answer must be supplied via AsyncAnswerOnRemoteCall
                        }
                        else
                        {
                            var res = this.remoteCallHandler(bt);
                            sm.SendMessage(res.Item1 ? eMsgType.RpcResponse : eMsgType.ErrorInRpc, sm.GetMessageId(), res.Item2, msgId);
                        }
                    });                    

                    break;
                case eMsgType.ErrorInRpc:
                case eMsgType.RpcResponse:
                                        
                    if (df.TryGetValue(msgId, out rsp))
                    {
                        rsp.res = bt;
                        rsp.IsRespOk = msgType == eMsgType.RpcResponse;

                        if (rsp.callBack == null)
                        {
                            rsp.mre.Set();
                        }
                        else
                        {
                            df.TryRemove(msgId, out rsp);
                            rsp.callBack(new Tuple<bool, byte[]>(rsp.IsRespOk, bt));
                        }
                    }
             
                    break;                
            }
        }
Exemple #18
0
        /// <summary>
        /// Any incoming data from remote partner is accumulated here
        /// </summary>
        /// <param name="msgType"></param>
        /// <param name="msgId"></param>
        /// <param name="bt"></param>
        internal void InternalDataArrived(eMsgType msgType, ulong msgId, byte[] bt)
        {
            ResponseCrate rsp = null;

            switch (msgType)
            {
                case eMsgType.Request:

                    Task.Run(() =>
                    {
                        if (AsyncRemoteCallHandler != null)
                        {
                            AsyncRemoteCallHandler(msgId, bt);
                            //Answer must be supplied via AsyncAnswerOnRemoteCall
                        }
                        else
                        {
                            this.remoteCallHandler(bt);
                        }
                    });

                    break;
                case eMsgType.RpcRequest:

                    Task.Run(() =>
                    {
                    if (AsyncRemoteCallHandler != null)
                        {
                            AsyncRemoteCallHandler(msgId, bt);
                            //Answer must be supplied via AsyncAnswerOnRemoteCall
                        }
                        else
                        {
                            var res = this.remoteCallHandler(bt);
                            sm.SendMessage(res.Item1 ? eMsgType.RpcResponse : eMsgType.ErrorInRpc, sm.GetMessageId(), res.Item2, msgId);
                        }
                    });

                    break;
                case eMsgType.ErrorInRpc:
                case eMsgType.RpcResponse:

                    if (df.TryGetValue(msgId, out rsp))
                    {
                        rsp.res = bt;
                        rsp.IsRespOk = msgType == eMsgType.RpcResponse;

                        if (rsp.callBack == null)
                        {
                            rsp.mre.Set();  //Signalling, to make waiting in parallel thread to proceed
                            //rsp.Set_MRE();
                        }
                        else
                        {
                            df.TryRemove(msgId, out rsp);
                            //Calling callback in parallel thread, quicly to return to ReaderWriterhandler.Reader procedure
                            Task.Run(() =>
                            {
                                rsp.callBack(new Tuple<bool, byte[]>(rsp.IsRespOk, bt));
                            });
                        }
                    }

                    break;
            }
        }
        /// <summary>
        /// Returns false if buffer threshold is reached
        /// </summary>
        /// <param name="msg"></param>
        /// <returns></returns>
        public bool SendMessage(eMsgType msgType, ulong msgId, byte[] msg, ulong responseMsgId=0)
        {
            if (totalBytesInQUeue > sm.maxQueueSizeInBytes)
            {
                //Cleaning queue
                lock (lock_q)
                {
                    totalBytesInQUeue = 0;
                    q.Clear();
                }
                //Generating exception
                throw new Exception("tiesky.com.SharmIpc: ReaderWriterHandler max queue treshold is reached " + sm.maxQueueSizeInBytes);
                //return false;
            }

            lock (lock_q)
            {

                //Splitting message
                int i = 0;
                int left = msg == null ? 0 : msg.Length;

                byte[] pMsg = null;

                ushort totalChunks = msg == null ? (ushort)1 : (msg.Length == 0) ? Convert.ToUInt16(1) : Convert.ToUInt16(Math.Ceiling((double)msg.Length / (double)bufferLenS));
                ushort currentChunk = 1;

                while (true)
                {
                    if (left > bufferLenS)
                    {

                        pMsg = new byte[bufferLenS + protocolLen];

                        //Writing protocol header
                        Buffer.BlockCopy(new byte[] { (byte)msgType }, 0, pMsg, 0, 1);    //MsgType (1 for standard message)
                        Buffer.BlockCopy(BitConverter.GetBytes(msgId), 0, pMsg, 1, 8);  //msgId_Sending
                        Buffer.BlockCopy(BitConverter.GetBytes(bufferLenS), 0, pMsg, 9, 4);  //payload len
                        Buffer.BlockCopy(BitConverter.GetBytes(currentChunk), 0, pMsg, 13, 2);  //current chunk
                        Buffer.BlockCopy(BitConverter.GetBytes(totalChunks), 0, pMsg, 15, 2);  //total chunks
                        Buffer.BlockCopy(BitConverter.GetBytes(responseMsgId), 0, pMsg, 17, 8);  //total chunks

                        //Writing payload
                        if(msg != null && msg.Length>0)
                            Buffer.BlockCopy(msg, i, pMsg, protocolLen, bufferLenS);

                        left -= bufferLenS;
                        i += bufferLenS;
                        q.Enqueue(pMsg);
                        totalBytesInQUeue += pMsg.Length;
                    }
                    else
                    {
                        pMsg = new byte[left + protocolLen];

                        //Writing protocol header
                        Buffer.BlockCopy(new byte[] { (byte)msgType }, 0, pMsg, 0, 1);    //MsgType (1 for standard message)
                        Buffer.BlockCopy(BitConverter.GetBytes(msgId), 0, pMsg, 1, 8);  //msgId_Sending
                        Buffer.BlockCopy(BitConverter.GetBytes((msg != null && msg.Length == 0) ? Int32.MaxValue : left), 0, pMsg, 9, 4);  //payload len
                        Buffer.BlockCopy(BitConverter.GetBytes(currentChunk), 0, pMsg, 13, 2);  //current chunk
                        Buffer.BlockCopy(BitConverter.GetBytes(totalChunks), 0, pMsg, 15, 2);  //total chunks
                        Buffer.BlockCopy(BitConverter.GetBytes(responseMsgId), 0, pMsg, 17, 8);  //total chunks

                        //Writing payload
                        if (msg != null && msg.Length > 0)
                            Buffer.BlockCopy(msg, i, pMsg, protocolLen, left);

                        q.Enqueue(pMsg);
                        totalBytesInQUeue += pMsg.Length;
                        break;
                    }

                    currentChunk++;
                }

                ////For SendProcedure1
                //mreSmthToSend.Set();
            }//eo lock

            StartSendProcedure();

            return true;
        }
	public void InitFrom(GameMsgFormInfo info){

		msgType = info.msgType; // type of message to construct from this form

		gameObjectName = info.gameObjectName;
		log = info.log;
			// interact status message
		interactName = info.interactName;

			// dialog message
		command = info.command;
		x = info.x;
		y = info.y;
		w = info.w;
		h = info.h;
		text = info.text;
		title = info.title;
		time = info.time;
		modal = info.modal;
		xmlName = info.xmlName;
		className = info.className;
		dialogName = info.dialogName;
		anchor = info.anchor;
		arguments = info.arguments;
		numArguments = info.numArguments;
		waitForDialogClosed = info.waitForDialogClosed;
		waitForDialogName = info.waitForDialogName;
			//quickinfomsg
		timeout = info.timeout;
		editbox = info.editbox;
		editboxlabel = info.editboxlabel;
		editboxprompt = info.editboxprompt;
		sendMap = info.sendMap;
			//interact dialog
		items = info.items;
		//info.baseobj = gmf.baseobj;
		baseXML = info.baseXML;

			//popupmsg
		hasCancel = info.hasCancel;
		commandString = info.commandString;
		Params = info.Params; // used for interact status message	
			// GUIScreenMsg
		ScreenName = info.ScreenName;

	}
	public bool ShowInspectorGUI(){
		// this is called from the ScriptedAction custom inspector, and only shows the fields needed for the selected type
		bool dirty = false;
		if (serializedObject == null) serializedObject = new SerializedObject(this); // needed to display arrays in editor like fashion
		msgType = (eMsgType)EditorGUILayout.EnumPopup("msgType",(Enum)msgType);
		EditorGUI.BeginChangeCheck();
		if (msgType == eMsgType.interactMsg){
			if (gameObjectName == null) gameObjectName = "";
			gameObjectName = EditorGUILayout.TextField("gameObject",gameObjectName);
			if (map != null) dirty |= map.ShowInspectorGUI("map");		
			log = EditorGUILayout.Toggle("log",log);
		}
		if (msgType == eMsgType.interactStatusMsg){
			if (gameObjectName == null) gameObjectName = "";
			gameObjectName = EditorGUILayout.TextField("gameObject",gameObjectName);
			sendMap = EditorGUILayout.Toggle("send Map?",sendMap);
			if (sendMap && map != null) 
				dirty |= map.ShowInspectorGUI("map");		
			else
				interactName = EditorGUILayout.TextField("interactName",interactName);
			log = EditorGUILayout.Toggle("log",log);
			
			// to show a string array in the editor:
			serializedObject.Update();
    		EditorGUIUtility.LookLikeInspector();
    		SerializedProperty myIterator = serializedObject.FindProperty("Params");
   			while (true){
        	Rect myRect = GUILayoutUtility.GetRect(0f, 16f);
        	bool showChildren = EditorGUI.PropertyField(myRect, myIterator);
			if (!myIterator.NextVisible(showChildren)) break;
			}
    		serializedObject.ApplyModifiedProperties()	;
			EditorGUIUtility.LookLikeControls();
			
		}
		if (msgType == eMsgType.animateMsg){
			state = (eAnimateState)EditorGUILayout.EnumPopup("state",(Enum)state);
			if (name == null) name = "";
			name = EditorGUILayout.TextField("name",name);
		}
		if (msgType == eMsgType.taskMsg){
			
		}
		if (msgType == eMsgType.dialogMsg 
			|| msgType == eMsgType.errorDialogMsg 
			|| msgType == eMsgType.quickInfoDialogMsg
			|| msgType == eMsgType.popupMsg )
		{
			command = (DialogMsg.Cmd)EditorGUILayout.EnumPopup("command",(Enum)command);
			x = EditorGUILayout.IntField("x",x);
			y = EditorGUILayout.IntField("y",y);
			w = EditorGUILayout.IntField("w",w);
			h = EditorGUILayout.IntField("h",h);
			text = EditorGUILayout.TextField("text",text);	
			title = EditorGUILayout.TextField("title",title);
			time = EditorGUILayout.FloatField("time",time);
			modal = EditorGUILayout.Toggle("modal",modal);
		}
		if (msgType == eMsgType.dialogMsg) 
		{
			if (xmlName == null) xmlName = "";
			xmlName = EditorGUILayout.TextField ("xmlName",xmlName);
			if (className == null) className = "";
			className = EditorGUILayout.TextField("className",className);
			dialogName = EditorGUILayout.TextField("dialogName",dialogName);
			waitForDialogClosed = EditorGUILayout.Toggle("waitForDialogClosed",waitForDialogClosed);
			if ( waitForDialogClosed == true )
				waitForDialogName = EditorGUILayout.TextField("waitForDalogName",waitForDialogName);
			anchor = EditorGUILayout.TextField("anchor",anchor);
			numArguments = EditorGUILayout.IntField("numArguments",numArguments);
			// display number of arguments...change number of fields on change
			if (arguments.Count != numArguments )
			{
				List<string> newlist = new List<string>();
				if ( numArguments > arguments.Count )
				{
					// new is greater than current...just copy old to new
					foreach( string arg in arguments )
						newlist.Add(arg);
					// add blank(s) at the end
					for( int i=0 ; i<(numArguments-arguments.Count) ; i++)
						newlist.Add("");
				}
				else
				{
					// new is less than current...just copy old-1 to new
					foreach( string arg in arguments )
					{
						if ( newlist.Count < numArguments )
							newlist.Add(arg);
					}
				}
				// reassign
				arguments = newlist;
			}
			for (int i=0 ; i<arguments.Count ; i++)
			{
				arguments[i] = EditorGUILayout.TextField ("argument" + (i+1).ToString (),arguments[i]);
			}
		}
		if (msgType == eMsgType.guiScreenMsg) 
		{
			if (ScreenName == null) ScreenName = "";
			ScreenName = EditorGUILayout.TextField ("xmlName",ScreenName);
			numArguments = EditorGUILayout.IntField("numArguments",numArguments);
			// display number of arguments...change number of fields on change
			if (arguments.Count != numArguments )
			{
				List<string> newlist = new List<string>();
				if ( numArguments > arguments.Count )
				{
					// new is greater than current...just copy old to new
					foreach( string arg in arguments )
						newlist.Add(arg);
					// add blank(s) at the end
					for( int i=0 ; i<(numArguments-arguments.Count) ; i++)
						newlist.Add("");
				}
				else
				{
					// new is less than current...just copy old-1 to new
					foreach( string arg in arguments )
					{
						if ( newlist.Count < numArguments )
							newlist.Add(arg);
					}
				}
				// reassign
				arguments = newlist;
			}
			for (int i=0 ; i<arguments.Count ; i++)
			{
				arguments[i] = EditorGUILayout.TextField ("argument" + (i+1).ToString (),arguments[i]);
			}
		}
		
		
		
		if (msgType == eMsgType.errorDialogMsg){
			
		}
		if (msgType == eMsgType.interactDialogMsg){
			
		}
		if (msgType == eMsgType.quickInfoDialogMsg){
			timeout = EditorGUILayout.FloatField("timeout",timeout);
			editbox = EditorGUILayout.Toggle("editbox",editbox);
			if (editboxlabel == null) editboxlabel = "";
			editboxlabel = EditorGUILayout.TextField("editboxlabel",editboxlabel);
			if (editboxprompt == null) editboxprompt = "";
			editboxprompt = EditorGUILayout.TextField("editboxprompt",editboxprompt);
		}
		if (msgType == eMsgType.popupMsg){
			hasCancel = EditorGUILayout.Toggle("hasCancel",hasCancel);
			if (commandString == null) commandString = "";
			commandString = EditorGUILayout.TextField("commandString",commandString);
		}

		dirty |= EditorGUI.EndChangeCheck();
		if (dirty) EditorUtility.SetDirty(this);
		return dirty;
	}
Exemple #22
0
        /// <summary>
        ///
        /// </summary>
        void InitReader()
        {
            string prefix = sm.instanceType == eInstanceType.Slave ? "1" : "2";

            if (ewh_Reader_ReadyToRead == null)
            {
                ewh_Reader_ReadyToRead  = new EventWaitHandle(false, EventResetMode.ManualReset, sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToRead");
                ewh_Reader_ReadyToWrite = new EventWaitHandle(true, EventResetMode.ManualReset, sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToWrite");
                ewh_Reader_ReadyToWrite.Set();
            }

            //if (sm.instanceType == tiesky.com.SharmIpc.eInstanceType.Slave)
            //{
            //    Console.WriteLine("My reader handlers:");
            //    Console.WriteLine(sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToRead");
            //    Console.WriteLine(sm.uniqueHandlerName + prefix + "_SharmNet_ReadyToWrite");
            //    Console.WriteLine("-------");
            //}


            if (Reader_mmf == null)
            {
                Reader_mmf      = System.IO.MemoryMappedFiles.MemoryMappedFile.CreateOrOpen(sm.uniqueHandlerName + prefix + "_SharmNet_MMF", sm.bufferCapacity, MemoryMappedFileAccess.ReadWrite);
                Reader_accessor = Reader_mmf.CreateViewAccessor(0, sm.bufferCapacity);
            }

            Task.Run(() =>
            {
                byte[] hdr           = null;
                byte[] ret           = null;
                ushort iCurChunk     = 0;
                ushort iTotChunk     = 0;
                ulong iMsgId         = 0;
                int iPayLoadLen      = 0;
                ulong iResponseMsgId = 0;

                eMsgType msgType = eMsgType.RpcRequest;

                try
                {
                    while (true)
                    {
                        ewh_Reader_ReadyToRead.WaitOne();
                        if (ewh_Reader_ReadyToRead == null) //Special Dispose case
                        {
                            return;
                        }
                        ewh_Reader_ReadyToRead.Reset();
                        //Reading data from MMF

                        //Reading header
                        hdr     = ReadBytes(0, protocolLen);
                        msgType = (eMsgType)hdr[0];

                        //Parsing header
                        switch (msgType)
                        {
                        case eMsgType.ErrorInRpc:

                            iPayLoadLen    = BitConverter.ToInt32(hdr, 9);   //+4
                            iResponseMsgId = BitConverter.ToUInt64(hdr, 17); //+8

                            DataArrived(msgType, iResponseMsgId, null);
                            break;

                        case eMsgType.RpcResponse:
                        case eMsgType.RpcRequest:
                        case eMsgType.Request:

                            bool zeroByte = false;
                            iMsgId        = BitConverter.ToUInt64(hdr, 1); //+8
                            iPayLoadLen   = BitConverter.ToInt32(hdr, 9);  //+4
                            if (iPayLoadLen == Int32.MaxValue)
                            {
                                zeroByte    = true;
                                iPayLoadLen = 0;
                            }
                            iCurChunk      = BitConverter.ToUInt16(hdr, 13); //+2
                            iTotChunk      = BitConverter.ToUInt16(hdr, 15); //+2
                            iResponseMsgId = BitConverter.ToUInt64(hdr, 17); //+8

                            if (iCurChunk == 1)
                            {
                                chunksCollected = null;
                                MsgId_Received  = iMsgId;
                            }
                            else if (iCurChunk != currentChunk + 1)
                            {
                                //Wrong income, sending special signal back, waiting for new MsgId
                                switch (msgType)
                                {
                                case eMsgType.RpcRequest:
                                    this.SendMessage(eMsgType.ErrorInRpc, this.GetMessageId(), null, iMsgId);
                                    break;

                                case eMsgType.RpcResponse:
                                    DataArrived(eMsgType.ErrorInRpc, iResponseMsgId, null);
                                    break;
                                }
                                break;
                            }

                            if (iTotChunk == iCurChunk)
                            {
                                if (chunksCollected == null)
                                {
                                    DataArrived(msgType, (msgType == eMsgType.RpcResponse) ? iResponseMsgId : iMsgId, iPayLoadLen == 0 ? ((zeroByte) ? new byte[0] : null) : ReadBytes(protocolLen, iPayLoadLen));
                                }
                                else
                                {
                                    ret = new byte[iPayLoadLen + chunksCollected.Length];
                                    Buffer.BlockCopy(chunksCollected, 0, ret, 0, chunksCollected.Length);
                                    Buffer.BlockCopy(ReadBytes(protocolLen, iPayLoadLen), 0, ret, chunksCollected.Length, iPayLoadLen);
                                    DataArrived(msgType, (msgType == eMsgType.RpcResponse) ? iResponseMsgId : iMsgId, ret);
                                }
                                chunksCollected = null;
                                currentChunk    = 0;
                            }
                            else
                            {
                                if (chunksCollected == null)
                                {
                                    chunksCollected = ReadBytes(protocolLen, iPayLoadLen);
                                }
                                else
                                {
                                    byte[] tmp = new byte[chunksCollected.Length + iPayLoadLen];
                                    Buffer.BlockCopy(chunksCollected, 0, tmp, 0, chunksCollected.Length);
                                    Buffer.BlockCopy(ReadBytes(protocolLen, iPayLoadLen), 0, tmp, chunksCollected.Length, iPayLoadLen);
                                    chunksCollected = tmp;
                                }

                                currentChunk = iCurChunk;
                            }
                            break;

                        default:
                            //Unknown protocol type
                            chunksCollected = null;
                            currentChunk    = 0;
                            //Wrong income, doing nothing
                            throw new Exception("tiesky.com.SharmIpc: Reading protocol contains errors");
                            //break;
                        }

                        //Setting signal
                        ewh_Reader_ReadyToWrite.Set();
                    }
                }
                catch
                {}
            });
        }
Exemple #23
0
 public bool SendMessage(eMsgType msgType, ulong msgId, byte[] msg, ulong responseMsgId = 0)
 {
     return(this.rwh.SendMessage(msgType, msgId, msg, responseMsgId));
 }