Beispiel #1
0
 public IReadOnlyList <Permission> GetAllPermissions(bool tenancyFilter = true)
 {
     //var key = (CurrentUnitOfWork.GetTenantId() ?? 0) + tenancyFilter.ToString();
     //Logger.Info("StartGetAllPermissionByFeature");
     //var result = _cacheManager.GetCache<string, IReadOnlyList<Permission>>("PermissionsByFeature").Get(key, () => {
     //    using (var featureDependencyContext = _iocManager.ResolveAsDisposable<FeatureDependencyContext>())
     //    {
     //        var featureDependencyContextObject = featureDependencyContext.Object;
     //        return GetAll()
     //            .WhereIf(tenancyFilter, p => p.MultiTenancySides.HasFlag(AbpSession.MultiTenancySide))
     //            .Where(p =>
     //                p.FeatureDependency == null ||
     //                AbpSession.MultiTenancySide == MultiTenancySides.Host ||
     //                p.FeatureDependency.IsSatisfied(featureDependencyContextObject)
     //            ).ToImmutableList();
     //    }
     //});
     //Logger.Info("EndGetAllPermissionsByFeature");
     //return result;
     using (var featureDependencyContext = _iocManager.ResolveAsDisposable <FeatureDependencyContext>())
     {
         var featureDependencyContextObject = featureDependencyContext.Object;
         var result = GetAll()
                      .WhereIf(tenancyFilter, p => p.MultiTenancySides.HasFlag(AbpSession.MultiTenancySide))
                      .Where(p =>
                             p.FeatureDependency == null ||
                             AbpSession.MultiTenancySide == MultiTenancySides.Host ||
                             p.FeatureDependency.IsSatisfied(featureDependencyContextObject)
                             ).ToImmutableList();
         return(result);
     }
 }
        public IDisposableDependencyObjectWrapper <IExternalLoginInfoManager> GetExternalLoginInfoManager(string loginProvider)
        {
            if (loginProvider == "WsFederation")
            {
                return(_iocManager.ResolveAsDisposable <WsFederationExternalLoginInfoManager>());
            }

            return(_iocManager.ResolveAsDisposable <DefaultExternalLoginInfoManager>());
        }
        public void Initialize()
        {
            foreach (var providerType in _authorizationConfiguration.Providers)
            {
                using (var provider = _iocManager.ResolveAsDisposable <AuthorizationProvider>(providerType))
                {
                    provider.Object.SetPermissions(this);
                }
            }

            Permissions.AddAllPermissions();
        }
Beispiel #4
0
 public void Initialize()
 {
     foreach (var providerType in _authorizationConfiguration.Providers)
     {
         _iocManager.RegisterIfNot(providerType, DependencyLifeStyle.Transient); //TODO: Needed?
         using (var provider = _iocManager.ResolveAsDisposable <AuthorizationProvider>(providerType))
         {
             provider.Object.SetPermissions(this);
         }
     }
     Permissions.AddAllPermissions();
 }
 public IReadOnlyList <Permission> GetAllPermissions(bool tenancyFilter = true)
 {
     using (var featureDependencyContext = _iocManager.ResolveAsDisposable <FeatureDependencyContext>())
     {
         var featureDependencyContextObject = featureDependencyContext.Object;
         return(GetAllPermissions()
                .WhereIf(tenancyFilter, p => p.MultiTenancySides.HasFlag(AbpSession.MultiTenancySide))
                .Where(p =>
                       p.FeatureDependency == null ||
                       AbpSession.MultiTenancySide == MultiTenancySides.Host ||
                       p.FeatureDependency.IsSatisfied(featureDependencyContextObject)
                       ).ToImmutableList());
     }
 }
Beispiel #6
0
        /// <summary>
        ///     执行回调逻辑
        /// </summary>
        /// <param name="key">支付业务关键字</param>
        /// <param name="outTradeNo">商户系统的订单号</param>
        /// <param name="totalFee">金额(单位:分)</param>
        /// <param name="transactionId">微信支付订单号</param>
        /// <returns></returns>
        public async Task ExecuteCallback(string key, string outTradeNo, string transactionId, decimal totalFee)
        {
            using (var obj = _iocManager.ResolveAsDisposable <TransactionLogHelper>())
            {
                //更新交易日志
                await obj.Object.UpdateAsync(outTradeNo, transactionId, async (unitOfWork, logInfo) =>
                {
                    var data = logInfo.CustomData.FromJsonString <JObject>();
                    Logger?.Info($"正在执行【{key}】回调逻辑。data:{data?.ToJsonString()}");

                    if (!decimal.Equals(logInfo.Currency.CurrencyValue, totalFee))
                    {
                        throw new UserFriendlyException(
                            $"支付金额不一致:要求支付金额为:{logInfo.Currency.CurrencyValue},实际支付金额为:{totalFee}");
                    }

                    var paymentCallbackAction = PaymentCallbackActions?.FirstOrDefault(p => p.Key == key);
                    if (paymentCallbackAction == null)
                    {
                        throw new UserFriendlyException($"Key:{key} 不存在,请使用Register方法进行注册");
                    }

                    await paymentCallbackAction.Process(unitOfWork, logInfo);
                });
            }
        }
Beispiel #7
0
 private static void Test_Way_2(IIocManager iocManager)
 {
     using (var tester = iocManager.ResolveAsDisposable <Tester>())
     {
         tester.Object.Test();
     }
 }
Beispiel #8
0
 /// <summary>
 ///     This method can be used to resolve and release an object automatically.
 ///     You can use the object in <see cref="func" /> and return a value.
 /// </summary>
 /// <typeparam name="TService">Type of the service to use</typeparam>
 /// <typeparam name="TReturn">Return type</typeparam>
 /// <param name="iocManager">IIocManager object</param>
 /// <param name="func">A function that can use the resolved object</param>
 /// <returns></returns>
 public static TReturn ResolveUsing <TService, TReturn>(this IIocManager iocManager, Func <TService, TReturn> func)
 {
     using (IDisposableDependencyObjectWrapper <TService> wrapper = iocManager.ResolveAsDisposable <TService>())
     {
         return(func(wrapper.Object));
     }
 }
Beispiel #9
0
 /// <summary>
 ///     This method can be used to resolve and release an object automatically.
 ///     You can use the object in <see cref="doAction" />.
 /// </summary>
 /// <typeparam name="T">Type of the object to get</typeparam>
 /// <param name="iocManager">IIocManager object</param>
 /// <param name="doAction"></param>
 public static void ResolveUsing <T>(this IIocManager iocManager, Action <T> doAction)
 {
     using (IDisposableDependencyObjectWrapper <T> wrapper = iocManager.ResolveAsDisposable <T>())
     {
         doAction(wrapper.Object);
     }
 }
 private static void Test_Way_2(IIocManager iocManager)
 {
     using (var tester = iocManager.ResolveAsDisposable<Tester>())
     {
         tester.Object.Test();
     }
 }
 public virtual void Initialize()
 {
     foreach (var providerType in _winformToolbarConfiguration.Providers)
     {
         using (var provider = _iocManager.ResolveAsDisposable <ToolbarProvider>(providerType)) {
             provider.Object.SetToolbars(this);
         }
     }
 }
 /// <summary>
 /// 初始化
 /// </summary>
 internal void Initialize()
 {
     foreach (var providerType in _baseCodeTypeConfiguration.Providers)
     {
         using (var provider = _iocManager.ResolveAsDisposable <AbpStepBodyProvider>(providerType))
         {
             provider.Object.Build(this);
         }
     }
 }
 public virtual void Initialize()
 {
     foreach (var providerType in _winformMenuConfiguration.Providers)
     {
         using (var provider = _iocManager.ResolveAsDisposable <MenuProvider>(providerType))
         {
             provider.Object.SetMenus(this);
         }
     }
     Menus.AddAllMenus();
 }
Beispiel #14
0
        public void Run <T>(IIocManager iocManager)
            where T : IMigratorExecuter
        {
            if (NeedMigration)
            {
                using (var migrateExecuter = iocManager.ResolveAsDisposable <T>())

                {
                    migrateExecuter.Object.Run();
                }
            }
        }
Beispiel #15
0
        public void Authorize(IInvocation invocation)
        {
            if (!invocation.MethodInvocationTarget.IsDefined(typeof(AbpAuthorizeAttribute), true))
            {
                return;
            }

            var authorizeAttributes = invocation.MethodInvocationTarget.GetCustomAttributes(typeof(AbpAuthorizeAttribute), true);

            using (var authorizationAttributeHelper = _iocManager.ResolveAsDisposable <AuthorizeAttributeHelper>())
            {
                authorizationAttributeHelper.Object.Authorize(authorizeAttributes.Cast <IAbpAuthorizeAttribute>());
            }
        }
        public async Task <bool> EnableFeatureForTenantAsync(EnableFeatureDto input)
        {
            var tenant = await _tenantManager.GetByIdAsync(input.TenantId);

            if (tenant == null)
            {
                return(false);
            }

            var allFeatures = _featureManager.GetAll();

            foreach (var feature in allFeatures)
            {
                if (input.FeatureNames.Contains(feature.Name))
                {
                    await _tenantManager.SetFeatureValueAsync(tenant.Id, feature.Name, "true");
                }
                else
                {
                    await _tenantManager.SetFeatureValueAsync(tenant.Id, feature.Name, "false");
                }
            }

            await CurrentUnitOfWork.SaveChangesAsync();

            using (CurrentUnitOfWork.SetTenantId(tenant.Id))
            {
                // Grant all permissions to admin role
                var adminRole = _roleManager.Roles.Single(r => r.Name == StaticRoleNames.Tenants.Admin);

                using (var featureDependencyContext = _iocManager.ResolveAsDisposable <FeatureDependencyContext>())
                {
                    var featureDependencyContextObject = featureDependencyContext.Object;
                    featureDependencyContextObject.TenantId = tenant.Id;

                    var permissions = PermissionManager.GetAllPermissions(adminRole.GetMultiTenancySide())
                                      .Where(permission =>
                                             permission.FeatureDependency == null ||
                                             permission.FeatureDependency.IsSatisfied(featureDependencyContextObject)
                                             ).ToList();

                    await _roleManager.SetGrantedPermissionsAsync(adminRole, permissions);
                }
            }

            return(true);
        }
        public static async void InitializeApp(IIocManager iocManger)
        {
            var logger = iocManger.Resolve <ILogger <InitializationManager> >();

            // EF data Migrations.
            using (var uowManager = iocManger.ResolveAsDisposable <IUnitOfWorkManager>())
            {
                using (var uow = uowManager.Object.Begin(TransactionScopeOption.Suppress))
                {
                    var dbContext = uowManager.Object.Current.GetDbContext <ResponsibleSystemDbContext>(MultiTenancySides.Host);
                    await new DataMigrationService(dbContext).Run();
                    logger.LogDebug("EfDataMigrationService - completed");

                    uow.Complete();
                }
            }
        }
Beispiel #18
0
 private IDisposableDependencyObjectWrapper <SettingProvider> CreateProvider(Type providerType)
 {
     return(iocManager.ResolveAsDisposable <SettingProvider>(providerType));
 }
Beispiel #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="providerType"></param>
 /// <returns></returns>
 private IDisposableDependencyObjectWrapper <FeatureProvider> CreateProvider(Type providerType)
 {
     _iocManager.RegisterIfNot(providerType); //TODO: Needed?
     return(_iocManager.ResolveAsDisposable <FeatureProvider>(providerType));
 }
 private IDisposableDependencyObjectWrapper <SettingProvider> CreateProvider(Type providerType)
 {
     _iocManager.RegisterIfNot(providerType, DependencyLifeStyle.Transient); //TODO: Needed?
     return(_iocManager.ResolveAsDisposable <SettingProvider>(providerType));
 }
        /// <summary>
        /// 支付回调配置
        /// </summary>
        /// <param name="logAction"></param>
        /// <param name="iocManager"></param>
        private static void PayNotifyConfig(Action <string, string> logAction, IIocManager iocManager)
        {
            void PayAction(string key, string outTradeNo, string transactionId, int totalFee, JObject data)
            {
                using (var paymentCallbackManagerObj = iocManager.ResolveAsDisposable <PaymentCallbackManager>())
                {
                    var paymentCallbackManager = paymentCallbackManagerObj?.Object;
                    if (paymentCallbackManager == null)
                    {
                        throw new ApplicationException("支付回调管理器异常,无法执行回调!");
                    }
                    AsyncHelper.RunSync(async() => await paymentCallbackManager.ExecuteCallback(key, outTradeNo, transactionId, totalFee, data));
                }
            }

            //支付回调设置
            PayNotifyBuilder
            .Create()
            //设置日志记录
            .WithLoggerAction(logAction).WithPayNotifyFunc(input =>
            {
                switch (input.Provider)
                {
                case "wechat":
                    {
                        using (var obj = iocManager.ResolveAsDisposable <WeChatPayApi>())
                        {
                            var api = obj.Object;
                            return(api.PayNotifyHandler(input.Request.Body, (output, error) =>
                            {
                                //获取微信支付自定义数据
                                if (string.IsNullOrWhiteSpace(output.Attach))
                                {
                                    throw new UserFriendlyException("自定义参数不允许为空!");
                                }

                                var data = JsonConvert.DeserializeObject <JObject>(output.Attach);
                                var key = data["key"]?.ToString();
                                var outTradeNo = output.OutTradeNo;
                                var totalFee = int.Parse(output.TotalFee);
                                PayAction(key, outTradeNo, output.TransactionId, totalFee, data);
                            }));
                        }
                    }

                case "alipay":
                    {
                        using (var obj = iocManager.ResolveAsDisposable <IAlipayAppService>())
                        {
                            var api = obj.Object;

                            var dictionary = input.Request.Form.ToDictionary(p => p.Key, p2 => p2.Value.FirstOrDefault()?.ToString());
                            //签名校验
                            if (!api.PayNotifyHandler(dictionary))
                            {
                                throw new UserFriendlyException("支付宝支付签名错误!");
                            }
                            var outTradeNo     = input.Request.Form["out_trade_no"];
                            var tradeNo        = input.Request.Form["trade_no"];
                            var charset        = input.Request.Form["charset"];
                            var totalFee       = (int)(decimal.Parse(input.Request.Form["total_fee"]) * 100);
                            var businessParams = input.Request.Form["business_params"];
                            if (string.IsNullOrWhiteSpace(businessParams))
                            {
                                throw new UserFriendlyException("自定义参数不允许为空!");
                            }
                            var data = JsonConvert.DeserializeObject <JObject>(businessParams);
                            var key  = data["key"]?.ToString();
                            PayAction(key, outTradeNo, tradeNo, totalFee, data);
                            return(Task.FromResult("success"));
                        }
                    }

                //国际支付宝
                case "global.alipay":
                    {
                        using (var obj = iocManager.ResolveAsDisposable <IGlobalAlipayAppService>())
                        {
                            var api = obj.Object;

                            var dictionary = input.Request.Form.ToDictionary(p => p.Key, p2 => p2.Value.FirstOrDefault()?.ToString());
                            //签名校验
                            if (!api.PayNotifyHandler(dictionary))
                            {
                                throw new UserFriendlyException("支付宝支付签名错误!");
                            }
                            var outTradeNo = input.Request.Form["out_trade_no"];
                            var tradeNo    = input.Request.Form["trade_no"];
                            var charset    = input.Request.Form["charset"];
                            var totalFee   = (int)(Convert.ToDecimal(input.Request.Form["total_fee"]) * 100);
                            //交易状态
                            string tradeStatus = input.Request.Form["trade_status"];
                            using (var transactionLogHelperObj = iocManager.ResolveAsDisposable <TransactionLogHelper>())
                            {
                                var customData = transactionLogHelperObj.Object.GetCustomDataByOutTradeNo(outTradeNo);
                                if (string.IsNullOrWhiteSpace(customData))
                                {
                                    throw new UserFriendlyException("自定义参数不允许为空!");
                                }
                                var data = JsonConvert.DeserializeObject <JObject>(customData);
                                var key  = data["key"]?.ToString();
                                PayAction(key, outTradeNo, tradeNo, totalFee, data);
                            }
                            return(Task.FromResult("success"));
                        }
                    }

                default:
                    break;
                }

                return(null);
            }).Build();
        }