private static async Task <IClusterClient> StartClientWithRetries(int initializeAttemptsBeforeFailing = 5) { int attempt = 0; IClusterClient client; while (true) { try { client = await ClientFactory.Build(() => { var builder = new ClientBuilder() .UseLocalhostClustering() .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IAccount).Assembly).WithReferences()) .ConfigureLogging(logging => logging.AddConsole()); return(builder); }); Console.WriteLine("Client successfully connect to silo host"); break; } catch (SiloUnavailableException) { attempt++; Console.WriteLine($"Attempt {attempt} of {initializeAttemptsBeforeFailing} failed to initialize the Orleans client."); if (attempt > initializeAttemptsBeforeFailing) { throw; } await Task.Delay(TimeSpan.FromSeconds(4)); } } return(client); }
private static async Task <IClusterClient> StartClientWithRetries(int initializeAttemptsBeforeFailing = 5) { int attempt = 0; IClusterClient client; while (true) { try { client = await ClientFactory.Build(() => { var builder = new ClientBuilder() .Configure <ClusterOptions>(options => { options.ClusterId = AppConfigHelper.ClusterId; options.ServiceId = AppConfigHelper.ServiceId; }) .UseAdoNetClustering(options => { options.ConnectionString = AppConfigHelper.ConnectionString; options.Invariant = AppConfigHelper.Invariant; }) .ConfigureServices((context, servicecollection) => { servicecollection.AddRay(); servicecollection.AddSingleton <ISerializer, ProtobufSerializer>(); //注册序列化组件 servicecollection.AddRabbitMQ(); //注册RabbitMq为默认消息队列 servicecollection.AddLogging(logging => logging.AddConsole()); servicecollection.AddMQHandler(); //注册所有handler servicecollection.PostConfigure <RabbitConfig>(c => { c.UserName = "******"; c.Password = "******"; c.Hosts = new[] { "127.0.0.1:5672" }; c.MaxPoolSize = 100; c.VirtualHost = "test-host"; }); }) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IAccount).Assembly).WithReferences()) .ConfigureLogging(logging => logging.AddConsole()); return(builder); }); Console.WriteLine("Client successfully connect to silo host"); break; } catch (SiloUnavailableException) { attempt++; Console.WriteLine($"Attempt {attempt} of {initializeAttemptsBeforeFailing} failed to initialize the Orleans client."); if (attempt > initializeAttemptsBeforeFailing) { throw; } await Task.Delay(TimeSpan.FromSeconds(4)); } } return(client); }
public async Task When_SectorIdentifierUri_Is_Not_A_Redirect_Uri_Then_Exception_Is_Thrown() { var parameter = new Client { RedirectionUrls = new[] { new Uri("https://google.com") }, SectorIdentifierUri = new Uri("https://localhost/identity") }; var sectorIdentifierUris = new List <string> { "https://localhost/sector_identifier" }; var json = sectorIdentifierUris.SerializeWithJavascript(); var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.Accepted) { Content = new StringContent(json) }; var handler = new FakeHttpMessageHandler(httpResponseMessage); var httpClientFake = new HttpClient(handler); _factory = new ClientFactory( new TestHttpClientFactory(httpClientFake), new InMemoryScopeRepository(), s => s.DeserializeWithJavascript <Uri[]>(), new TestOutputLogger("test", _outputHelper)); var ex = await _factory.Build(parameter).ConfigureAwait(false) as Option <Client> .Error; Assert.Equal(ErrorCodes.InvalidClientMetaData, ex.Details.Title); Assert.Equal(Strings.OneOrMoreSectorIdentifierUriIsNotARedirectUri, ex.Details.Detail); }
public async Task <IActionResult> Put([FromBody] Client?client, CancellationToken cancellationToken) { if (client == null) { return(BuildError(ErrorCodes.InvalidRequest, Strings.NoParameterInBodyRequest, HttpStatusCode.BadRequest)); } try { var clientFactory = new ClientFactory(_httpClient, _scopeStore, _urlReader, _logger); var toInsert = await clientFactory.Build(client, false, cancellationToken).ConfigureAwait(false); switch (toInsert) { case Option <Client> .Error error: return(BuildError(error.Details.Title, error.Details.Detail, error.Details.Status)); case Option <Client> .Result result: var updated = await _clientRepository.Update(result.Item, cancellationToken).ConfigureAwait(false); return(updated switch { Option.Success => Ok(result.Item), _ => BadRequest( new ErrorDetails { Status = HttpStatusCode.BadRequest, Title = ErrorCodes.UnhandledExceptionCode, Detail = Strings.RequestIsNotValid }) });
public IAppointmentFactory WithClient(Action <ClientFactory> client) { var clientFactory = new ClientFactory(); client(clientFactory); this.client = clientFactory.Build(); return(this); }
private static async Task <IClusterClient> StartClientWithRetries(int initializeAttemptsBeforeFailing = 5) { var serviceName = new Uri("fabric:/AppCloud/StatelessHost"); const string invariant = "Npgsql"; const string connectionString = "Server=127.0.0.1;Port=5432;Database=Orleans;User Id=postgres;Password=123456;Pooling=false;"; int attempt = 0; IClusterClient client; while (true) { try { client = await ClientFactory.Build(() => { var builder = new ClientBuilder() //.UseLocalhostClustering() .Configure <ClusterOptions>(options => { //options.ServiceId =serviceName.ToString(); options.ServiceId = "CoinWeb"; options.ClusterId = "CoinV2"; }) .UseAdoNetClustering(option => { option.ConnectionString = connectionString; option.Invariant = invariant; }) .ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(IHello).Assembly).WithReferences()) .ConfigureLogging(logging => logging.AddConsole()); return(builder); }); Console.WriteLine("Client successfully connect to silo host"); break; } catch (SiloUnavailableException) { attempt++; Console.WriteLine($"Attempt {attempt} of {initializeAttemptsBeforeFailing} failed to initialize the Orleans client."); if (attempt > initializeAttemptsBeforeFailing) { throw; } await Task.Delay(TimeSpan.FromSeconds(4)); } } return(client); }
public async Task When_Passing_Valid_Request_Then_No_Exception_Is_Thrown() { var parameter = new Client { RedirectionUrls = new[] { new Uri("http://localhost") }, AllowedScopes = new[] { "openid" }, ApplicationType = ApplicationTypes.Native, JsonWebKeys = TestKeys.SecretKey.CreateSignatureJwk().ToSet(), //new JsonWebKeySet(), IdTokenEncryptedResponseAlg = SecurityAlgorithms.Aes128KW, IdTokenEncryptedResponseEnc = SecurityAlgorithms.Aes128CbcHmacSha256, UserInfoEncryptedResponseAlg = SecurityAlgorithms.Aes128KW, UserInfoEncryptedResponseEnc = SecurityAlgorithms.Aes128CbcHmacSha256, RequestObjectEncryptionAlg = SecurityAlgorithms.Aes128KW, RequestObjectEncryptionEnc = SecurityAlgorithms.Aes128CbcHmacSha256, RequestUris = new[] { new Uri("http://localhost") }, SectorIdentifierUri = new Uri("https://localhost") }; var sectorIdentifierUris = new List <string> { "http://localhost" }; var json = sectorIdentifierUris.SerializeWithJavascript(); var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.Accepted) { Content = new StringContent(json) }; var handler = new FakeHttpMessageHandler(httpResponseMessage); var httpClientFake = new HttpClient(handler); _factory = new ClientFactory( new TestHttpClientFactory(httpClientFake), new InMemoryScopeRepository(), s => s.DeserializeWithJavascript <Uri[]>(), new TestOutputLogger("test", _outputHelper)); var ex = await Record.ExceptionAsync(() => _factory.Build(parameter)).ConfigureAwait(false); Assert.Null(ex); }
public async Task When_One_Request_Uri_Contains_A_Fragment_Then_Exception_Is_Thrown() { var localhost = "http://localhost/#localhost"; var parameter = new Client { JsonWebKeys = TestKeys.SecretKey.CreateSignatureJwk().ToSet(), RedirectionUrls = new[] { new Uri(localhost) }, AllowedScopes = new[] { "test" }, RequestUris = new[] { new Uri("https://localhost"), } }; var ex = await _factory.Build(parameter).ConfigureAwait(false) as Option <Client> .Error; Assert.Equal(ErrorCodes.InvalidRedirectUri, ex.Details.Title); Assert.Equal(string.Format(Strings.TheRedirectUrlCannotContainsFragment, localhost), ex.Details.Detail); }