private T GetChannel <T>(string name) where T : class { T obj; var clientFactory = ClientFactory.Current; if (ClientConfigHelper.IsEndPointExist(name)) { obj = clientFactory.CreateClient <T>(name); } else { var config = ClientConfigHelper.GetConfig <T>(); var address = config.GetAddress <T>(); if (string.IsNullOrWhiteSpace(address)) { var msg = string.Format("没有找到EndPoint '{0}'对应的配置," + "请确认EndPoint是否已经正确配置.", typeof(T).FullName); throw new ArgumentNullException(msg); } var binding = DefaultEndpointPolicy.EndpointPolicy.DefaultBinding;; obj = clientFactory.CreateClient <T>(binding, new EndpointAddress(address)); } return(obj); }
private static void CreateCacheToken(string user, string pass, DateTime expiresOn, string token) { var key = new ClientConfigHelper() { User = user, Password = pass }; var value = new ClientConfigHelperValues() { ExpiresOn = expiresOn, Token = token }; ClientConfigHelpers.TryAdd(key, value); }
private static ClientConfigHelperValues GetExistsToken(string user, string pass) { ClientConfigHelperValues valuesToReturn; var clientConfigHelper = new ClientConfigHelper() { User = user, Password = pass }; ClientConfigHelpers.TryGetValue(clientConfigHelper, out valuesToReturn); if (null != valuesToReturn) { if (!isValidToken(valuesToReturn)) { valuesToReturn = null; } } return(valuesToReturn); }
private async ETVoid StartAsync() { try { SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance); DontDestroyOnLoad(gameObject); ClientConfigHelper.SetConfigHelper(); Game.EventSystem.Add(DLLType.Core, typeof(Core).Assembly); Game.EventSystem.Add(DLLType.Model, typeof(Model).Assembly); Game.Scene.AddComponent <TimerComponent>(); Game.Scene.AddComponent <GlobalConfigComponent>(); Game.Scene.AddComponent <NetOuterComponent>(); Game.Scene.AddComponent <ResourcesComponent>(); // 实体管理组件 Game.Scene.AddComponent <UnitComponent>(); Game.Scene.AddComponent <UIComponent>(); // 下载ab包 await BundleHelper.DownloadBundle(); // 加载配置 Game.Scene.GetComponent <ResourcesComponent>().LoadBundle("config.unity3d"); Game.Scene.AddComponent <ConfigComponent>(); Game.Scene.GetComponent <ResourcesComponent>().UnloadBundle("config.unity3d"); Game.Scene.AddComponent <OpcodeTypeComponent>(); Game.Scene.AddComponent <MessageDispatcherComponent>(); UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent <ConfigComponent>().Get(typeof(UnitConfig), 1001); Log.Debug($"config {JsonHelper.ToJson(unitConfig)}"); } catch (Exception e) { Log.Error(e); } }
public static IServiceCollection AddOpenIdAuthority(this IServiceCollection services, IConfiguration configuration) { if (services == null) { throw new ArgumentNullException(nameof(services)); } var idProviderConfig = new IdProviderConfig(); configuration.Bind("IdProvider", idProviderConfig); services.AddSingleton(idProviderConfig); var hostingConfig = new HostingConfig(); configuration.Bind("Hosting", hostingConfig); services.AddSingleton(hostingConfig); var clientConfigs = configuration.GetSection("Apps").Get <List <ClientAppConfig> >() ?? new List <ClientAppConfig>(); var clients = ClientConfigHelper.GetClientsFromConfig(clientConfigs); var apps = ClientConfigHelper.GetAppsFromClients(clients); var appStore = new InMemoryAppStore(apps); services.AddSingleton <IAppStore>(appStore); var idScopeConfig = configuration.GetSection("IdScopes").Get <List <IdScopeConfig> >() ?? new List <IdScopeConfig>(); var idScopes = idScopeConfig.Select(x => new IdentityResource(x.Name, x.DisplayName ?? x.Name, x.ClaimTypes) { Required = x.Required }).ToList(); idScopes.AddRange(new List <IdentityResource>() { new IdentityResources.OpenId(), new IdentityResources.Profile(), new IdentityResources.Email(), new IdentityResources.Phone(), new IdentityResources.Address(), }); var connection = configuration.GetConnectionString("OpenIdAuthority"); services.AddDbContext <OpenIdAuthorityDbContext>(options => options.UseSqlServer(connection)); services.AddTransient <IOneTimeCodeStore, DbOneTimeCodeStore>(); services.AddTransient <IOneTimeCodeService, OneTimeCodeService>(); services.AddTransient <IUserStore, DbUserStore>(); services.AddTransient <IMessageService, MessageService>(); services.AddIdentityServer(options => { options.UserInteraction.LoginUrl = "/signin"; options.UserInteraction.LogoutUrl = "/signout"; options.UserInteraction.LogoutIdParameter = "id"; options.UserInteraction.ErrorUrl = "/error"; options.Authentication.CookieLifetime = TimeSpan.FromMinutes(idProviderConfig.DefaultSessionLengthMinutes); }) .AddDeveloperSigningCredential() //todo: replace .AddInMemoryClients(clients) .AddProfileService <ProfileService>() .AddInMemoryIdentityResources(idScopes); var smtpConfig = new SmtpConfig(); configuration.Bind("Mail:Smtp", smtpConfig); services.AddSingleton(smtpConfig); services.AddTransient <IEmailService, SmtpEmailService>(); var emailTemplates = ProcessEmailTemplates.GetTemplatesFromMailConfig(configuration.GetSection("Mail")); services.AddSingleton(emailTemplates); services.AddTransient <IEmailTemplateService, EmailTemplateService>(); services.AddSingleton <IPasswordHashService>(new AspNetIdentityPasswordHashService(10000)); services.AddTransient <IPasswordHashStore, DbPasswordHashStore>(); services.AddTransient <IPasswordService, DefaultPasswordService>(); services.AddTransient <AuthenticateOrchestrator>(); services.AddTransient <UserOrchestrator>(); services.AddEmbeddedViews(); services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>(); // IUrlHelper services.AddSingleton <IActionContextAccessor, ActionContextAccessor>(); services.AddScoped <IUrlHelper>(x => { var actionContext = x.GetRequiredService <IActionContextAccessor>().ActionContext; var factory = x.GetRequiredService <IUrlHelperFactory>(); return(factory.GetUrlHelper(actionContext)); }); var allowedOrigins = clients.SelectMany(x => x.AllowedCorsOrigins).Distinct().ToArray(); if (allowedOrigins.Length > 0) { services.AddCors(options => { options.AddPolicy("CorsPolicy", builder => builder .WithOrigins(allowedOrigins) .AllowAnyMethod() .AllowAnyHeader() .AllowCredentials()); }); } services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddSingleton <ITempDataProvider, CookieTempDataProvider>(); return(services); }