public TMsg ReadMessage <TMsg>() where TMsg : BaseNetworkMessage, new()
        {
            var msg = new TMsg();

            msg.Deserialize(this);
            return(msg);
        }
Beispiel #2
0
        public TMsg ReadMessage <TMsg>() where TMsg : MessageBase, new()
        {
            TMsg result = Activator.CreateInstance <TMsg>();

            result.Deserialize(this);
            return(result);
        }
        public TMsg ReadMessage <TMsg>() where TMsg : class, INetworkSerializable, new()
        {
            var msg = new TMsg();

            msg.Deserialize(this);
            return(msg);
        }
        public TMsg ReadMessage <TMsg>() where TMsg : IMessageBase, new()
        {
            TMsg msg = typeof(TMsg).IsValueType ? default : new TMsg();

                       msg.Deserialize(reader);
                       return(msg);
        }
Beispiel #5
0
    public TMsg ReadMessage <TMsg>() where TMsg : P2PMessageBase, new()
    {
        TMsg tmsg = Activator.CreateInstance <TMsg>();

        tmsg.Deserialize(this);
        return(tmsg);
    }
        public TMsg Read <TMsg>() where TMsg : struct, INetworkSerializable
        {
            var msg = new TMsg();

            msg.Deserialize(this);
            return(msg);
        }
        /// <summary>
        /// Reads a serializable message from the underlying buffer. If the type is a
        /// reference type, this will allocate GC.
        /// </summary>
        public TMsg Read <TMsg>() where TMsg : INetworkSerializable, new()
        {
            var msg = new TMsg();

            msg.Deserialize(ref this);
            return(msg);
        }
Beispiel #8
0
        public TMsg ReadMessage <TMsg>() where TMsg : MessageBase, new()
        {
            TMsg local = Activator.CreateInstance <TMsg>();

            local.Deserialize(this);
            return(local);
        }
        public TMsg ReadMessage <TMsg>() where TMsg : MessageBase, new()
        {
            TMsg instance = Activator.CreateInstance <TMsg>();

            instance.Deserialize(this);
            return(instance);
        }
Beispiel #10
0
        public TMsg ReadMessage <TMsg>() where TMsg : MessageBase, new()
        {
            TMsg result = new TMsg();

            result.Deserialize(reader);
            return(result);
        }
Beispiel #11
0
        private TSales SaveTrans(TMsg m, string agentId, string salesNo, DateTime salesDate)
        {
            TSales sales = new TSales();

            sales.SetAssignedIdTo(Guid.NewGuid().ToString());
            sales.SalesDate = salesDate;
            sales.SalesNo   = salesNo;
            if (!string.IsNullOrEmpty(agentId))
            {
                MAgent agent = _mAgentRepository.Get(agentId);
                if (agent == null)
                {
                    throw new Exception("Kode Agen salah atau tidak terdaftar");
                }
                sales.AgentId = agent;
            }
            else
            {
                throw new Exception("Kode Agen kosong.");
            }
            sales.MsgId = m;

            sales.CreatedDate = DateTime.Now;
            sales.CreatedBy   = Environment.UserName;
            sales.DataStatus  = EnumDataStatus.New.ToString();
            sales.SalesDets.Clear();
            _tSalesRepository.Save(sales);
            return(sales);
        }
Beispiel #12
0
        public TMsg ReadMessage <TMsg>() where TMsg : DataFile, new()
        {
            var msg = new TMsg();

            msg.Deserialize(this);
            return(msg);
        }
Beispiel #13
0
        internal static void SaveMessage(GsmComm.PduConverter.SmsPdu smsPdu)
        {
            // Received message
            SmsDeliverPdu data = (SmsDeliverPdu)smsPdu;

            // create our NHibernate session factory
            var sessionFactory = CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // populate the database
                using (var transaction = session.BeginTransaction())
                {
                    TMsg msg = new TMsg();
                    msg.Id      = Guid.NewGuid().ToString();
                    msg.MsgDate = data.SCTimestamp.ToDateTime();
                    msg.MsgFrom = data.OriginatingAddress;
                    msg.MsgTo   = "";
                    msg.MsgText = data.UserDataText;

                    // save both stores, this saves everything else via cascading
                    session.SaveOrUpdate(msg);

                    transaction.Commit();
                }
            }
        }
        public TMsg ReadMessage <TMsg>() where TMsg : MessageBase, new()
        {
            var msg = new TMsg();

            msg.Deserialize(reader);
            return(msg);
        }
Beispiel #15
0
        public TMsg ReadMessage <TMsg>() where TMsg : MessageBase, new()
        {
            TMsg msg = new TMsg();

            msg.Deserialize(this);
            return(msg);
        }
        public TMsg ReadMessage <TMsg>() where TMsg : IMessageBase, new()
        {
            // Normally I would just do:
            // TMsg msg = new TMsg();
            // but mono calls an expensive method Activator.CreateInstance
            // For value types this is unnecesary,  just use the default value
            TMsg msg = typeof(TMsg).IsValueType ? default(TMsg) : new TMsg();

            msg.Deserialize(reader);
            return(msg);
        }
Beispiel #17
0
        private void SaveMessage(InboundMessage m)
        {
            string pesan     = string.Empty;
            bool?  isSuccess = null;

            try
            {
                _tMsgRepository.DbContext.BeginTransaction();

                //check sms for mencegah double data
                if (_tMsgRepository.GetMsgLikes(DateTime.Today, m.getText()))
                {
                    throw new Exception("SMS ini sudah pernah diinput.");
                }

                // Received message
                TMsg msg = new TMsg();
                msg.SetAssignedIdTo(Guid.NewGuid().ToString());
                msg.MsgDate     = DateTime.Now;// Convert.ToDateTime(m.getDate().toGMTString());
                msg.MsgFrom     = m.getOriginator();
                msg.MsgText     = m.getText();
                msg.DataStatus  = EnumDataStatus.New.ToString();
                msg.CreatedBy   = Environment.UserName;
                msg.CreatedDate = DateTime.Now;
                // save both stores, this saves everything else via cascading
                _tMsgRepository.Save(msg);
                isSuccess = true;
                pesan     = "\nBerhasil.";
            }
            catch (Exception ex)
            {
                _tMsgRepository.DbContext.RollbackTransaction();
                //throw ex;
                isSuccess = false;
                pesan     = "\nGagal.\n" + ex.GetBaseException().Message;
            }
            finally
            {
                if (isSuccess.HasValue)
                {
                    //delete sms
                    bool deleteSuccess = gateway.deleteMessage(m);
                }
            }
        }
Beispiel #18
0
        private void SaveTrans(TMsg msg)
        {
            string pesan     = string.Empty;
            bool?  isSuccess = null;

            //MessageBox.Show(msg.MsgText);
            //MessageBox.Show(msg.MsgFrom);
            try
            {
                _tSalesRepository.DbContext.BeginTransaction();

                //split string
                SaveTransHelper hlp = new SaveTransHelper(_tSalesRepository, _tSalesDetRepository, _mGameRepository, _mAgentRepository, _tMsgRepository);
                hlp.SaveToTrans(msg, msg.MsgText, dtSalesDate.Value);

                _tSalesRepository.DbContext.CommitTransaction();
                isSuccess = true;
                pesan     = "\nBerhasil.";
            }
            catch (Exception ex)
            {
                _tSalesRepository.DbContext.RollbackTransaction();
                isSuccess = false;
                pesan     = "\nGagal.\n" + ex.GetBaseException().Message;
                //throw ex;
            }
            finally
            {
                if (isSuccess.HasValue)
                {
                    _tSalesRepository.DbContext.BeginTransaction();
                    //update msg status
                    msg.MsgStatus    = string.Format("Read|{0}", isSuccess.Value.ToString());
                    msg.DataStatus   = EnumDataStatus.Updated.ToString();
                    msg.ModifiedBy   = Environment.UserName;
                    msg.ModifiedDate = DateTime.Now;
                    _tMsgRepository.Update(msg);
                    _tSalesRepository.DbContext.CommitTransaction();

                    string txt          = msg.MsgText;
                    string sender       = "+" + msg.MsgFrom;
                    bool   replySuccess = SendMessage(txt, sender, pesan);
                }
            }
        }
Beispiel #19
0
        private void SaveMessage(SmsPdu smsPdu)
        {
            string        pesan = string.Empty;
            SmsDeliverPdu data  = (SmsDeliverPdu)smsPdu;

            try
            {
                _tMsgRepository.DbContext.BeginTransaction();

                // Received message
                TMsg msg = new TMsg();
                msg.SetAssignedIdTo(Guid.NewGuid().ToString());
                msg.MsgDate = data.SCTimestamp.ToDateTime();
                msg.MsgFrom = data.OriginatingAddress;
                msg.MsgTo   = "";
                msg.MsgText = data.UserDataText;

                // save both stores, this saves everything else via cascading
                _tMsgRepository.Save(msg);

                //split string
                SaveTransHelper hlp = new SaveTransHelper(_tSalesRepository, _tSalesDetRepository, _mGameRepository, _mAgentRepository, _tMsgRepository);
                hlp.SaveToTrans(data.UserDataText);
                _tMsgRepository.DbContext.CommitTransaction();
                pesan = "\nBerhasil.";
            }
            catch (Exception ex)
            {
                _tMsgRepository.DbContext.RollbackTransaction();
                pesan = "\nGagal.\n" + ex.GetBaseException().Message;
                //throw ex;
            }
            if (data.UserDataText.Length >= 150)
            {
                SendMessage(data.OriginatingAddress, data.UserDataText.Substring(0, 150) + pesan);
            }
            else
            {
                SendMessage(data.OriginatingAddress, data.UserDataText + pesan);
            }

            //make delay to send sms
        }
Beispiel #20
0
    //登录
    //协议参数:str用户名,str密码
    //返回协议:-1表示失败 0表示成功
    public void MsgLogin(Conn conn, ProtocolBase protoBase)
    {
        //获取数值
        int           start     = 0;
        ProtocolBytes protocol  = (ProtocolBytes)protoBase;
        string        protoName = protocol.GetString(start, ref start);
        string        id        = protocol.GetString(start, ref start);
        string        pw        = protocol.GetString(start, ref start);
        string        strFormat = "[收到登录协议]" + conn.GetAdress();

        Console.WriteLine(strFormat + " 用户名:" + id + " 密码:" + pw);
        //构建返回协议
        ProtocolBytes protocolRet = new ProtocolBytes();

        protocolRet.AddString("Login");
        //验证
        if (!DataMgr.instance.CheckPassWord(id, pw))
        {
            protocolRet.AddInt(-1);
            conn.Send(protocolRet);
            return;
        }
        //是否已经登录
        ProtocolBytes protocolLogout = new ProtocolBytes();

        protocolLogout.AddString("Logout");
        if (!Player.KickOff(id, protocolLogout))
        {
            protocolRet.AddInt(-1);
            conn.Send(protocolRet);
            return;
        }

        //获取玩家数据
        PlayerData playerData = DataMgr.instance.GetPlayerData(id);

        if (playerData == null)
        {
            protocolRet.AddInt(-1);
            conn.Send(protocolRet);
            return;
        }
        conn.player      = new Player(id, conn);
        conn.player.data = playerData;
        //事件触发
        ServNet.instance.handlePlayerEvent.OnLogin(conn.player);

        // 正常返回
        //protocolRet.AddInt(0);
        //protocolRet.AddString(id);
        //conn.Send(protocolRet);

        // 测试 Json
        RspMsg msg = new RspMsg();

        msg.rspType = 0;
        msg.strTips = "登录成功!";
        TMsg tg = new TMsg();

        msg.strJsData = JsonMapper.ToJson(tg);

        ProtocolJson ptemp = new ProtocolJson();

        ptemp.SetKeyCode("Login");
        ptemp.PushContent <RspMsg>(msg);
        conn.Send(ptemp);

        //// 测试probuffer
        //ProtocolPB pb = new ProtocolPB();
        //pb.SetKeyCode("Login");
        //ChatMsg cm = new ChatMsg();
        //cm.sender = "习近平:";
        //cm.msg = "特朗普今日访华,拉出去宰了!!";
        //List<string> pData = new List<string>();
        //for (int i = 0; i < 10; i++)
        //{
        //    pData.Add(i.ToString());
        //}
        //cm.data = pData;
        //TMsg tm = new TMsg();
        //cm.content = tm;
        //pb.Serialize<ChatMsg>(cm);
        //conn.Send(pb);
        return;
    }
Beispiel #21
0
        public void SaveToTrans(TMsg m, string msg, DateTime salesDate)
        {
            //many line breaks, every handphone have different string
            string[] separator = new string[] { "\n", "\r", "\r\n", "\n\r" };
            string[] lines     = msg.Replace(" ", "").ToUpper().Split(separator, StringSplitOptions.RemoveEmptyEntries);// Regex.Split(msg.ToUpper(), "\n");
            string   agentId   = string.Empty;
            string   salesNo   = string.Empty;

            IList <DetailMessage> listDet = new List <DetailMessage>();
            DetailMessage         detMsg  = null;
            decimal factor = 1;
            bool    isHBR  = false;

            //set TH as default game
            bool isTH = true;

            //separate number with value with this string
            string[] valueseparator = new string[] { ConfigurationManager.AppSettings["ValueSeparator"] };
            string   valseparator   = ConfigurationManager.AppSettings["ValueSeparator"];

            //separate each number with this string
            string[] numseparator = new string[] { ConfigurationManager.AppSettings["NumSeparator"] };
            foreach (string line in lines)
            {
                factor = 1;
                if (line.Contains("A="))
                {
                    agentId = line.Replace("A=", "");
                }
                else if (line.Contains("KE="))
                {
                    salesNo = line.Replace("KE=", "");
                }
                //if message contain HRB string, the game is HBR
                else if (line.Contains("HBR"))
                {
                    isHBR = true;
                    isTH  = false;
                }
                ////if message contain TH string, the game is TH
                //else if (line.Contains("TH"))
                //{
                //    isTH = true;
                //}
                else
                {
                    //search game and value
                    //det[0] = number list
                    //det[1] = value and game (for BB)
                    //string[] dets = line.Split(valueseparator, StringSplitOptions.RemoveEmptyEntries); // Regex.Split(line, "=");
                    //string det = dets[0].Trim();
                    string val  = line.Substring(line.LastIndexOf(valseparator) + 1);
                    string nums = line.Substring(0, line.LastIndexOf(valseparator));
                    //check if games is BB
                    if (val.Contains("BB"))
                    {
                        decimal value = 0;
                        //replace comma with dot to identify decimal number, ex : 0,5
                        if (!decimal.TryParse(val.Replace("BB", "").Replace(",", "."), out value))
                        {
                            throw new Exception("Format angka salah!!!");
                        }

                        string[] numbers = nums.Split(numseparator, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string num in numbers)
                        {
                            detMsg = new DetailMessage();

                            if (isTH && num.Length == 4)
                            {
                                detMsg.GameId = EnumGame.D4TH.ToString();
                            }
                            else
                            {
                                detMsg.GameId = string.Format("D{0}", num.Length);
                            }
                            detMsg.SalesNumber = num;
                            detMsg.SalesValue  = value * factor;
                            detMsg.IsBB        = true;
                            detMsg.IsHBR       = false;
                            //HBR with factor = 2 is for only game D4 only
                            if (isHBR && num.Length == 4)
                            {
                                detMsg.SalesValue = value * 2;
                                detMsg.IsHBR      = true;
                            }
                            listDet.Add(detMsg);
                        }
                    }
                    //check if games is BK
                    if (val.Contains("-"))
                    {
                        //replace comma with dot to identify decimal number, ex : 0,5
                        string[] BKseparator = new string[] { "-" };
                        string[] BK          = nums.Split(BKseparator, StringSplitOptions.RemoveEmptyEntries);
                        decimal  b           = 0;
                        decimal  k           = 0;

                        if (!decimal.TryParse(BK[0], out b) || !decimal.TryParse(BK[1], out k))
                        {
                            throw new Exception("Format angka salah!!!");
                        }

                        string[] numbers = nums.Split(numseparator, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string num in numbers)
                        {
                            //besar
                            detMsg             = new DetailMessage();
                            detMsg.GameId      = EnumGame.BK_B.ToString();
                            detMsg.SalesNumber = num;
                            detMsg.SalesValue  = b * 2;
                            detMsg.IsBB        = false;
                            detMsg.IsHBR       = false;
                            listDet.Add(detMsg);

                            //kecil
                            detMsg             = new DetailMessage();
                            detMsg.GameId      = EnumGame.BK_K.ToString();
                            detMsg.SalesNumber = num;
                            detMsg.SalesValue  = k * 2;
                            detMsg.IsBB        = false;
                            detMsg.IsHBR       = false;
                            listDet.Add(detMsg);
                        }
                    }
                    //if not, just do it
                    else
                    {
                        decimal value = 0;
                        if (!decimal.TryParse(val.Replace(",", "."), out value))
                        {
                            throw new Exception("Format angka salah!!!");
                        }

                        //cannot use regex .(dot), it use for other functionality
                        // string[] numbers = Regex.Split(det, ".");

                        string[] numbers = nums.Split(numseparator, StringSplitOptions.RemoveEmptyEntries);
                        foreach (string num in numbers)
                        {
                            detMsg = new DetailMessage();
                            //check if numbers contain x string
                            //(this for game WING)
                            if (num.Contains("X"))
                            {
                                detMsg.GameId = EnumGame.WING.ToString();
                            }
                            else if (num.Contains("MK"))
                            {
                                detMsg.GameId = EnumGame.MK.ToString();
                            }
                            else if (num.Contains("/"))
                            {
                                detMsg.GameId = EnumGame.PAKET.ToString();
                            }
                            else if (num.Contains("D"))
                            {
                                detMsg.GameId = EnumGame.D.ToString();
                            }
                            else if (num.Contains("T"))
                            {
                                detMsg.GameId = EnumGame.T.ToString();
                            }
                            else if (num.Contains("B"))
                            {
                                detMsg.GameId = EnumGame.B.ToString();
                            }
                            //if not, use regular games
                            else
                            {
                                if (isTH && num.Length == 4)
                                {
                                    detMsg.GameId = EnumGame.D4TH.ToString();
                                }
                                else
                                {
                                    detMsg.GameId = string.Format("D{0}", num.Length);
                                }
                            }
                            detMsg.SalesNumber = num;
                            detMsg.SalesValue  = value * factor;
                            detMsg.IsHBR       = false;

                            //HBR with factor = 2 is for only game D4 only
                            if (isHBR && num.Length == 4)
                            {
                                detMsg.SalesValue = value * 2;
                                detMsg.IsHBR      = true;
                            }
                            listDet.Add(detMsg);
                        }
                    }
                }
            }
            //save trans and details
            TSales sales = SaveTrans(m, agentId, salesNo, salesDate);

            SaveSalesDets(sales, listDet);
        }
Beispiel #22
0
 public void Signal(TMsg msg) => _target.Enqueue(() => _callback(msg));