Exemple #1
0
        /// <summary>
        /// 连接测试
        /// </summary>
        public BaseContract TestConnect(string userId)
        {
            var data = new BaseContract();

            data.status = "true";
            return(data);
        }
 /// <summary>
 /// Apply the specified contract.
 /// </summary>
 /// <returns>The apply.</returns>
 /// <param name="contract">Contract.</param>
 public void Apply(BaseContract contract)
 {
     // use reflection to iterate through all contract properties
     // and set to equivalent view model properties
     foreach (PropertyInfo prop in contract.GetType().GetRuntimeProperties())
     {
         var vmProperty            = GetType().GetRuntimeProperty(prop.Name);
         var contractPropertyValue = prop.GetValue(contract);
         vmProperty.SetValue(this, contractPropertyValue);
     }
 }
            public void SaveContract(BaseContract contract)
            {
                if (contract.Address == this.integration.contractRegistryAddress)
                {
                    throw new ArgumentOutOfRangeException(contract.Address + " is a magic address which cannot be used for contracts.");
                }

                if (contract is NonexistentContract)
                {
                    return;
                }

                var data     = StrongForceSerialization.SerializeStatefulObject(contract);
                var typeName = Encoding.ASCII.GetBytes(contract.GetType().Name);

                this.SaveData(contract.Address, data, typeName);
                this.integration.logger.LogTrace("Saved contract data: " + data.Length + " bytes for " + contract.Address);
            }
        private void ContractEvent(BaseContract contract, CustomEventCode code)
        {
            if (null == nebulaObject)
            {
                return;
            }
            var eventInstance = new ItemGeneric {
                ItemId          = nebulaObject.Id,
                ItemType        = nebulaObject.Type,
                CustomEventCode = (byte)code,
                EventData       = contract.GetInfo()
            };
            SendParameters sendParameters = new SendParameters {
                ChannelId  = Settings.ItemEventChannel,
                Unreliable = false
            };
            var eventData = new EventData((byte)EventCode.ItemGeneric, eventInstance);

            ReceiveEvent(eventData, sendParameters);
        }
Exemple #5
0
        public BaseContract Run(PackageGenTypeMethod packageGenType,
                                string batId, string customerId, string unitId, string userId)
        {
            int       pageSize  = 500;                        // 每页数量
            AppType   appType   = AppType.BS;                 //平台类型
            string    bizId     = Utils.NewGuid();
            string    methodKey = "Task.PackageObjectImages"; //定义任务主键
            string    ifCode    = TaskCode.T013.ToString();   //任务编号
            var       data      = new BaseContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = null;
            htLogExt["customer_id"]   = customerId;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = unitId;
            htLogExt["user_code"]     = null;
            htLogExt["user_id"]       = userId;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = appType.ToString();
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("package_gen_type", packageGenType);
                htParams.Add("bat_id", batId);
                htParams.Add("customer_id", customerId);
                htParams.Add("unit_id", unitId);
                htParams.Add("user_id", userId);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, userId, htLogExt);

                bool statusFlag = true;

                // 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                #region Check Length
                htResult = ErrorService.CheckLength("客户ID", customerId, 1, 50, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    throw new Exception(string.Format("批次{0}:客户ID不能为空", batId));
                }
                htResult = ErrorService.CheckLength("门店ID", unitId, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    throw new Exception(string.Format("批次{0}:门店ID不能为空", batId));
                }
                #endregion

                htLogExt["customer_id"] = customerId;

                var dataService = new ExchangeBsService.ObjectImagesBsService();                     //调用中间服务
                // 获取总数量
                int count = dataService.GetObjectImagesNotPackagedCount(customerId, userId, unitId); //获取未打包的商品数量
                if (count <= 0)
                {
                    data.status = Utils.GetStatus(true);
                    return(data);
                }

                // 创建数据包
                string         pkgTypeCode    = PackageTypeMethod.ObjectImages.ToString();//打包类型
                string         pkgGenTypeCode = packageGenType.ToString();
                PackageService pkgService     = new PackageService();
                Hashtable      htPkg          = pkgService.CreatePackage(appType, batId, pkgTypeCode,
                                                                         customerId, unitId, userId, pkgGenTypeCode, null);//创建数据包**使用操作数据库之外的打包程序
                if (!Convert.ToBoolean(htPkg["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htPkg["error_code"].ToString();
                    data.error_full_desc = htPkg["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    Console.WriteLine(data.error_full_desc);
                    return(data);
                }
                string pkgId = htPkg["package_id"].ToString();  //文件夹的名字

                // 循环生成数据包文件
                int num = 0;
                while (num <= count)
                {
                    //使用实体类
                    IList <cPos.Model.ObjectImagesInfo> items = dataService.GetItemListPackaged(
                        customerId, userId, unitId, num, pageSize);  //获取未打包的图片集合
                    if (items.Count <= 0)
                    {
                        break;
                    }
                    num += pageSize;

                    //foreach (var item in items)
                    //{
                    //    item.ItemPropList = dataService.GetItemPropInfoListPackaged(
                    //        customerId, userId, unitId, item.Item_Id);
                    //}

                    //创建文件包
                    Hashtable htPkgf = pkgService.CreateObjectImagessPackageFile(
                        appType, batId, pkgId, userId, null, items);
                    if (!Convert.ToBoolean(htPkgf["status"]))
                    {
                        data.status          = Utils.GetStatus(false);
                        data.error_code      = htPkgf["error_code"].ToString();
                        data.error_full_desc = htPkgf["error_desc"].ToString();
                        LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                        Console.WriteLine(data.error_full_desc);
                        return(data);
                    }
                    // 记录数据打包批次号
                    dataService.SetObjectImagesBatInfo(customerId, userId, unitId, batId, items);
                }

                // 发布数据包
                Hashtable htPkgPublish = pkgService.PublishPackage(appType, batId, pkgId, userId);
                if (!Convert.ToBoolean(htPkgPublish["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htPkgPublish["error_code"].ToString();
                    data.error_full_desc = htPkgPublish["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    Console.WriteLine(data.error_full_desc);
                    return(data);
                }

                // 更新数据打包标识
                dataService.SetObjectImagesIfFlagInfo(customerId, userId, unitId, batId);

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                Console.WriteLine(data.error_full_desc);
            }
            return(data);
        }
Exemple #6
0
        public BaseContract Run(PackageGenTypeMethod packageGenType,
                                string batId, string customerId, string unitId, string userId)
        {
            //int pageSize = 500; // 每页数量
            AppType   appType   = AppType.BS;
            string    bizId     = Utils.NewGuid();
            string    methodKey = "Task.PackageSkuProps";
            string    ifCode    = TaskCode.T006.ToString();
            var       data      = new BaseContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = null;
            htLogExt["customer_id"]   = customerId;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = unitId;
            htLogExt["user_code"]     = null;
            htLogExt["user_id"]       = userId;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = appType.ToString();
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("package_gen_type", packageGenType);
                htParams.Add("bat_id", batId);
                htParams.Add("customer_id", customerId);
                htParams.Add("unit_id", unitId);
                htParams.Add("user_id", userId);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, userId, htLogExt);

                bool statusFlag = true;

                // 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                #region Check Length
                htResult = ErrorService.CheckLength("客户ID", customerId, 1, 50, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    throw new Exception(string.Format("批次{0}:客户ID不能为空", batId));
                }
                htResult = ErrorService.CheckLength("门店ID", unitId, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    throw new Exception(string.Format("批次{0}:门店ID不能为空", batId));
                }
                #endregion

                htLogExt["customer_id"] = customerId;

                var dataService = new ExchangeBsService.SkuBsService();

                string         pkgTypeCode    = PackageTypeMethod.SKUPROPS.ToString();
                string         pkgGenTypeCode = packageGenType.ToString();
                PackageService pkgService     = new PackageService();

                // 判断是否已打包
                var isPackaged = pkgService.CheckIsPackaged(customerId, pkgTypeCode);
                if (isPackaged > 0)
                {
                    data.status = Utils.GetStatus(true);
                    return(data);
                }

                // 获取数据
                var items = dataService.GetSkuPropListPackage(customerId, userId, unitId);
                if (items == null || items.Count <= 0)
                {
                    data.status = Utils.GetStatus(true);
                    return(data);
                }

                // 创建数据包
                Hashtable htPkg = pkgService.CreatePackage(appType, batId, pkgTypeCode,
                                                           customerId, null, userId, pkgGenTypeCode, null);
                if (!Convert.ToBoolean(htPkg["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htPkg["error_code"].ToString();
                    data.error_full_desc = htPkg["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    Console.WriteLine(data.error_full_desc);
                    return(data);
                }
                string pkgId = htPkg["package_id"].ToString();

                // 生成数据包文件
                Hashtable htPkgf = pkgService.CreateSkuPropsPackageFile(
                    appType, batId, pkgId, userId, null, items);
                if (!Convert.ToBoolean(htPkgf["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htPkgf["error_code"].ToString();
                    data.error_full_desc = htPkgf["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    Console.WriteLine(data.error_full_desc);
                    return(data);
                }

                // 发布数据包
                Hashtable htPkgPublish = pkgService.PublishPackage(appType, batId, pkgId, userId);
                if (!Convert.ToBoolean(htPkgPublish["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htPkgPublish["error_code"].ToString();
                    data.error_full_desc = htPkgPublish["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    Console.WriteLine(data.error_full_desc);
                    return(data);
                }

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                Console.WriteLine(data.error_full_desc);
            }
            return(data);
        }
Exemple #7
0
        public BaseContract Run(PackageGenTypeMethod packageGenType,
                                string batId, string customerId, string unitId, string userId)
        {
            int       pageSize  = 1000; // 每页数量
            AppType   appType   = AppType.AP;
            string    bizId     = Utils.NewGuid();
            string    methodKey = "Task.PackageMobileUnit";
            string    ifCode    = TaskCode.T012.ToString();
            var       data      = new BaseContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = null;
            htLogExt["customer_id"]   = customerId;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = unitId;
            htLogExt["user_code"]     = null;
            htLogExt["user_id"]       = userId;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = appType.ToString();
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("package_gen_type", packageGenType);
                htParams.Add("bat_id", batId);
                htParams.Add("customer_id", customerId);
                htParams.Add("unit_id", unitId);
                htParams.Add("user_id", userId);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, userId, htLogExt);

                bool statusFlag = true;

                // 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                #region Check Length
                htResult = ErrorService.CheckLength("用户ID", userId, 1, 50, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    throw new Exception(string.Format("批次{0}:用户ID不能为空", batId));
                }
                #endregion

                htLogExt["customer_id"] = customerId;

                var dataService       = new ExchangeBsService.UnitBsService();
                var apCustomerService = new cPos.Admin.Service.Implements.CustomerService();

                // 获取总数量
                int customersCount = apCustomerService.GetMobileCustomerNotPackagedCount(customerId, userId, unitId);
                int unitsCount     = apCustomerService.GetMobileCustomerShopNotPackagedCount(customerId, userId, unitId);
                if (customersCount <= 0 && unitsCount <= 0)
                {
                    data.status = Utils.GetStatus(true);
                    return(data);
                }

                // 创建数据包
                string         pkgTypeCode    = PackageTypeMethod.MOBILE.ToString();
                string         pkgGenTypeCode = packageGenType.ToString();
                PackageService pkgService     = new PackageService();
                Hashtable      htPkg          = pkgService.CreatePackage(appType, batId, pkgTypeCode,
                                                                         customerId, unitId, userId, pkgGenTypeCode, null, null, AppType.MOBILE.ToString());
                if (!Convert.ToBoolean(htPkg["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htPkg["error_code"].ToString();
                    data.error_full_desc = htPkg["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    Console.WriteLine(data.error_full_desc);
                    return(data);
                }
                string pkgId = htPkg["package_id"].ToString();

                // 循环生成数据包文件
                int num = 0;
                IList <cPos.Admin.Model.Customer.CustomerInfo> customers = apCustomerService.GetMobileCustomerListNotPackaged(
                    customerId, userId, unitId, num, pageSize);
                IList <cPos.Admin.Model.Customer.CustomerShopInfo> units = apCustomerService.GetMobileCustomerShopListNotPackaged(
                    customerId, userId, unitId, num, pageSize);


                Hashtable htPkgf = pkgService.CreateMoblieCustomerAndUnitsPackageFile(
                    appType, batId, pkgId, userId, null, customers, units);
                if (!Convert.ToBoolean(htPkgf["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htPkgf["error_code"].ToString();
                    data.error_full_desc = htPkgf["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    Console.WriteLine(data.error_full_desc);
                    return(data);
                }
                // 记录数据打包批次号
                apCustomerService.SetMobileCustomerBatInfo(customerId, userId, unitId, batId, customers);
                apCustomerService.SetMobileCustomerShopBatInfo(customerId, userId, unitId, batId, units);


                // 发布数据包
                Hashtable htPkgPublish = pkgService.PublishPackage(appType, batId, pkgId, userId);
                if (!Convert.ToBoolean(htPkgPublish["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htPkgPublish["error_code"].ToString();
                    data.error_full_desc = htPkgPublish["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    Console.WriteLine(data.error_full_desc);
                    return(data);
                }

                // 更新数据打包标识
                apCustomerService.UpdateMobileCustomerNotPackagedIfFlag(customerId, userId, unitId, batId);
                apCustomerService.UpdateMobileCustomerShopNotPackagedIfFlag(customerId, userId, unitId, batId);

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                Console.WriteLine(data.error_full_desc);
            }
            return(data);
        }
 public void ContractStageChanged(BaseContract contract)
 {
     ContractEvent(contract, CustomEventCode.ContractStageChanged);
 }
 public void ContractReady(BaseContract contract)
 {
     ContractEvent(contract, CustomEventCode.ContractReady);
 }
Exemple #10
0
        public BaseContract Run(PackageGenTypeMethod packageGenType,
                                string batId, string customerId, string unitId, string userId)
        {
            AppType   appType   = AppType.BS;
            string    bizId     = Utils.NewGuid();
            string    methodKey = "Task.PackageUsers";
            string    ifCode    = TaskCode.T001.ToString();
            var       data      = new BaseContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = null;
            htLogExt["customer_id"]   = customerId;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = unitId;
            htLogExt["user_code"]     = null;
            htLogExt["user_id"]       = userId;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = appType.ToString();
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("package_gen_type", packageGenType);
                htParams.Add("bat_id", batId);
                htParams.Add("customer_id", customerId);
                htParams.Add("unit_id", unitId);
                htParams.Add("user_id", userId);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, userId, htLogExt);

                bool statusFlag = true;

                // 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                #region Check Length
                htResult = ErrorService.CheckLength("客户ID", customerId, 1, 50, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    throw new Exception(string.Format("批次{0}:客户ID不能为空", batId));
                }
                htResult = ErrorService.CheckLength("门店ID", unitId, 0, 50, true, true, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    throw new Exception(string.Format("批次{0}:门店ID不能为空", batId));
                }
                #endregion

                htLogExt["customer_id"] = customerId;

                // 循环生成数据包
                int count = 1000; // 获取总数量
                //int pageSize = 500; // 每页数量
                int num = 0;

                while (num <= count)
                {
                    ExchangeBsService.UserAuthService bsUserAuthService = new ExchangeBsService.UserAuthService();
                    cPos.Model.BaseInfo usersInfo = bsUserAuthService.GetUserBaseByUserId(userId, customerId, unitId);
                    string         pkgBatId       = Utils.NewGuid();
                    string         pkgTypeCode    = PackageTypeMethod.USERS.ToString();
                    string         pkgGenTypeCode = packageGenType.ToString();
                    PackageService pkgService     = new PackageService();
                    Hashtable      htPkg          = pkgService.CreatePackage(appType, pkgBatId, pkgTypeCode,
                                                                             customerId, unitId, userId, pkgGenTypeCode, null, null, AppType.POS.ToString());
                    if (!Convert.ToBoolean(htPkg["status"]))
                    {
                        data.status          = Utils.GetStatus(false);
                        data.error_code      = htPkg["error_code"].ToString();
                        data.error_full_desc = htPkg["error_desc"].ToString();
                        LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                        Console.WriteLine(data.error_full_desc);
                        return(data);
                    }
                    string    pkgId  = htPkg["package_id"].ToString();
                    Hashtable htPkgf = pkgService.CreateUsersProfilePackageFile(
                        AppType.Client, pkgBatId, pkgId, userId, null,
                        usersInfo.CurrMenuInfoList, usersInfo.CurrRoleInfoList,
                        usersInfo.CurrRoleMenuInfoList, usersInfo.CurrSalesUserInfoList,
                        usersInfo.CurrSalesUserRoleInfoList);
                    if (!Convert.ToBoolean(htPkgf["status"]))
                    {
                        data.status          = Utils.GetStatus(false);
                        data.error_code      = htPkgf["error_code"].ToString();
                        data.error_full_desc = htPkgf["error_desc"].ToString();
                        LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                        Console.WriteLine(data.error_full_desc);
                        return(data);
                    }
                    Hashtable htPkgPublish = pkgService.PublishPackage(AppType.Client, pkgBatId, pkgId, userId);
                    if (!Convert.ToBoolean(htPkgPublish["status"]))
                    {
                        data.status          = Utils.GetStatus(false);
                        data.error_code      = htPkgPublish["error_code"].ToString();
                        data.error_full_desc = htPkgPublish["error_desc"].ToString();
                        LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                        Console.WriteLine(data.error_full_desc);
                        return(data);
                    }
                }

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                Console.WriteLine(data.error_full_desc);
            }
            return(data);
        }
 public void ContractDeclined(BaseContract contract)
 {
     ContractEvent(contract, CustomEventCode.ContractDeclined);
 }
Exemple #12
0
        /// <summary>
        /// 修改用户密码接口
        /// </summary>
        public BaseContract ChangePassword(TransType transType,
                                           string userId, string token, string unitId, string newPassword)
        {
            string    bizId     = Utils.NewGuid();
            string    methodKey = "AuthService.ChangePassword";
            string    ifCode    = "C029";
            var       data      = new BaseContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = null;
            htLogExt["customer_id"]   = null;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = unitId;
            htLogExt["user_code"]     = null;
            htLogExt["user_id"]       = userId;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = AppType.Client;
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("trans_type", transType);
                htParams.Add("user_id", userId);
                htParams.Add("token", token);
                htParams.Add("unit_id", unitId);
                htParams.Add("new_password", newPassword);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, null, htLogExt);

                bool      statusFlag = false;
                Hashtable htError    = null;
                CertInfo  certInfo   = null;

                Dex.Services.AuthService authService = new Dex.Services.AuthService();

                // 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                #region Check Length
                htResult = ErrorService.CheckLength("用户ID", userId, 1, 32, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <BaseContract>(htResult));
                }
                //htResult = ErrorService.CheckLength("令牌", token, 1, 32, true, false, ref paramCheckFlag);
                //if (!paramCheckFlag) return ErrorConvert.Export<BaseContract>(htResult);
                htResult = ErrorService.CheckLength("门店ID", unitId, 1, 32, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <BaseContract>(htResult));
                }
                htResult = ErrorService.CheckLength("用户新密码", newPassword, 1, 40, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    return(ErrorConvert.Export <BaseContract>(htResult));
                }
                #endregion

                // 检查User和Customer
                certInfo = authService.GetCertByUserId(userId);
                if (certInfo == null)
                {
                    htError              = ErrorService.OutputError(ErrorCode.A006, "用户ID不存在", true);
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    return(data);
                }

                statusFlag = true;
                // 检查Token是否不匹配或过期
                //statusFlag = authService.CheckCertToken(token, certInfo.CertId, userId);
                //if (!statusFlag)
                //{
                //    htError = ErrorService.OutputError(ErrorCode.A005, "令牌不匹配或过期", true);
                //    data.status = Utils.GetStatus(false);
                //    data.error_code = htError["error_code"].ToString();
                //    data.error_full_desc = htError["error_desc"].ToString();
                //    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                //    return data;
                //}

                // 查询凭证
                certInfo = authService.GetCertByUserId(userId);
                if (certInfo == null || certInfo.CustomerId == null || certInfo.CustomerId.Length == 0)
                {
                    htError              = ErrorService.OutputError(ErrorCode.A007, "获取后台数据(客户ID)失败", true);
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htError["error_code"].ToString();
                    data.error_full_desc = htError["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    return(data);
                }

                string customerId = certInfo.CustomerId;

                htLogExt["customer_code"] = certInfo.CustomerCode;
                htLogExt["customer_id"]   = certInfo.CustomerId;
                htLogExt["user_code"]     = certInfo.UserCode;

                // 提交
                var bsAuthService = new ServicesBs.AuthService();
                bsAuthService.ChangePassword(customerId, unitId, userId, newPassword);
                authService.UpdateCertPwdByUserId(userId, newPassword);

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), null, htLogExt);
            }
            return(data);
        }
Exemple #13
0
        public static T Export <T>(Hashtable htError) where T : BaseContract
        {
            BaseContract contract = null;

            if (typeof(T) == typeof(BaseContract))
            {
                contract = new BaseContract();
            }
            if (typeof(T) == typeof(ValidateContract))
            {
                contract = new ValidateContract();
            }
            if (typeof(T) == typeof(GetUserUnitRelationsContract))
            {
                contract = new GetUserUnitRelationsContract();
            }
            if (typeof(T) == typeof(GetUsersProfileContract))
            {
                contract = new GetUsersProfileContract();
            }
            if (typeof(T) == typeof(GetPosCodeContract))
            {
                contract = new GetPosCodeContract();
            }
            if (typeof(T) == typeof(GetLogsContract))
            {
                contract = new GetLogsContract();
            }
            if (typeof(T) == typeof(GetLogContract))
            {
                contract = new GetLogContract();
            }
            if (typeof(T) == typeof(GetPackagesContract))
            {
                contract = new GetPackagesContract();
            }
            if (typeof(T) == typeof(GetPackagesCountContract))
            {
                contract = new GetPackagesCountContract();
            }
            if (typeof(T) == typeof(GetPackageFilesContract))
            {
                contract = new GetPackageFilesContract();
            }
            if (typeof(T) == typeof(GetPackageFilesCountContract))
            {
                contract = new GetPackageFilesCountContract();
            }
            if (typeof(T) == typeof(UploadInoutOrdersContract))
            {
                contract = new UploadInoutOrdersContract();
            }
            if (typeof(T) == typeof(GetCountContract))
            {
                contract = new GetCountContract();
            }
            if (typeof(T) == typeof(GetStockBalancesContract))
            {
                contract = new GetStockBalancesContract();
            }
            if (typeof(T) == typeof(UploadContract))
            {
                contract = new UploadContract();
            }
            if (typeof(T) == typeof(GetVipsContract))
            {
                contract = new GetVipsContract();
            }
            if (typeof(T) == typeof(GetVipContract))
            {
                contract = new GetVipContract();
            }
            if (typeof(T) == typeof(ExistVipNoContract))
            {
                contract = new ExistVipNoContract();
            }
            if (typeof(T) == typeof(DownloadInoutOrdersContract))
            {
                contract = new DownloadInoutOrdersContract();
            }
            if (typeof(T) == typeof(DownloadCcOrdersContract))
            {
                contract = new DownloadCcOrdersContract();
            }
            if (typeof(T) == typeof(GetAnnsContract))
            {
                contract = new GetAnnsContract();
            }
            if (typeof(T) == typeof(GetPriceOrdersContract))
            {
                contract = new GetPriceOrdersContract();
            }
            if (typeof(T) == typeof(CheckVersionContract))
            {
                contract = new CheckVersionContract();
            }
            if (typeof(T) == typeof(GetUnitXmlConfigInfoContract))
            {
                contract = new GetUnitXmlConfigInfoContract();
            }
            if (typeof(T) == typeof(GetItemInfoContract))
            {
                contract = new GetItemInfoContract();
            }
            if (typeof(T) == typeof(ApplyCustomerAndUnitContract))
            {
                contract = new ApplyCustomerAndUnitContract();
            }

            contract.status          = htError["status"].ToString();
            contract.error_code      = htError["error_code"].ToString();
            contract.error_full_desc = htError["error_desc"].ToString();
            return((T)contract);
        }
Exemple #14
0
        public BaseContract Run(PackageGenTypeMethod packageGenType,
                                string batId, string customerId, string unitId, string userId)
        {
            int       pageSize  = 500; // 每页数量
            AppType   appType   = AppType.AP;
            string    bizId     = Utils.NewGuid();
            string    methodKey = "Task.PackageMobile";
            string    ifCode    = TaskCode.T011.ToString();
            var       data      = new BaseContract();
            Hashtable htLogExt  = new Hashtable();

            htLogExt["customer_code"] = null;
            htLogExt["customer_id"]   = customerId;
            htLogExt["unit_code"]     = null;
            htLogExt["unit_id"]       = unitId;
            htLogExt["user_code"]     = null;
            htLogExt["user_id"]       = userId;
            htLogExt["if_code"]       = ifCode;
            htLogExt["app_code"]      = appType.ToString();
            try
            {
                Hashtable htParams = new Hashtable();
                htParams.Add("package_gen_type", packageGenType);
                htParams.Add("bat_id", batId);
                htParams.Add("customer_id", customerId);
                htParams.Add("unit_id", unitId);
                htParams.Add("user_id", userId);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Params.ToString(), htParams, userId, htLogExt);

                bool statusFlag = true;

                // 检查参数
                Hashtable htResult       = new Hashtable();
                bool      paramCheckFlag = false;
                #region Check Length
                htResult = ErrorService.CheckLength("用户ID", userId, 1, 50, true, false, ref paramCheckFlag);
                if (!paramCheckFlag)
                {
                    throw new Exception(string.Format("批次{0}:用户ID不能为空", batId));
                }
                #endregion

                htLogExt["customer_id"] = customerId;

                var dataService = new cPos.Admin.Service.SkuService();

                // 获取总数量
                int count = dataService.GetSkuNotPackagedCount();
                if (count <= 0)
                {
                    data.status = Utils.GetStatus(true);
                    return(data);
                }

                // 创建数据包
                string         pkgTypeCode    = PackageTypeMethod.MOBILE.ToString();
                string         pkgGenTypeCode = packageGenType.ToString();
                PackageService pkgService     = new PackageService();
                Hashtable      htPkg          = pkgService.CreatePackage(appType, batId, pkgTypeCode,
                                                                         customerId, unitId, userId, pkgGenTypeCode, null, null, "MOBILE");
                if (!Convert.ToBoolean(htPkg["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htPkg["error_code"].ToString();
                    data.error_full_desc = htPkg["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    Console.WriteLine(data.error_full_desc);
                    return(data);
                }
                string pkgId = htPkg["package_id"].ToString();

                // 循环生成数据包文件
                int num = 0;
                while (num <= count)
                {
                    IList <cPos.Model.SkuInfo> items = dataService.GetSkuListPackaged(pageSize, num);
                    if (items.Count <= 0)
                    {
                        break;
                    }
                    num += pageSize;

                    Hashtable htPkgf = pkgService.CreateMobileSkusPackageFile(
                        appType, batId, pkgId, userId, null, items);
                    if (!Convert.ToBoolean(htPkgf["status"]))
                    {
                        data.status          = Utils.GetStatus(false);
                        data.error_code      = htPkgf["error_code"].ToString();
                        data.error_full_desc = htPkgf["error_desc"].ToString();
                        LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                        Console.WriteLine(data.error_full_desc);
                        return(data);
                    }
                    // 记录数据打包批次号
                    dataService.SetSkuBatInfo(batId, items, userId);
                }

                // 发布数据包
                Hashtable htPkgPublish = pkgService.PublishPackage(appType, batId, pkgId, userId);
                if (!Convert.ToBoolean(htPkgPublish["status"]))
                {
                    data.status          = Utils.GetStatus(false);
                    data.error_code      = htPkgPublish["error_code"].ToString();
                    data.error_full_desc = htPkgPublish["error_desc"].ToString();
                    LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                    Console.WriteLine(data.error_full_desc);
                    return(data);
                }

                // 更新数据打包标识
                dataService.SetSkuIfFlagInfo(batId, userId);

                data.status = Utils.GetStatus(statusFlag);
                LogService.WriteTrace(bizId, methodKey, TraceLogType.Return.ToString(), data.ToString(), userId, htLogExt);
            }
            catch (Exception ex)
            {
                data.status          = Utils.GetStatus(false);
                data.error_code      = ErrorCode.A000.ToString();
                data.error_full_desc = ex.ToString();
                LogService.WriteError(bizId, methodKey, data.error_code, data.ToString(), userId, htLogExt);
                Console.WriteLine(data.error_full_desc);
            }
            return(data);
        }
 public void ContractCompleted(BaseContract contract)
 {
     ContractEvent(contract, CustomEventCode.ContractCompleted);
 }
Exemple #16
0
 public EthFunc(BaseContract contract, byte[] callData, ParseResponseDelegate parseResponse) : base(contract, callData)
 {
     _parseResponse = parseResponse;
 }
Exemple #17
0
        static void Main(string[] args)
        {
            string logFolderPath = @"C:\cpos_log\task\";   //日志文件地址

            try
            {
                int    cycleTime = 60000;
                string userId    = "0ed1a737a178491c86278b001a059a15";
                string unitId    = null; // "1"
                string batId     = string.Empty;
                PackageGenTypeMethod packageGenType = PackageGenTypeMethod.AUTO_TASK;
                var exPackageService  = new cPos.ExchangeService.DexPackageService();
                var apCustomerService = new cPos.Admin.Service.Implements.CustomerService();
                var apUserService     = new cPos.Admin.Service.Implements.UserService();

                while (true)
                {
                    Console.WriteLine(string.Format("[{0}]任务批次开始...", Utils.GetNow()));
                    Common.PackageIds.Clear();

                    // 获取客户列表
                    Hashtable htCustomer = new Hashtable();
                    htCustomer["Status"] = "1";
                    IList <cPos.Admin.Model.Customer.CustomerInfo> customers =
                        apCustomerService.GetAllCustomerList(htCustomer);
                    WorkerType   workerType;
                    BaseContract result          = new BaseContract();
                    string       taskBeginFormat = "[{0}] {2} {1}任务开始...";
                    string       taskEndFormat   = "[{0}] {2} {1}任务结束";
                    foreach (var customer in customers)
                    {
                        if (!customer.IsPad.Equals(1))
                        {
                            Console.WriteLine(string.Format("[{0} {1}]该客户暂未开放同步功能.", Utils.GetNow(), customer.Code));
                            continue;
                        }
                        //if (customer.Code.Equals("nestle"))//测试单个客户
                        //{

                        // Package - ObjectImages  新增图片
                        if (true)
                        {
                            workerType = WorkerType.ObjectImages;
                            batId      = Utils.NewGuid();
                            Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType, customer.Code));
                            var worker = new PackageObjectImages();
                            result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                            Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType, customer.Code));
                        }
                        //}

                        // Package - SkuPrices
                        if (true)
                        {
                            unitId     = null;
                            workerType = WorkerType.SkuPrices;
                            batId      = Utils.NewGuid();
                            Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType, customer.Code));
                            var worker = new PackageSkuPrices();
                            result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                            Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType, customer.Code));
                        }

                        // Package - ItemProps
                        if (true)
                        {
                            workerType = WorkerType.ItemProps;
                            batId      = Utils.NewGuid();
                            Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType, customer.Code));
                            var worker = new PackageItemProps();
                            result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                            Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType, customer.Code));
                        }
                        // Package - SkuProps
                        if (true)
                        {
                            workerType = WorkerType.SkuProps;
                            batId      = Utils.NewGuid();
                            Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType, customer.Code));
                            var worker = new PackageSkuProps();
                            result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                            Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType, customer.Code));
                        }
                        // Package - Items
                        if (true)
                        {
                            workerType = WorkerType.Items;
                            batId      = Utils.NewGuid();
                            Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType, customer.Code));
                            var worker = new PackageItems();
                            result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                            Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType, customer.Code));
                        }
                        // Package - ItemsCategory
                        if (true)
                        {
                            workerType = WorkerType.ItemCategorys;
                            batId      = Utils.NewGuid();
                            Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType, customer.Code));
                            var worker = new PackageItemCategorys();
                            result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                            Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType, customer.Code));
                        }

                        // Package - Skus
                        if (true)
                        {
                            workerType = WorkerType.Skus;
                            batId      = Utils.NewGuid();
                            Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType, customer.Code));
                            var worker = new PackageSkus();
                            result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                            Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType, customer.Code));
                        }
                        // Package - Units
                        if (true)
                        {
                            workerType = WorkerType.Units;
                            batId      = Utils.NewGuid();
                            Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType, customer.Code));
                            var worker = new PackageUnits();
                            result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                            Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType, customer.Code));
                        }



                        //// Package - Users
                        //if (true)
                        //{
                        //    workerType = WorkerType.Users;
                        //    batId = Utils.NewGuid();
                        //    Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType, customer.Code));
                        //    var worker = new PackageUsers();
                        //    result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                        //    Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType, customer.Code));
                        //}

                        #region
                        // Package - ItemPrices
                        //if (false)
                        //{
                        //    workerType = WorkerType.SkuProps;
                        //    batId = Utils.NewGuid();
                        //    Console.WriteLine(string.Format("[{0}] {1}任务开始...", Utils.GetNow(), workerType));
                        //    var worker = new PackageItemPrices();
                        //    result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                        //    Console.WriteLine(string.Format("[{0}] {1}任务结束", Utils.GetNow(), workerType));
                        //}
                        //// Package - Users
                        //if (false)
                        //{
                        //    workerType = WorkerType.Users;
                        //    batId = Utils.NewGuid();
                        //    Console.WriteLine(string.Format("[{0}] {1}任务开始...", Utils.GetNow(), workerType));
                        //    var worker = new PackageUsers();
                        //    result = worker.Run(packageGenType, batId, customer.ID, unitId, userId);
                        //    Console.WriteLine(string.Format("[{0}] {1}任务结束", Utils.GetNow(), workerType));
                        //}

                        //// 获取门店列表
                        //Hashtable htUnit = new Hashtable();
                        //htUnit["CustomerID"] = customer.ID;
                        //htUnit["ShopStatus"] = "1";
                        //IList<MVS.cPos.Model.Customer.CustomerShopInfo> units =
                        //    apCustomerService.GetAllShopList(htUnit);
                        //foreach (var unit in units)
                        //{
                        //    if (true)
                        //    {
                        //        workerType = WorkerType.ItemPrices;
                        //        batId = Utils.NewGuid();
                        //        Console.WriteLine(string.Format("[{0}] {1} {2}任务开始...",
                        //            Utils.GetNow(), workerType, unit.Code));
                        //        var worker = new PackageItemPrices();
                        //        result = worker.Run(packageGenType, batId, customer.ID, unit.ID, userId);
                        //        Console.WriteLine(string.Format("[{0}] {1} {2}任务结束:{3}.",
                        //            Utils.GetNow(), workerType, unit.Code, result.status));
                        //    }
                        //}
                        #endregion
                    }

                    // 导出mobile人员(客户、门店)相关数据
                    if (false)
                    {
                        IList <cPos.Admin.Model.User.UserInfo> mobileUserList = null;
                        Hashtable htMoblieUser = new Hashtable();
                        htMoblieUser["RoleCode"] = "MobileSales";
                        mobileUserList           = apUserService.GetUserList(htMoblieUser);
                        if (mobileUserList != null && mobileUserList.Count > 0)
                        {
                            foreach (var mobileUser in mobileUserList)
                            {
                                // Package - Mobile-customers,units
                                if (true)
                                {
                                    unitId     = null;
                                    workerType = WorkerType.Mobile;
                                    batId      = Utils.NewGuid();
                                    Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType,
                                                                    "MOBILE-" + mobileUser.Account));
                                    var worker = new PackageMobileUnit();
                                    result = worker.Run(packageGenType, batId, null, null, mobileUser.ID);
                                    Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType,
                                                                    "MOBILE-" + mobileUser.Account));
                                }
                            }
                        }
                    }

                    // Package - Mobile基础数据
                    if (false)
                    {
                        unitId     = null;
                        workerType = WorkerType.Mobile;
                        batId      = Utils.NewGuid();
                        Console.WriteLine(string.Format(taskBeginFormat, Utils.GetNow(), workerType, "MOBILE"));
                        var worker = new PackageMobile();
                        result = worker.Run(packageGenType, batId, null, unitId, userId);
                        Console.WriteLine(string.Format(taskEndFormat, Utils.GetNow(), workerType, "MOBILE"));
                    }

                    // 发布数据包
                    Console.WriteLine(string.Format("[{0}]数据包发布开始...", Utils.GetNow()));
                    foreach (var packageId in Common.PackageIds)
                    {
                        exPackageService.PublishPackage(batId, packageId, userId);
                    }
                    Console.WriteLine(string.Format("[{0}]数据包发布完成", Utils.GetNow()));

                    Console.WriteLine(string.Format("[{0}]任务批次结束", Utils.GetNow()));
                    Console.WriteLine(string.Format("".PadLeft(50, '=')));
                    Thread.Sleep(cycleTime);
                }
            }
            catch (Exception ex)
            {
                Utils.SaveFile(logFolderPath, Utils.GetNowString() + ".log", ex.ToString());
                Console.Write(ex.ToString());
                Console.Read();
            }
        }