/// <summary>
 /// Initializes a new instance of the <see cref="NugetPackagesFactory" /> class.
 /// </summary>
 /// <param name="resolverService">The resolver service.</param>
 /// <param name="registerService">The register service.</param>
 public NugetPackagesFactory(
     IResolverService resolverService,
     IRegisterService registerService)
 {
     this.resolverService = resolverService;
     this.registerService = registerService;
 }
예제 #2
0
 public RegisterLogic(
     ISecurityChallengeProvider securityChallengeProvider,
     IRegisterService registerService,
     IDateTimeAdapter dateTimeAdapter)
 {
     this.securityChallengeProvider = securityChallengeProvider;
     this.registerService = registerService;
     this.dateTimeAdapter = dateTimeAdapter;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectFactory" /> class.
        /// </summary>
        /// <param name="resolverService">The resolver service.</param>
        /// <param name="registerService">The register service.</param>
        public ProjectFactory(
            IResolverService resolverService,
            IRegisterService registerService)
        {
            TraceService.WriteLine("ProjectFactory::Constructor");

            this.resolverService = resolverService;
            this.registerService = registerService;
        }
예제 #4
0
        public RegisterContent()
        {
            InitializeComponent();

            txtLicenseKey.Width = this.Width - 50;

            _licenseKeyService = ObjectLocator.GetInstance<ILicenseKeyService>();
            _registerService = ObjectLocator.GetInstance<IRegisterService>();
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="EffectFactory" /> class.
 /// </summary>
 /// <param name="resolverService">The resolver service.</param>
 /// <param name="registerService">The register service.</param>
 /// <param name="settingsService">The settings service.</param>
 /// <param name="visualStudioService">The visual studio service.</param>
 public EffectFactory(
     IResolverService resolverService,
     IRegisterService registerService,
     ISettingsService settingsService,
     IVisualStudioService visualStudioService)
     : base(settingsService)
 {
     this.resolverService = resolverService;
     this.registerService = registerService;
     this.visualStudioService = visualStudioService;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="ViewModelAndViewsFactory" /> class.
 /// </summary>
 /// <param name="visualStudioService">The visual studio service.</param>
 /// <param name="settingsService">The settings service.</param>
 /// <param name="resolverService">The resolver service.</param>
 /// <param name="registerService">The register service.</param>
 public ViewModelAndViewsFactory(
     IVisualStudioService visualStudioService,
     ISettingsService settingsService,
     IResolverService resolverService,
     IRegisterService registerService)
 {
     this.visualStudioService = visualStudioService;
     this.settingsService = settingsService;
     this.resolverService = resolverService;
     this.registerService = registerService;
 }
예제 #7
0
 public TeamController(IRegisterService registerService,
     ITeamService teamService,
     ITaskService taskService,
     IUserService userService,
     IAuthroizationService authService)
 {
     _registerService = registerService;
     _teamService = teamService;
     _taskService = taskService;
     _userService = userService;
     _authService = authService;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomRendererFactory" /> class.
        /// </summary>
        /// <param name="visualStudioService">The visual studio service.</param>
        /// <param name="settingsService">The settings service.</param>
        /// <param name="resolverService">The resolver service.</param>
        /// <param name="registerService">The register service.</param>
        public CustomRendererFactory(
            IVisualStudioService visualStudioService,
            ISettingsService settingsService,
            IResolverService resolverService,
            IRegisterService registerService)
            : base(settingsService)
        {
            TraceService.WriteLine("CustomRendererFactory::Constructor");

            this.visualStudioService = visualStudioService;
            this.resolverService = resolverService;
            this.registerService = registerService;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ProjectFactory" /> class.
        /// </summary>
        /// <param name="resolverService">The resolver service.</param>
        /// <param name="registerService">The register service.</param>
        /// <param name="cachingService">The caching service.</param>
        /// <param name="settingsService">The settings service.</param>
        public ProjectFactory(
            IResolverService resolverService,
            IRegisterService registerService,
            ICachingService cachingService,
            ISettingsService settingsService)
        {
            TraceService.WriteLine("ProjectFactory::Constructor");

            this.resolverService = resolverService;
            this.registerService = registerService;
            this.cachingService = cachingService;
            this.settingsService = settingsService;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ViewModelAndViewsFactory" /> class.
 /// </summary>
 /// <param name="visualStudioService">The visual studio service.</param>
 /// <param name="settingsService">The settings service.</param>
 /// <param name="resolverService">The resolver service.</param>
 /// <param name="registerService">The register service.</param>
 /// <param name="testingFrameworkFactory">The testing framework factory.</param>
 /// <param name="mvvmCrossViewFactory">The MVVM cross view factory.</param>
 public ViewModelAndViewsFactory(
     IVisualStudioService visualStudioService,
     ISettingsService settingsService,
     IResolverService resolverService,
     IRegisterService registerService,
     ITestingFrameworkFactory testingFrameworkFactory,
     IMvvmCrossViewFactory mvvmCrossViewFactory)
     : base(settingsService, 
     visualStudioService)
 {
     this.resolverService = resolverService;
     this.registerService = registerService;
     this.testingFrameworkFactory = testingFrameworkFactory;
     this.mvvmCrossViewFactory = mvvmCrossViewFactory;
 }
예제 #11
0
        /// <summary>
        /// Override constructor to instantiate the Licensing Manager and
        /// point it to an object that it's the running executable.
        /// </summary>
        /// <remarks>
        /// This constructor is useful when running an application and calling
        /// Scutex via a CCW (COM Callable Wrapper) and the executing assembly
        /// (i.e. Access) does not contain the security attribute.
        /// </remarks>
        /// <param name="instance">
        /// Reference to an object were the required attributes can be located
        /// </param>
        public LicensingManager(object instance)
        {
            this.instance = instance;

            Bootstrapper.Configure();

            InterfaceInteraction = new TrialInterfaceInteraction();

            hashingProvider = ObjectLocator.GetInstance<IHashingProvider>();
            encodingService = ObjectLocator.GetInstance<IEncodingService>();
            licenseManagerService = ObjectLocator.GetInstance<ILicenseManagerService>();
            _clientLicenseService = ObjectLocator.GetInstance<IClientLicenseService>();
            _comBypassProvider = ObjectLocator.GetInstance<IComBypassProvider>();
            _registerService = ObjectLocator.GetInstance<IRegisterService>();

            SetCriticalVerificationData();
            VerifyLicensingAssembly();
        }
예제 #12
0
        /// <summary>
        /// 开始 Senparc.Weixin SDK 初始化参数流程
        /// </summary>
        /// <param name="registerService"></param>
        /// <param name="senparcWeixinSetting"></param>
        /// <param name="extensionCacheStrategiesFunc"><para>需要注册的扩展缓存策略</para>
        /// <para>(LocalContainerCacheStrategy、RedisContainerCacheStrategy、MemcacheContainerCacheStrategy已经自动注册),</para>
        /// <para>如果设置为 null(注意:不适委托返回 null,是整个委托参数为 null),则自动使用反射扫描所有可能存在的扩展缓存策略</para></param>
        /// <returns></returns>
        public static IRegisterService UseSenparcWeixin(this IRegisterService registerService, SenparcWeixinSetting senparcWeixinSetting, Func <IList <IDomainExtensionCacheStrategy> > extensionCacheStrategiesFunc = null)
        {
            //Senparc.Weixin SDK 配置
            //Senparc.Weixin.Config.IsDebug = isDebug;
            Senparc.Weixin.Config.DefaultSenparcWeixinSetting = senparcWeixinSetting;

            // 微信的 本地 缓存
            var cache = LocalContainerCacheStrategy.Instance;//只要引用就可以被激活

            if (extensionCacheStrategiesFunc != null)
            {
                var containerCacheStrategies = extensionCacheStrategiesFunc();
                if (containerCacheStrategies != null)
                {
                    foreach (var cacheStrategy in containerCacheStrategies)
                    {
                        var exCache = cacheStrategy;//确保能运行到就行,会自动注册
                    }
                }
            }
            else
            {
                var officialTypes = new List <Type>()
                {
                    typeof(LocalContainerCacheStrategy)
                };

                //自动注册 Redis 和 Memcached
                //Redis
                var redisConfiguration = senparcWeixinSetting.Cache_Redis_Configuration;
                if ((!string.IsNullOrEmpty(redisConfiguration) && redisConfiguration != "Redis配置"))
                {
                    try
                    {
                        var redisInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Redis", "Senparc.Weixin.Cache.Redis", "RedisContainerCacheStrategy", "Instance");
                        officialTypes.Add(redisInstance.GetType());
                    }
                    catch (Exception ex)
                    {
                        WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex));
                    }
                }

                //Memcached
                var memcachedConfiguration = senparcWeixinSetting.Cache_Memcached_Configuration;
                if ((!string.IsNullOrEmpty(memcachedConfiguration) && memcachedConfiguration != "Memcached配置"))
                {
                    try
                    {
                        var memcachedInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Memcached", "Senparc.Weixin.Cache.Memcached", "MemcachedContainerCacheStrategy", "Instance");
                        officialTypes.Add(memcachedInstance.GetType());
                    }
                    catch (Exception ex)
                    {
                        WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex));
                    }
                }

                //查找所有扩产缓存
                var types = AppDomain.CurrentDomain.GetAssemblies()
                            .SelectMany(a => a.GetTypes()
                                        .Where(t => !t.IsAbstract && !officialTypes.Contains(t) && t.GetInterfaces().Contains(typeof(IDomainExtensionCacheStrategy))))
                            .ToArray();

                foreach (var type in types)
                {
                    try
                    {
                        var exCache = ReflectionHelper.GetStaticMember(type, "Instance");
                    }
                    catch (Exception ex)
                    {
                        WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex));
                    }
                }
            }

            return(registerService);
        }
예제 #13
0
 /// <summary>
 /// 注册公众号(或小程序)信息
 /// </summary>
 /// <param name="registerService">RegisterService</param>
 /// <param name="appId">微信公众号后台的【开发】>【基本配置】中的“AppID(应用ID)”</param>
 /// <param name="appSecret">微信公众号后台的【开发】>【基本配置】中的“AppSecret(应用密钥)”</param>
 /// <param name="name">标记AccessToken名称(如微信公众号名称),帮助管理员识别</param>
 /// <returns></returns>
 public static IRegisterService RegisterMpAccount(this IRegisterService registerService, string appId, string appSecret, string name)
 {
     AccessTokenContainer.Register(appId, appSecret, name);
     return(registerService);
 }
예제 #14
0
 /// <summary>
 /// 设置所有使用了 ApiHandlerWapper 的接口,可以自动进入重试的 API 错误代码
 /// </summary>
 /// <param name="registerService"></param>
 /// <param name="invalidCredentialReturnCodes">可进入重试的 API 错误代码</param>
 /// <returns></returns>
 public static IRegisterService SetMP_InvalidCredentialValues(this IRegisterService registerService, IEnumerable <ReturnCode> invalidCredentialReturnCodes)
 {
     ApiHandlerWapper.InvalidCredentialValues = invalidCredentialReturnCodes.Select(z => (int)z);
     return(registerService);
 }
예제 #15
0
        /// <summary>
        /// 开始 Senparc.Weixin SDK 初始化参数流程
        /// </summary>
        /// <param name="registerService"></param>
        /// <param name="senparcWeixinSetting">微信全局设置参数,必填</param>
        /// <param name="senparcSetting">用于提供 SenparcSetting.Cache_Redis_Configuration 和 Cache_Memcached_Configuration 两个参数,如果不使用这两种分布式缓存可传入null</param>
        /// <returns></returns>
        public static IRegisterService UseSenparcWeixin(this IRegisterService registerService, SenparcWeixinSetting senparcWeixinSetting, SenparcSetting senparcSetting = null)
        {
            senparcWeixinSetting = senparcWeixinSetting ?? new SenparcWeixinSetting();
            senparcSetting       = senparcSetting ?? new SenparcSetting();

            //Senparc.Weixin SDK 配置
            Senparc.Weixin.Config.SenparcWeixinSetting = senparcWeixinSetting;

            /* 扩展缓存注册开始 */
            var cacheTypes = "";//所有注册的扩展缓存

            // 微信的 本地 缓存
            var cache = LocalContainerCacheStrategy.Instance;//只要引用就可以被激活

            cacheTypes += typeof(LocalContainerCacheStrategy);

            DateTime dt1 = DateTime.Now;

            //官方扩展缓存注册

            //var officialTypes = new List<Type>() { typeof(LocalContainerCacheStrategy) };//官方提供的扩展缓存策略

            //自动注册 Redis 和 Memcached
            //Redis
            var redisConfiguration = senparcSetting.Cache_Redis_Configuration;

            if ((!string.IsNullOrEmpty(redisConfiguration) && redisConfiguration != "Redis配置"))
            {
                try
                {
                    var redisInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Redis", "Senparc.Weixin.Cache.Redis", "RedisContainerCacheStrategy", "Instance");
                    if (redisInstance != null)
                    {
                        //officialTypes.Add(redisInstance.GetType());
                        cacheTypes += "\r\n" + redisInstance.GetType();
                    }
                }
                catch (Exception ex)
                {
                    WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex));
                }
            }

            //Memcached
            var memcachedConfiguration = senparcSetting.Cache_Memcached_Configuration;

            if ((!string.IsNullOrEmpty(memcachedConfiguration) && memcachedConfiguration != "Memcached配置"))
            {
                try
                {
                    var memcachedInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Memcached", "Senparc.Weixin.Cache.Memcached", "MemcachedContainerCacheStrategy", "Instance");
                    if (memcachedInstance != null)
                    {
                        //officialTypes.Add(memcachedInstance.GetType());
                        cacheTypes += "\r\n" + memcachedInstance.GetType();
                    }
                }
                catch (Exception ex)
                {
                    WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex));
                }
            }

            DateTime dt2        = DateTime.Now;
            var      exCacheLog = "微信扩展缓存注册总用时:{0}ms\r\n扩展缓存:{1}".FormatWith((dt2 - dt1).TotalMilliseconds, cacheTypes);

            WeixinTrace.SendCustomLog("微信扩展缓存注册完成", exCacheLog);

            /* 扩展缓存注册结束 */

            //ApiBind 自动扫描
            Senparc.NeuChar.Register.RegisterApiBind();

            return(registerService);
        }
예제 #16
0
 /// <summary>
 /// 设置为 ApiHandlerWapper 服务的 AccessTokenContainer_GetFirstOrDefaultAppIdFunc 委托,默认为返回 AccessTokenContainer 中的 GetFirstOrDefaultAppId() 方法
 /// </summary>
 /// <param name="registerService"></param>
 /// <param name="func">自定义返回 AccessTokenContainer 中的 GetFirstOrDefaultAppId() 方法</param>
 /// <returns></returns>
 public static IRegisterService SetMP_AccessTokenContainer_GetFirstOrDefaultAppIdFunc(this IRegisterService registerService, Func <string, Task <bool> > func)
 {
     ApiHandlerWapper.AccessTokenContainer_CheckRegisteredAsyncFunc = func;
     return(registerService);
 }
예제 #17
0
 public RegisterController(IRegisterService _registerService)
 {
     this.registerService = _registerService;
 }
예제 #18
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            //DPBMARK WebSocket
            RegisterWebSocket();//微信注册WebSocket模块(按需,必须执行在RouteConfig.RegisterRoutes()之前)
            //DPBMARK_END


            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            /*
             * CO2NET 全局注册开始
             * 建议按照以下顺序进行注册
             */

            /*
             * CO2NET 是从 Senparc.Weixin 分离的底层公共基础模块,经过了长达 6 年的迭代优化。
             * 关于 CO2NET 在所有项目中的通用设置可参考 CO2NET 的 Sample:
             * https://github.com/Senparc/Senparc.CO2NET/blob/master/Sample/Senparc.CO2NET.Sample.netcore/Startup.cs
             */


            //设置全局 Debug 状态
            var isGLobalDebug = true;
            //全局设置参数,将被储存到 Senparc.CO2NET.Config.SenparcSetting
            var senparcSetting = SenparcSetting.BuildFromWebConfig(isGLobalDebug);
            //也可以通过这种方法在程序任意位置设置全局 Debug 状态:
            //Senparc.CO2NET.Config.IsDebug = isGLobalDebug;


            //CO2NET 全局注册,必须!!
            IRegisterService register = RegisterService.Start(senparcSetting).UseSenparcGlobal();

            #region  全局缓存配置(按需)

            //当同一个分布式缓存同时服务于多个网站(应用程序池)时,可以使用命名空间将其隔离(非必须)
            register.ChangeDefaultCacheNamespace("DefaultCO2NETCache");

            #region 配置和使用 Redis          -- DPBMARK Redis

            //配置全局使用Redis缓存(按需,独立)
            var redisConfigurationStr = senparcSetting.Cache_Redis_Configuration;
            var useRedis = !string.IsNullOrEmpty(redisConfigurationStr) && redisConfigurationStr != "Redis配置";
            if (useRedis)//这里为了方便不同环境的开发者进行配置,做成了判断的方式,实际开发环境一般是确定的,这里的if条件可以忽略
            {
                /* 说明:
                 * 1、Redis 的连接字符串信息会从 Config.SenparcSetting.Cache_Redis_Configuration 自动获取并注册,如不需要修改,下方方法可以忽略
                 * /* 2、如需手动修改,可以通过下方 SetConfigurationOption 方法手动设置 Redis 链接信息(仅修改配置,不立即启用)
                 */
                Senparc.CO2NET.Cache.Redis.Register.SetConfigurationOption(redisConfigurationStr);

                //以下会立即将全局缓存设置为 Redis
                Senparc.CO2NET.Cache.Redis.Register.UseKeyValueRedisNow();//键值对缓存策略(推荐)
                //Senparc.CO2NET.Cache.Redis.Register.UseHashRedisNow();//HashSet储存格式的缓存策略

                //也可以通过以下方式自定义当前需要启用的缓存策略
                //CacheStrategyFactory.RegisterObjectCacheStrategy(() => RedisObjectCacheStrategy.Instance);//键值对
                //CacheStrategyFactory.RegisterObjectCacheStrategy(() => RedisHashSetObjectCacheStrategy.Instance);//HashSet
            }
            //如果这里不进行Redis缓存启用,则目前还是默认使用内存缓存

            #endregion                        // DPBMARK_END

            #region 配置和使用 Memcached      -- DPBMARK Memcached

            //配置Memcached缓存(按需,独立)
            var memcachedConfigurationStr = senparcSetting.Cache_Memcached_Configuration;
            var useMemcached = !string.IsNullOrEmpty(memcachedConfigurationStr) && memcachedConfigurationStr != "Memcached配置";

            if (useMemcached) //这里为了方便不同环境的开发者进行配置,做成了判断的方式,实际开发环境一般是确定的,这里的if条件可以忽略
            {
                /* 说明:
                 * 1、Memcached 的连接字符串信息会从 Config.SenparcSetting.Cache_Memcached_Configuration 自动获取并注册,如不需要修改,下方方法可以忽略
                 * /* 2、如需手动修改,可以通过下方 SetConfigurationOption 方法手动设置 Memcached 链接信息(仅修改配置,不立即启用)
                 */
                Senparc.CO2NET.Cache.Memcached.Register.SetConfigurationOption(memcachedConfigurationStr);

                //以下会立即将全局缓存设置为 Memcached
                Senparc.CO2NET.Cache.Memcached.Register.UseMemcachedNow();

                //也可以通过以下方式自定义当前需要启用的缓存策略
                CacheStrategyFactory.RegisterObjectCacheStrategy(() => MemcachedObjectCacheStrategy.Instance);
            }

            #endregion                        //  DPBMARK_END

            #endregion

            #region 注册日志(按需,建议)

            register.RegisterTraceLog(ConfigWeixinTraceLog);//配置TraceLog

            #endregion


            /* 微信配置开始
             * 建议按照以下顺序进行注册
             */

            //设置微信 Debug 状态
            var isWeixinDebug = true;
            //全局设置参数,将被储存到 Senparc.Weixin.Config.SenparcWeixinSetting
            var senparcWeixinSetting = SenparcWeixinSetting.BuildFromWebConfig(isWeixinDebug);
            //也可以通过这种方法在程序任意位置设置微信的 Debug 状态:
            //Senparc.Weixin.Config.IsDebug = isWeixinDebug;

            //微信全局注册,必须!!
            register.UseSenparcWeixin(senparcWeixinSetting, senparcSetting)


            #region 注册公众号或小程序(按需)

            //注册公众号(可注册多个)                                                -- DPBMARK MP
            .RegisterMpAccount(senparcWeixinSetting, "【盛派网络小助手】公众号")    // DPBMARK_END


            //注册多个公众号或小程序(可注册多个)                                        -- DPBMARK MiniProgram
            .RegisterWxOpenAccount(senparcWeixinSetting, "【盛派网络小助手】小程序")    // DPBMARK_END

            //除此以外,仍然可以在程序任意地方注册公众号或小程序:
            //AccessTokenContainer.Register(appId, appSecret, name);//命名空间:Senparc.Weixin.MP.Containers
            #endregion

            #region 注册企业号(按需)           -- DPBMARK Work

            //注册企业微信(可注册多个)
            .RegisterWorkAccount(senparcWeixinSetting, "【盛派网络】企业微信")

            //除此以外,仍然可以在程序任意地方注册企业微信:
            //AccessTokenContainer.Register(corpId, corpSecret, name);//命名空间:Senparc.Weixin.Work.Containers
            #endregion                          // DPBMARK_END

            #region 注册微信支付(按需)        -- DPBMARK TenPay

            //注册旧微信支付版本(V2)(可注册多个)
            .RegisterTenpayOld(senparcWeixinSetting, "【盛派网络小助手】公众号")    //这里的 name 和第一个 RegisterMpAccount() 中的一致,会被记录到同一个 SenparcWeixinSettingItem 对象中

            //注册最新微信支付版本(V3)(可注册多个)
            .RegisterTenpayV3(senparcWeixinSetting, "【盛派网络小助手】公众号") //记录到同一个 SenparcWeixinSettingItem 对象中

            #endregion                                              // DPBMARK_END

            #region 注册微信第三方平台(按需)  -- DPBMARK Open

            //注册第三方平台(可注册多个)
            .RegisterOpenComponent(senparcWeixinSetting,
                                   //getComponentVerifyTicketFunc
                                   async componentAppId =>
            {
                var dir = Path.Combine(ServerUtility.ContentRootMapPath("~/App_Data/OpenTicket"));
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                var file = Path.Combine(dir, string.Format("{0}.txt", componentAppId));
                using (var fs = new FileStream(file, FileMode.Open))
                {
                    using (var sr = new StreamReader(fs))
                    {
                        var ticket = await sr.ReadToEndAsync();
                        return(ticket);
                    }
                }
            },

                                   //getAuthorizerRefreshTokenFunc
                                   async(componentAppId, auhtorizerId) =>
            {
                var dir = Path.Combine(ServerUtility.ContentRootMapPath("~/App_Data/AuthorizerInfo/" + componentAppId));
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                var file = Path.Combine(dir, string.Format("{0}.bin", auhtorizerId));
                if (!File.Exists(file))
                {
                    return(null);
                }

                using (Stream fs = new FileStream(file, FileMode.Open))
                {
                    var binFormat = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    var result    = (RefreshAuthorizerTokenResult)binFormat.Deserialize(fs);
                    return(result.authorizer_refresh_token);
                }
            },

                                   //authorizerTokenRefreshedFunc
                                   async(componentAppId, auhtorizerId, refreshResult) =>
            {
                var dir = Path.Combine(ServerUtility.ContentRootMapPath("~/App_Data/AuthorizerInfo/" + componentAppId));
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                var file = Path.Combine(dir, string.Format("{0}.bin", auhtorizerId));
                using (Stream fs = new FileStream(file, FileMode.Create))
                {
                    //这里存了整个对象,实际上只存RefreshToken也可以,有了RefreshToken就能刷新到最新的AccessToken
                    var binFormat = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    binFormat.Serialize(fs, refreshResult);
                    fs.Flush();
                }
            }, "【盛派网络】开放平台")

            //除此以外,仍然可以在程序任意地方注册开放平台:
            //ComponentContainer.Register();//命名空间:Senparc.Weixin.Open.Containers
            #endregion                          // DPBMARK_END

            ;

            /* 微信配置结束 */
        }
예제 #19
0
 /// <summary>
 /// YoYo Senparc CO2NET 跟踪日志
 /// </summary>
 /// <param name="registerService"></param>
 /// <param name="action"></param>
 /// <returns></returns>
 public static IRegisterService UseYoYoSenparcCO2NETTraceLog(this IRegisterService registerService, Action action)
 {
     action();
     return(registerService);
 }
예제 #20
0
 public static IRegisterService RegisterWxOpenAccount(this IRegisterService registerService, string appId, string appSercet, string name = null)
 {
     throw new WeixinException("请统一使用请统一使用Senparc.Weixin.WxOpen.Register.RegisterWxOpenAccount()方法进行注册!");
 }
예제 #21
0
        void Application_Start(object sender, EventArgs e)
        {
            #region 微信注册

            /* CO2NET 全局注册开始
             * 建议按照以下顺序进行注册
             */

            //设置全局 Debug 状态
            var isGLobalDebug  = true;
            var senparcSetting = SenparcSetting.BuildFromWebConfig(isGLobalDebug);

            //CO2NET 全局注册,必须!!
            IRegisterService register = RegisterService.Start(senparcSetting)
                                        .UseSenparcGlobal(false, null);

            /* 微信配置开始
             * 建议按照以下顺序进行注册
             */

            //设置微信 Debug 状态
            var isWeixinDebug        = true;
            var senparcWeixinSetting = SenparcWeixinSetting.BuildFromWebConfig(isWeixinDebug);

            //微信全局注册,必须!!
            register.UseSenparcWeixin(senparcWeixinSetting, senparcSetting)
            .RegisterMpAccount(senparcWeixinSetting, "WXQuestion");
            // 注册微信AppId
            //AccessTokenContainer.RegisterAsync(WXinConfig.WeixinAppId, WXinConfig.WeixinAppSecret).Start();

            // 异步执行
            //new Thread(x => {
            //}).Start();
            #endregion

            //初始化Aoc容器
            EngineContext.Initialize(false);
            // 数据库不用初始化  CodeFirst 容易报错
            Database.SetInitializer <WeiObjectContext>(null);

            //RegisterRoutes(RouteTable.Routes);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            GlobalConfiguration.Configure(WebApiConfig.Register);

            //fluent数据验证设置
            DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;        // 属性值可以为null
            ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(new WeiValidatorFactory()));
            // GlobalFilterCollection
            RegisterGlobalFilters(GlobalFilters.Filters);

            GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
            //GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.

            //Task t = new Task(() =>
            //{
            //    var tlogger = EngineContext.Current.Resolve<ILogger>();
            //    try
            //    {
            //        ViewServices.Users.UserViewService uservice = new ViewServices.Users.UserViewService();
            //        uservice.SaveUserList(WXinConfig.WeixinAppId);
            //    }
            //    catch (Exception ex)
            //    {
            //        //var logger2 = EngineContext.Current.Resolve<ILogger>();
            //        tlogger.Error(ex.Message, ex, null);
            //    }
            //});
            //t.Start();
            var logger = EngineContext.Current.Resolve <ILogger>();

            logger.Information("Application started", null, null);
        }
 public GeodatalovDatasetsController(RegisterDbContext dbContext, IGeodatalovDatasetService geodatalovDatasetService, IAccessControlService accessControllService, IRegisterService registerService, IRegisterItemService registerItemService, IDatasetDeliveryService datasetDeliveryService)
 {
     _db = dbContext;
     _geodatalovDatasetService = geodatalovDatasetService;
     _accessControlService     = accessControllService;
     _metadataService          = new MetadataService(_db);
     _registerService          = registerService;
     _registerItemService      = registerItemService;
     _datasetDeliveryService   = datasetDeliveryService;
 }
예제 #23
0
        public void TestRegisterMpAccount()
        {
            SenparcWeixinSetting senparcWeixinSetting;
            SenparcSetting       senparcSetting;
            IConfiguration       config;

            config = new ConfigurationBuilder()
                     .SetBasePath(Directory.GetCurrentDirectory())
                     .AddJsonFile("appsettings.json").Build();

            senparcSetting       = new SenparcSetting();
            senparcWeixinSetting = new SenparcWeixinSetting();

            config.GetSection("SenparcSetting").Bind(senparcSetting);
            config.GetSection("SenparcWeixinSetting").Bind(senparcWeixinSetting);

            var services = new ServiceCollection();

            services.AddSenparcGlobalServices(config);

            IRegisterService register = RegisterService.Start(senparcSetting).UseSenparcGlobal();

            #region Redis配置
            var redisConfigurationStr = senparcSetting.Cache_Redis_Configuration;
            Senparc.CO2NET.Cache.Redis.Register.SetConfigurationOption(redisConfigurationStr);
            Senparc.CO2NET.Cache.Redis.Register.UseKeyValueRedisNow();

            // 这里需要同时安装以下两个Nuget包,否则启动报错
            // Senparc.Weixin.Cache.Redis
            // Senparc.Weixin.Cache.CsRedis
            register.UseSenparcWeixinCacheRedis();

            #endregion


            var logFile = Path.Combine(Directory.GetCurrentDirectory(), "Debugger.log");
            var logs    = new List <string>();
            logs.Add("**********************    Start configuration the senparcSDK    **********************");
            logs.Add($"    ");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  Before the method: UseSenparcWeixin Invoke");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinAppId: {senparcWeixinSetting.WeixinAppId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinAppSecret: {senparcWeixinSetting.WeixinAppSecret}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  Token: {senparcWeixinSetting.Token}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  EncodingAESKey: {senparcWeixinSetting.EncodingAESKey}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinCorpId: {senparcWeixinSetting.WeixinCorpId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinCorpSecret: {senparcWeixinSetting.WeixinCorpSecret}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WxOpenAppId: {senparcWeixinSetting.WxOpenAppId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WxOpenAppSecret: {senparcWeixinSetting.WxOpenAppSecret}");

            register.UseSenparcWeixin(senparcWeixinSetting, senparcSetting);

            logs.Add($"    ");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  After the method: UseSenparcWeixin Invoke & Before the method: RegisterMpAccount Invoke");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinAppId: {senparcWeixinSetting.WeixinAppId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinAppSecret: {senparcWeixinSetting.WeixinAppSecret}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  Token: {senparcWeixinSetting.Token}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  EncodingAESKey: {senparcWeixinSetting.EncodingAESKey}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinCorpId: {senparcWeixinSetting.WeixinCorpId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinCorpSecret: {senparcWeixinSetting.WeixinCorpSecret}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WxOpenAppId: {senparcWeixinSetting.WxOpenAppId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WxOpenAppSecret: {senparcWeixinSetting.WxOpenAppSecret}");

            register.RegisterMpAccount(senparcWeixinSetting.MpSetting); // 公众号账号配置

            logs.Add($"    ");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  After the method: RegisterMpAccount Invoke & Before the method: RegisterWorkAccount");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinAppId: {senparcWeixinSetting.WeixinAppId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinAppSecret: {senparcWeixinSetting.WeixinAppSecret}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  Token: {senparcWeixinSetting.Token}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  EncodingAESKey: {senparcWeixinSetting.EncodingAESKey}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinCorpId: {senparcWeixinSetting.WeixinCorpId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinCorpSecret: {senparcWeixinSetting.WeixinCorpSecret}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WxOpenAppId: {senparcWeixinSetting.WxOpenAppId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WxOpenAppSecret: {senparcWeixinSetting.WxOpenAppSecret}");

            register.RegisterWorkAccount(senparcWeixinSetting.WorkSetting); // 企业微信账号配置

            logs.Add($"    ");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  After the method: RegisterWorkAccount Invoke & Before the method: RegisterWxOpenAccount");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinAppId: {senparcWeixinSetting.WeixinAppId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinAppSecret: {senparcWeixinSetting.WeixinAppSecret}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  Token: {senparcWeixinSetting.Token}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  EncodingAESKey: {senparcWeixinSetting.EncodingAESKey}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinCorpId: {senparcWeixinSetting.WeixinCorpId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinCorpSecret: {senparcWeixinSetting.WeixinCorpSecret}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WxOpenAppId: {senparcWeixinSetting.WxOpenAppId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WxOpenAppSecret: {senparcWeixinSetting.WxOpenAppSecret}");

            register.RegisterWxOpenAccount(senparcWeixinSetting.WxOpenSetting); // 小程序账号配置

            logs.Add($"    ");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  After the method: RegisterWxOpenAccount Invoke");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinAppId: {senparcWeixinSetting.WeixinAppId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinAppSecret: {senparcWeixinSetting.WeixinAppSecret}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  Token: {senparcWeixinSetting.Token}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  EncodingAESKey: {senparcWeixinSetting.EncodingAESKey}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinCorpId: {senparcWeixinSetting.WeixinCorpId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WeixinCorpSecret: {senparcWeixinSetting.WeixinCorpSecret}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WxOpenAppId: {senparcWeixinSetting.WxOpenAppId}");
            logs.Add($"{DateTime.Now:yyyy/MM/dd HH:mm:ss fffff}  WxOpenAppSecret: {senparcWeixinSetting.WxOpenAppSecret}");
            logs.Add($"    ");
            logs.Add("**********************    End configuration the senparcSDK    **********************");

            File.AppendAllLines(logFile, logs, Encoding.UTF8);
            Console.WriteLine(string.Join("\r\n", logs));
        }
예제 #24
0
 public RegisterModel(IRegisterService registerService) : base(registerService)
 {
     _registerService = registerService;
 }
예제 #25
0
 /// <summary>
 /// 根据 SenparcWeixinSetting 自动注册小程序信息
 /// </summary>
 /// <param name="registerService">RegisterService</param>
 /// <param name="weixinSettingForWxOpen">SenparcWeixinSetting</param>
 /// <param name="name">统一标识,如果为null,则使用 SenparcWeixinSetting.ItemKey </param>
 /// <returns></returns>
 public static IRegisterService UseYoYoSenparcWxOpenAccount(this IRegisterService registerService, ISenparcWeixinSettingForWxOpen weixinSettingForWxOpen, string name = null)
 {
     return(registerService.RegisterWxOpenAccount(weixinSettingForWxOpen, name));
 }
예제 #26
0
 public Account(IRegisterService registerService, ILoginService loginService, ILogoutService logoutService)
 {
     this._registerService = registerService;
     this._loginService = loginService;
     this._logoutService = logoutService;
 }
예제 #27
0
 public ProfileMockSI(IRegisterService registerService)
 {
     _registerService = registerService;
 }
예제 #28
0
파일: Account.cs 프로젝트: mustva/BlogSite
 public Account(IRegisterService registerService, ILoginService loginService, ILogoutService logoutService)
 {
     this._registerService = registerService;
     this._loginService    = loginService;
     this._logoutService   = logoutService;
 }
예제 #29
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider svp, IOptions <SenparcSetting> senparcSetting, IOptions <SenparcWeixinSetting> senparcWeixinSetting)
        {
            app.Use(async(context, next) =>
            {
                context.Response.Headers.Add("X-Frame-Options", "SAMEORIGIN");
                await next();
            });

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
                app.UseHsts();
            }


            //其他错误页面处理
            app.UseStatusCodePagesWithReExecute("/StatusCode/{0}");
            //启用Session
            app.UseSession();
            app.UseMyMVCDI();
            app.UseHttpsRedirection();
            app.UseStaticFiles();
            app.UseCookiePolicy();
            app.UseAuthentication();
            app.UseStaticHttpContext();
            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "areas",
                    pattern: "{area:exists}/{controller=Index}/{action=Index}/{id?}"
                    );

                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute(
                    name: "article",
                    pattern: "{title}/index.html",
                    defaults: new { controller = "Home", action = "Article" }
                    );
                endpoints.MapControllerRoute(
                    name: "article2",
                    pattern: "{title}/",
                    defaults: new { controller = "Home", action = "Article" }
                    );
            });

            //使用环境变量
            app.UseForwardedHeaders(new ForwardedHeadersOptions
            {
                ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
            });

            app.UseMiddlewareExtension(new ResultExceptionHandler());
            IRegisterService register = RegisterService.Start(env, senparcSetting.Value).UseSenparcGlobal();

            register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value);//微信全局注册,必须!
            //加入HttpContext
            //MyHttpContext.ServiceProvider = svp;
        }
예제 #30
0
파일: Startup.cs 프로젝트: ym1100/EasyCMS
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env,
                              IHostApplicationLifetime appLifetime, IOptions <Dictionary <string, string> > options,
                              IOptions <SenparcSetting> senparcSetting, IOptions <SenparcWeixinSetting> senparcWeixinSetting)
        {
            //if (env.IsDevelopment())
            //{
            //    app.UseDeveloperExceptionPage();
            // //  app.AddRazorRuntimeCompilation();
            //}
            //else
            //{
            //    app.UseExceptionHandler("/Home/Error");
            //    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            //    app.UseHsts();
            //}
            app.UseCookiePolicy();
            app.UseHttpsRedirection();

            //添加新的媒体文件类型,静态文件路由
            app.UseAtlassDefaultFiles(options);

            app.UseRouting();
            #region 自定义中间件
            app.UseMiddleware <AtlassHttpRequestMiddleware>();
            //app.UseMiddleware(typeof(AtlassExceptionMiddlerware));
            #endregion
            app.UseAuthorization();
            app.UseSession();

            app.UseEasyCachingResponseCaching();


            app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllerRoute(
                    name: "default",
                    pattern: "{controller=Home}/{action=Index}/{id?}");
                endpoints.MapControllerRoute(name: "areaRoute",
                                             pattern: "{area:exists}/{controller=Home}/{action=Index}/{id?}");
            });

            //启动hangfire服务和面板
            app.UseHangfireServer(new BackgroundJobServerOptions
            {
                Queues = new[] { "default" }
            });
            app.UseHangfireDashboard();
            //app.UseHangfireDashboard("/hangfire", new DashboardOptions()
            //{
            //    Authorization = new[] { new HangfireAuthorizeFilter() }
            //});


            //关于 UseSenparcGlobal() 的更多用法见 CO2NET Demo:
            //https://github.com/Senparc/Senparc.CO2NET/blob/master/Sample/Senparc.CO2NET.Sample.netcore/Startup.cs
            IRegisterService register = RegisterService.Start(senparcSetting.Value)
                                        .UseSenparcGlobal();

            register.ChangeDefaultCacheNamespace("DefaultCO2NETCache");
            register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value)

            #region 注册公众号(按需)
            //注册公众号(可注册多个)                                                -- DPBMARK MP
            .RegisterMpAccount(senparcWeixinSetting.Value, "doctor_platform_mp")     // DPBMARK_END //注册最新微信支付版本(V3)(可注册多个)
            .RegisterTenpayV3(senparcWeixinSetting.Value, "doctor_platform_tenpay"); //记录到同一个 SenparcWeixinSettingItem 对象中
            #endregion

            //应用程序启动后
            appLifetime.ApplicationStarted.Register(() => {
                try
                {
                    GlobalParamsDto.WebRoot = env.WebRootPath;
                    //SugarDbConn.DbConnectStr = this.Configuration.GetSection("DbConn:mysqlConn").Value;   //为数据库连接字符串赋值
                    GlobalParamsDto.Host = this.Configuration.GetSection("WebHost:Host").Value;

                    //初始化栏目相关的缓存
                    CmsCacheInit.Init();
                }
                catch (Exception e)
                {
                    LogNHelper.Exception(e);
                }
            });
        }
예제 #31
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IOptions <SenparcSetting> senparcSetting, IOptions <SenparcWeixinSetting> senparcWeixinSetting)
        {
            //引入EnableRequestRewind中间件
            app.UseEnableRequestRewind();
            app.UseSession();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });


            #region 提供网站根目录(当前 Sample 用到,和 SDK 无关)
            if (env.ContentRootPath != null)
            {
                Senparc.Weixin.MP.Sample.CommonService.Utilities.Server.AppDomainAppPath = env.ContentRootPath; // env.ContentRootPath;
            }
            Senparc.Weixin.MP.Sample.CommonService.Utilities.Server.WebRootPath = env.WebRootPath;              // env.ContentRootPath;
            #endregion

            // 启动 CO2NET 全局注册,必须!
            IRegisterService register = RegisterService.Start(env, senparcSetting.Value)
                                        //关于 UseSenparcGlobal() 的更多用法见 CO2NET Demo:https://github.com/Senparc/Senparc.CO2NET/blob/master/Sample/Senparc.CO2NET.Sample.netcore/Startup.cs
                                        .UseSenparcGlobal();

            //如果需要自动扫描自定义扩展缓存,可以这样使用:
            //register.UseSenparcGlobal(true);
            //如果需要指定自定义扩展缓存,可以这样用:
            //register.UseSenparcGlobal(false, GetExCacheStrategies);

            #region CO2NET 全局配置

            #region 全局缓存配置(按需)

            //当同一个分布式缓存同时服务于多个网站(应用程序池)时,可以使用命名空间将其隔离(非必须)
            register.ChangeDefaultCacheNamespace("DefaultCO2NETCache");

            #region 配置和使用 Redis

            //配置全局使用Redis缓存(按需,独立)
            var redisConfigurationStr = senparcSetting.Value.Cache_Redis_Configuration;
            var useRedis = !string.IsNullOrEmpty(redisConfigurationStr) && redisConfigurationStr != "Redis配置";
            if (useRedis)//这里为了方便不同环境的开发者进行配置,做成了判断的方式,实际开发环境一般是确定的,这里的if条件可以忽略
            {
                /* 说明:
                 * 1、Redis 的连接字符串信息会从 Config.SenparcSetting.Cache_Redis_Configuration 自动获取并注册,如不需要修改,下方方法可以忽略
                 * /* 2、如需手动修改,可以通过下方 SetConfigurationOption 方法手动设置 Redis 链接信息(仅修改配置,不立即启用)
                 */
                Senparc.CO2NET.Cache.Redis.Register.SetConfigurationOption(redisConfigurationStr);

                //以下会立即将全局缓存设置为 Redis
                Senparc.CO2NET.Cache.Redis.Register.UseKeyValueRedisNow();//键值对缓存策略(推荐)
                //Senparc.CO2NET.Cache.Redis.Register.UseHashRedisNow();//HashSet储存格式的缓存策略

                //也可以通过以下方式自定义当前需要启用的缓存策略
                //CacheStrategyFactory.RegisterObjectCacheStrategy(() => RedisObjectCacheStrategy.Instance);//键值对
                //CacheStrategyFactory.RegisterObjectCacheStrategy(() => RedisHashSetObjectCacheStrategy.Instance);//HashSet
            }
            //如果这里不进行Redis缓存启用,则目前还是默认使用内存缓存

            #endregion

            #region 配置和使用 Memcached

            //配置Memcached缓存(按需,独立)
            var memcachedConfigurationStr = senparcSetting.Value.Cache_Memcached_Configuration;
            var useMemcached = !string.IsNullOrEmpty(memcachedConfigurationStr) && memcachedConfigurationStr != "Memcached配置";

            if (useMemcached) //这里为了方便不同环境的开发者进行配置,做成了判断的方式,实际开发环境一般是确定的,这里的if条件可以忽略
            {
                app.UseEnyimMemcached();

                /* 说明:
                 * 1、Memcached 的连接字符串信息会从 Config.SenparcSetting.Cache_Memcached_Configuration 自动获取并注册,如不需要修改,下方方法可以忽略
                 * /* 2、如需手动修改,可以通过下方 SetConfigurationOption 方法手动设置 Memcached 链接信息(仅修改配置,不立即启用)
                 */
                Senparc.CO2NET.Cache.Memcached.Register.SetConfigurationOption(redisConfigurationStr);

                //以下会立即将全局缓存设置为 Memcached
                Senparc.CO2NET.Cache.Memcached.Register.UseMemcachedNow();

                //也可以通过以下方式自定义当前需要启用的缓存策略
                CacheStrategyFactory.RegisterObjectCacheStrategy(() => MemcachedObjectCacheStrategy.Instance);
            }

            #endregion

            #endregion

            #region 注册日志(按需,建议)

            register.RegisterTraceLog(ConfigTraceLog);//配置TraceLog

            #endregion

            #endregion

            #region 微信相关配置


            /* 微信配置开始
             *
             * 建议按照以下顺序进行注册,尤其须将缓存放在第一位!
             */

            //注册开始

            #region 微信缓存(按需,必须在 register.UseSenparcWeixin() 之前)

            // 微信的 Memcached 缓存,如果不使用则注释掉(开启前必须保证配置有效,否则会抛错)
            if (useMemcached)
            {
                app.UseSenparcWeixinCacheMemcached();
            }

            //微信的 Redis 缓存,如果不使用则注释掉(开启前必须保证配置有效,否则会抛错)
            if (useRedis)
            {
                app.UseSenparcWeixinCacheRedis();
            }

            #endregion


            //开始注册微信信息,必须!
            register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value)
            //注意:上一行没有 ; 下面可接着写 .RegisterXX()

            #region 注册公众号或小程序(按需)

            //注册公众号(可注册多个)
            .RegisterMpAccount(senparcWeixinSetting.Value, "【盛派网络小助手】公众号")
            //注册多个公众号或小程序(可注册多个)
            .RegisterWxOpenAccount(senparcWeixinSetting.Value, "【盛派网络小助手】小程序")

            //除此以外,仍然可以在程序任意地方注册公众号或小程序:
            //AccessTokenContainer.Register(appId, appSecret, name);//命名空间:Senparc.Weixin.MP.Containers
            #endregion

            #region 注册企业号(按需)

            //注册企业微信(可注册多个)
            .RegisterWorkAccount(senparcWeixinSetting.Value, "【盛派网络】企业微信")

            //除此以外,仍然可以在程序任意地方注册企业微信:
            //AccessTokenContainer.Register(corpId, corpSecret, name);//命名空间:Senparc.Weixin.Work.Containers
            #endregion

            #region 注册微信支付(按需)

            //注册旧微信支付版本(V2)(可注册多个)
            .RegisterTenpayOld(senparcWeixinSetting.Value, "【盛派网络小助手】公众号")    //这里的 name 和第一个 RegisterMpAccount() 中的一致,会被记录到同一个 SenparcWeixinSettingItem 对象中

            //注册最新微信支付版本(V3)(可注册多个)
            .RegisterTenpayV3(senparcWeixinSetting.Value, "【盛派网络小助手】公众号")    //记录到同一个 SenparcWeixinSettingItem 对象中

            #endregion

            #region 注册微信第三方平台(按需)

            //注册第三方平台(可注册多个)
            .RegisterOpenComponent(senparcWeixinSetting.Value,
                                   //getComponentVerifyTicketFunc
                                   componentAppId =>
            {
                var dir = Path.Combine(Server.GetMapPath("~/App_Data/OpenTicket"));
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                var file = Path.Combine(dir, string.Format("{0}.txt", componentAppId));
                using (var fs = new FileStream(file, FileMode.Open))
                {
                    using (var sr = new StreamReader(fs))
                    {
                        var ticket = sr.ReadToEnd();
                        return(ticket);
                    }
                }
            },

                                   //getAuthorizerRefreshTokenFunc
                                   (componentAppId, auhtorizerId) =>
            {
                var dir = Path.Combine(Server.GetMapPath("~/App_Data/AuthorizerInfo/" + componentAppId));
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                var file = Path.Combine(dir, string.Format("{0}.bin", auhtorizerId));
                if (!File.Exists(file))
                {
                    return(null);
                }

                using (Stream fs = new FileStream(file, FileMode.Open))
                {
                    var binFormat = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    var result    = (RefreshAuthorizerTokenResult)binFormat.Deserialize(fs);
                    return(result.authorizer_refresh_token);
                }
            },

                                   //authorizerTokenRefreshedFunc
                                   (componentAppId, auhtorizerId, refreshResult) =>
            {
                var dir = Path.Combine(Server.GetMapPath("~/App_Data/AuthorizerInfo/" + componentAppId));
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                var file = Path.Combine(dir, string.Format("{0}.bin", auhtorizerId));
                using (Stream fs = new FileStream(file, FileMode.Create))
                {
                    //这里存了整个对象,实际上只存RefreshToken也可以,有了RefreshToken就能刷新到最新的AccessToken
                    var binFormat = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
                    binFormat.Serialize(fs, refreshResult);
                    fs.Flush();
                }
            }, "【盛派网络】开放平台")

            //除此以外,仍然可以在程序任意地方注册开放平台:
            //ComponentContainer.Register();//命名空间:Senparc.Weixin.Open.Containers
            #endregion

            ;

            /* 微信配置结束 */

            #endregion
        }
예제 #32
0
 public RegisterController(IRegisterService service)
 {
     _service = service;
 }
예제 #33
0
        /// <summary>
        /// 开始 Senparc.Weixin SDK 初始化参数流程
        /// </summary>
        /// <param name="registerService"></param>
        /// <param name="senparcWeixinSetting">微信全局设置参数,必填</param>
        /// <param name="senparcSetting">用于提供 SenparcSetting.Cache_Redis_Configuration 和 Cache_Memcached_Configuration 两个参数,如果不使用这两种分布式缓存可传入null</param>
        /// <returns></returns>
        public static IRegisterService UseSenparcWeixin(this IRegisterService registerService, SenparcWeixinSetting senparcWeixinSetting, SenparcSetting senparcSetting = null)
        {
            senparcWeixinSetting = senparcWeixinSetting ?? new SenparcWeixinSetting();
            senparcSetting       = (senparcSetting ?? CO2NET.Config.SenparcSetting) ?? new SenparcSetting();

            //Senparc.Weixin SDK 配置
            Senparc.Weixin.Config.SenparcWeixinSetting = senparcWeixinSetting;

            /* 扩展缓存注册开始 */
            var cacheTypes = "";//所有注册的扩展缓存

            // 微信的 本地 缓存
            var cache = LocalContainerCacheStrategy.Instance;//只要引用就可以被激活

            cacheTypes += typeof(LocalContainerCacheStrategy);

            var dt1 = SystemTime.Now;

            //官方扩展缓存注册

            //var officialTypes = new List<Type>() { typeof(LocalContainerCacheStrategy) };//官方提供的扩展缓存策略

            //自动注册 Redis 和 Memcached
            //Redis
            var redisConfiguration = senparcSetting.Cache_Redis_Configuration;

            if (!string.IsNullOrEmpty(redisConfiguration) &&
                /*缓存配置默认值,不启用*/
                redisConfiguration != "Redis配置" &&
                redisConfiguration != "#{Cache_Redis_Configuration}#")
            {
                try
                {
                    {
                        //StackExchange.Redis
                        var redisInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Redis", "Senparc.Weixin.Cache.Redis", "RedisContainerCacheStrategy", "Instance");
                        if (redisInstance != null)
                        {
                            //officialTypes.Add(redisInstance.GetType());
                            cacheTypes += "\r\n" + redisInstance.GetType();
                        }
                    }
                    {
                        //CsRedis
                        var redisInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.CsRedis", "Senparc.Weixin.Cache.CsRedis", "RedisContainerCacheStrategy", "Instance");
                        if (redisInstance != null)
                        {
                            //officialTypes.Add(redisInstance.GetType());
                            cacheTypes += "\r\n" + redisInstance.GetType();
                        }
                    }
                }
                catch (Exception ex)
                {
                    WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex));
                }
            }

            //Memcached
            var memcachedConfiguration = senparcSetting.Cache_Memcached_Configuration;

            if (!string.IsNullOrEmpty(memcachedConfiguration) &&
                /*缓存配置默认值,不启用*/
                memcachedConfiguration != "Memcached配置" &&
                memcachedConfiguration != "#{Cache_Memcached_Configuration}#")
            {
                try
                {
                    var memcachedInstance = ReflectionHelper.GetStaticMember("Senparc.Weixin.Cache.Memcached", "Senparc.Weixin.Cache.Memcached", "MemcachedContainerCacheStrategy", "Instance");
                    if (memcachedInstance != null)
                    {
                        //officialTypes.Add(memcachedInstance.GetType());
                        cacheTypes += "\r\n" + memcachedInstance.GetType();
                    }
                }
                catch (Exception ex)
                {
                    WeixinTrace.WeixinExceptionLog(new Exceptions.WeixinException(ex.Message, ex));
                }
            }

            var exCacheLog = $"微信扩展缓存注册总用时:{SystemTime.DiffTotalMS(dt1, "f4")}ms\r\n扩展缓存:{cacheTypes}";

            WeixinTrace.SendCustomLog("微信扩展缓存注册完成", exCacheLog);

            /* 扩展缓存注册结束 */

            //注册 NeuChar
            Senparc.NeuChar.Register.AddNeuChar();

            return(registerService);
        }
 public RegisterController(IMapper mapper, IRegisterService service)
 {
     _mapper  = mapper;
     _service = service;
 }
예제 #35
0
 /// <summary>
 /// 注册微信支付TenpayV3
 /// </summary>
 /// <param name="registerService">RegisterService</param>
 /// <param name="tenPayV3Info">微信支付(新版本 V3)参数</param>
 /// <param name="name">公众号唯一标识名称</param>
 /// <returns></returns>
 public static IRegisterService RegisterTenpayRealV3(this IRegisterService registerService, Func <TenPayV3Info> tenPayV3Info, string name)
 {
     TenPayV3InfoCollection.Register(tenPayV3Info(), name);
     return(registerService);
 }
예제 #36
0
 /// <summary>
 /// 设置为 ApiHandlerWapper 服务的 AccessTokenContainer_GetAccessTokenResultFunc 委托,默认为返回 AccessTokenContainer 中的 GetAccessTokenResult() 方法
 /// </summary>
 /// <param name="registerService"></param>
 /// <param name="func">自定义返回 AccessTokenContainer 中的 AccessTokenResult GetAccessTokenResult(appId) 方法</param>
 /// <returns></returns>
 public static IRegisterService SetMP_AccessTokenContainer_GetAccessTokenResultFunc(this IRegisterService registerService, Func <string, bool, Task <IAccessTokenResult> > func)
 {
     ApiHandlerWapper.AccessTokenContainer_GetAccessTokenResultAsyncFunc = func;
     return(registerService);
 }
예제 #37
0
 public LogController(IRegisterService registerService, IUserService userService)
 {
     _registerService = registerService;
     _userService = userService;
 }
예제 #38
0
 /// <summary>
 /// 注册公众号(或小程序)的JSApi(RegisterMpAccount注册过程中已包含)
 /// </summary>
 /// <param name="registerService">RegisterService</param>
 /// <param name="appId">微信公众号后台的【开发】>【基本配置】中的“AppID(应用ID)”</param>
 /// <param name="appSecret">微信公众号后台的【开发】>【基本配置】中的“AppSecret(应用密钥)”</param>
 /// <param name="name">标记AccessToken名称(如微信公众号名称),帮助管理员识别</param>
 /// <returns></returns>
 public static IRegisterService RegisterMpJsApiTicket(this IRegisterService registerService, string appId, string appSecret, string name)
 {
     JsApiTicketContainer.Register(appId, appSecret, name);
     return(registerService);
 }
 public RegisterController(IRegisterService registerService)
 {
     _registerService = registerService;
 }
        /// <summary>
        /// Creates a new broadcaster class with the given IRegisterService
        /// (or Bonjour if null)
        /// </summary>
        /// <param name="registerService">The service that will perform the broadcast</param>
        /// <param name = "port">The port to advertise the service as being available on (i.e.
        /// the port that the listener is using)</param>
        public CouchbaseLiteServiceBroadcaster(IRegisterService registerService, ushort port)
        {
            if (registerService == null) {
                throw new ArgumentNullException("registerService");
            }

            if (registerService.Name == null) {
                registerService.Name = "CouchbaseLite_" + Environment.MachineName;   
            }

            if (registerService.RegType == null) {
                registerService.RegType = "_http._tcp";
            }

            _registerService = registerService;
            _registerService.Port = port;
        }
예제 #41
0
 public RegisterService()
 {
     register_service = (IRegisterService)Activator.CreateInstance(
         ProviderFactory.SelectedProvider.RegisterService);
 }
예제 #42
0
 public DatasetsController(RegisterDbContext dbContext, IRegisterItemService registerItemService, IRegisterService registerService, IAccessControlService accessControllService, IDatasetDeliveryService datasetDeliveryService, ITranslationService translationService, IDatasetService datasetService, IStatusReportService statusReportService)
 {
     db = dbContext;
     _registerItemService    = registerItemService;
     _registerService        = registerService;
     _accessControlService   = accessControllService;
     _datasetDeliveryService = datasetDeliveryService;
     _translationService     = translationService;
     _datasetService         = datasetService;
     _statusReportService    = statusReportService;
 }
 public RegisterServiceEventArgs(IRegisterService service, bool isRegistered, ServiceErrorCode error)
 {
     this.service = service;
     this.is_registered = isRegistered;
     this.error = error;
 }
예제 #44
0
 /// <summary>
 /// 使用运行时缓存
 /// </summary>
 /// <param name="service"></param>
 /// <returns></returns>
 public static IRegisterService UseRuntimeCache(this IRegisterService service)
 {
     CacheFactory.CacheType = CacheType.Runtime;
     return(service);
 }
예제 #45
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IOptions <SenparcSetting> senparcSetting, IOptions <SenparcWeixinSetting> senparcWeixinSetting)
        {
            app.UseAbp(); //Initializes ABP framework.
            app.UseSession();

            //app.UseSignalR(routes =>
            //{
            //    routes.MapHub<ChatHub>("/signalr-ChatHub");
            //});
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseDatabaseErrorPage();
            }
            else
            {
                app.UseExceptionHandler("/Error");
            }

            //自定义中间件
            app.UseThumbMiddleware();

            app.UseStaticFiles();

            app.UseEmbeddedFiles(); //Allows to expose embedded files to the web!

            app.UseAuthentication();

            app.UseJwtTokenMiddleware();

            ApplicationConfigurer.Configure(app);

            app.UseHangfireServer();
            app.UseHangfireDashboard("/masterhangfire", new DashboardOptions
            {
                Authorization = new[] { new AbpHangfireAuthorizationFilter() }
            });

            app.UseSwagger();
            // Enable middleware to serve swagger-ui assets (HTML, JS, CSS etc.)
            app.UseSwaggerUI(options =>
            {
                options.SwaggerEndpoint("/swagger/v1/swagger.json", "Master API V1");
            }); // URL: /swagger

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            // 启动 CO2NET 全局注册,必须!
            IRegisterService register = RegisterService.Start(env, senparcSetting.Value)
                                        //关于 UseSenparcGlobal() 的更多用法见 CO2NET Demo:https://github.com/Senparc/Senparc.CO2NET/blob/master/Sample/Senparc.CO2NET.Sample.netcore/Startup.cs
                                        .UseSenparcGlobal();

            #region 微信相关配置


            /* 微信配置开始
             *
             * 建议按照以下顺序进行注册,尤其须将缓存放在第一位!
             */

            //注册开始



            //开始注册微信信息,必须!
            register.UseSenparcWeixin(senparcWeixinSetting.Value, senparcSetting.Value)
            //注意:上一行没有 ; 下面可接着写 .RegisterXX()

            #region 注册公众号或小程序(按需)

            //注册公众号(可注册多个)
            .RegisterMpAccount(senparcWeixinSetting.Value, "公众号")

            //除此以外,仍然可以在程序任意地方注册公众号或小程序:
            //AccessTokenContainer.Register(appId, appSecret, name);//命名空间:Senparc.Weixin.MP.Containers
            #endregion


            ;
            /* 微信配置结束 */

            #endregion
        }
예제 #46
0
 /// <summary>
 /// 使用MemoryCache缓存
 /// </summary>
 /// <param name="service"></param>
 /// <returns></returns>
 public static IRegisterService UseMemoryCache(this IRegisterService service)
 {
     CacheFactory.CacheType = CacheType.MemoryCache;
     return(service);
 }
        /// <summary>
        /// Creates a new broadcaster class with the given IRegisterService
        /// (or Bonjour if null)
        /// </summary>
        /// <param name="registerService">The service that will perform the broadcast</param>
        /// <param name = "port">The port to advertise the service as being available on (i.e.
        /// the port that the listener is using)</param>
        public CouchbaseLiteServiceBroadcaster(IRegisterService registerService, ushort port)
        {
            if (registerService == null) {
                Log.To.Discovery.E(TAG, "registerService null in ctor, throwing...");
                throw new ArgumentNullException("registerService");
            }

            if (registerService.Name == null) {
                registerService.Name = "CouchbaseLite_" + Environment.MachineName;   
            }

            if (registerService.RegType == null) {
                registerService.RegType = "_http._tcp";
            }

            _registerService = registerService;
            _registerService.Port = port;
        }
예제 #48
0
 public RegisterService(IZeroconfProvider provider = null)
 {
     ProviderFactory.SelectedProvider = provider;
     register_service = (IRegisterService)Activator.CreateInstance(
         ProviderFactory.SelectedProvider.RegisterService);
 }
 public RegisterService()
 {
     register_service = (IRegisterService)Activator.CreateInstance(
         ProviderFactory.SelectedProvider.RegisterService);
 }
예제 #50
0
 /// <summary>
 /// 使用Redis缓存
 /// </summary>
 /// <param name="service"></param>
 /// <returns></returns>
 public static IRegisterService UseRedisCache(this IRegisterService service)
 {
     CacheFactory.CacheType = CacheType.Redis;
     return(service);
 }
예제 #51
0
 public override void OncePerTest()
 {
     this.mockUserStore = new Mock<IUserPasswordStore<User, long>>();
     this.sut = new UserService(this.mockUserStore.Object);
 }