Пример #1
0
        public async System.Threading.Tasks.Task RequestTestAsync()
        {
            WMSGetShippingMethodRequest req = new WMSGetShippingMethodRequest("admin", "longqi123456");
            var res = await req.Request();

            var logger    = new Moq.Mock <ILogger <DataAccess> >();
            var sp        = new Moq.Mock <IServiceProvider>();
            var myContext = new Service.Context.XinDBContext(new Microsoft.EntityFrameworkCore.DbContextOptions <Service.Context.XinDBContext>());

            sp.Setup((o) => o.GetService(typeof(IEntityContext))).Returns(myContext);

            sp.Setup((o) => o.GetService(typeof(IRepository <ECShippingMethod>)))
            .Returns(new GenericEntityRepository <ECShippingMethod>(logger.Object));
            var _uowProvider = new UowProvider(logger.Object, sp.Object);

            List <ECShippingMethod> list = new List <ECShippingMethod>();

            using (var uow = _uowProvider.CreateUnitOfWork())
            {
                var repository = uow.GetRepository <ECShippingMethod>();
                foreach (var item in res.Body)
                {
                    var m = Mapper <EC_ShippingMethod, ECShippingMethod> .Map(item);

                    list.Add(m);
                }
                repository.BulkInsert(list, x => x.IncludeGraph = true);
                uow.SaveChanges();
            }
        }
Пример #2
0
        public override async Task Job(DateTime?datetime = null)
        {
            List <ECShippingMethod> insertList = new List <ECShippingMethod>();

            using (var uow = _uowProvider.CreateUnitOfWork())
            {
                var repository = uow.GetRepository <ECShippingMethod>();
                try
                {
                    await repository.DeleteAll();

                    await uow.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    log.Error($"物流承运商信息 - 出现异常:{ex.Message}");
                    throw ex;
                }

                try
                {
                    WMSGetShippingMethodRequest req = new WMSGetShippingMethodRequest(login.Username, login.Password);
                    log.Info($"物流承运商信息 - 开始拉取");

                    var response = await req.Request();

                    foreach (var item in response.Body)
                    {
                        var m = Mapper <EC_ShippingMethod, ECShippingMethod> .Map(item);

                        insertList.Add(m);
                    }
                    repository.BulkInsert(insertList, x => x.IncludeGraph = true);
                    uow.SaveChanges();
                    log.Info("物流承运商信息 - 拉取完成");
                }
                catch (Exception ex)
                {
                    log.Error($"物流承运商信息 - 出现异常:{ex.Message}");
                    throw;
                }
            }
        }