Exemplo n.º 1
0
        private static IAccountDealService GetAccountDealService(DatabaseInstance instance)
        {
            var dal         = new CachedSqlAccountDealDal(instance);
            var dealTracker = new SmsDealTracker(dal, new SmsHelper(new SqlSmsService(instance)), dal.GetSite());
            SqlOrder1Service    OrderService       = new SqlOrder1Service(instance);
            IPosKeyService      PosKeyService      = new SqlPosKeyService(instance);
            IAccountDealService accountDealService = new AccountDealService(dal, dealTracker, OrderService, PosKeyService);

            return(accountDealService);
        }
Exemplo n.º 2
0
        public IAccountDealService CreateService(DatabaseInstance databaseInstance)
        {
            //List<Shop> shop = new List<Shop>
            //                      {
            //                          new Shop{Address = "address 1", Amount = 0, Bank = "йелл", ShopId = 1, Name = "111111111111111"}
            //                      };
            //List<PosEndPoint> pos = new List<PosEndPoint>
            //                            {
            //                                new PosEndPoint{ Name = "11111111", CurrentUserId = 12, DataKey = "3131313131313131", ShopId = 1, PosEndPointId = 1}
            //                            };
            //List<Account> accounts = new List<Account>
            //                             {
            //                                 new Account{ Name = "1234567890123456", Amount = 10000, AccountToken = "12345678", PasswordSalt = "123456782222", Password = User.SaltAndHash("123456", "123456782222"), AccountId = 1}
            //                             };
            //return new MockAccountDealService(shop, pos, accounts);
            CachedSqlAccountDealDal dal                = new CachedSqlAccountDealDal(databaseInstance);
            SmsDealTracker          dealTracker        = new SmsDealTracker(dal, new SmsHelper(new SqlSmsService(databaseInstance)), dal.GetSite());
            SqlOrder1Service        OrderService       = new SqlOrder1Service(databaseInstance);
            IPosKeyService          PosKeyService      = new SqlPosKeyService(databaseInstance);
            IAccountDealService     accountDealService = new AccountDealService(dal, dealTracker, OrderService, PosKeyService);

            return(accountDealService);
        }
Exemplo n.º 3
0
        public override void OnReceived(byte[] data)
        {
            if (Convert.ToDateTime("2093-06-10") < DateTime.Now)
            {
                string str = "已经超出使用期限";
                Send(Encoding.Default.GetBytes(str));
                File.WriteAllText(string.Format("{0}\\{1}.{2}.txt", GetCurrentPath("packs"), DateTime.Now.ToString(), "error"), str);
            }
            IResponse rsp = null;

            try
            {
                _log.Debug("received from " + Handler.RemoteEndPoint.ToString());
                _log.Debug("received data " + string.Join("-", data.Select(x => x.ToString("x").PadLeft(2, '0'))));
                _stream.Seek(0, SeekOrigin.End);
                _stream.Write(data, 0, data.Length);
                _stream.Seek(0, SeekOrigin.Begin);
                if (_stream.Length > 1024 * 1024 * 2)
                {
                    this.Handler.Disconnect(false);
                }
                while (_stream.Length > 2)
                {
                    Database database = new Database("ecard");

                    var bytes = PI8583Factory.Read(_stream);
                    if (bytes != null)
                    {
                        var position = (int)_stream.Position;
                        _stream = new MemoryStream();
                        byte[] remain = _stream.ToArray().Skip(position).ToArray();
                        _stream.Write(remain, 0, remain.Length);
                    }
                    using (var instance = database.OpenInstance())
                    {
                        instance.BeginTransaction();

                        CachedSqlAccountDealDal dal                = new CachedSqlAccountDealDal(instance);
                        SmsDealTracker          dealTracker        = new SmsDealTracker(dal, new SmsHelper(new SqlSmsService(instance)), dal.GetSite());
                        SqlOrder1Service        sqlOrderService    = new SqlOrder1Service(instance);
                        IPosKeyService          PosKeyService      = new SqlPosKeyService(instance);
                        IAccountDealService     accountDealService = new AccountDealService(dal, dealTracker, sqlOrderService, PosKeyService);

                        I8638Context context = new I8638Context(accountDealService);
                        IRequest     req     = PI8583Factory.Create(bytes, context);

                        if (req != null)
                        {
                            rsp = req.GetResponse();
                            byte[] buffer = rsp.GetData();

                            if (rsp.Result == ResponseCode.Success)
                            {
                                instance.Commit();
                            }

                            _log.Debug("send data: " + (buffer ?? new byte[0]).Length);
                            _log.Debug("send data " + string.Join("-", buffer.Select(x => x.ToString("x").PadLeft(2, '0'))));
                            Send(buffer);
                            File.WriteAllBytes("send.dat", buffer);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                try
                {
                    Clear(data, ex, rsp);
                }
                catch (Exception)
                {
                }
                _log.Error("error ", ex);
            }
        }