public async Task InvokeGenericCalculator() { // create instance of GenericCalculatorInt32Client, see MyGrpcProxies var proxy = _clientFactory.CreateClient <IGenericCalculator <int> >(_channel); // POST /IGenericCalculator-Int32/Touch Console.WriteLine("Invoke Touch"); var touchResponse = proxy.Touch(); Console.WriteLine(" {0}", touchResponse); // POST /IGenericCalculator-Int32/GetRandomValue Console.WriteLine("Invoke GetRandomValue"); var x = await proxy.GetRandomValue(); var y = await proxy.GetRandomValue(); Console.WriteLine(" X = {0}", x); Console.WriteLine(" Y = {0}", y); // POST /IGenericCalculator-Int32/Sum Console.WriteLine("Invoke Sum"); var sumResponse = await proxy.Sum(x, y); Console.WriteLine(" {0} + {1} = {2}", x, y, sumResponse); // POST /IGenericCalculator-Int32/Multiply Console.WriteLine("Invoke Multiply"); var multiplyResponse = await proxy.Multiply(x, y); Console.WriteLine(" {0} * {1} = {2}", x, y, multiplyResponse); }
private static async Task InvokeThrowApplicationException(ChannelBase channel) { var client = DefaultClientFactory.CreateClient <IDebugService>(channel); try { await client.ThrowApplicationException(" application error occur"); } catch (ApplicationException ex) { Console.WriteLine(ex.Message); } }
private IClient CreateClient() { string clientID = clientIDGenerator.GenerateClientID(); IClient client = clientFactory.CreateClient(clientID); return(client); }
/// <summary> /// Initializes a new <see cref="LogServiceAdapter"/> instance. /// </summary> /// <param name="clientFactory">An instance capable of creating a wcf client.</param> /// <param name="logger">The logger.</param> public LogServiceAdapter( IClientFactory <ILogService> clientFactory, ILogger logger) { _client = clientFactory.CreateClient(); _logger = logger; }
private async Task <IModel> ConnectAsync(CancellationToken cancellationToken) { ExceptionDispatchInfo edi = null; for (int i = 0; i < 5; i++) { try { return(_queueFactory.CreateClient("rabbit")); } catch (Exception ex) { if (i == 4) { edi = ExceptionDispatchInfo.Capture(ex); } _logger.LogError(0, ex, "Failed to start listening to rabbit mq"); } await Task.Delay(5000, cancellationToken); } edi.Throw(); return(null); }
private static async Task ServiceModelCall(ChannelBase channel) { var client = DefaultClientFactory.CreateClient <ICalculator>(channel); // SumAsync var sumResult = await client.SumAsync(1, 2, 3); Console.WriteLine(" SumAsync(1 + 2 + 3) = {0}", sumResult); // SumValues var sumValuesResult = await client.SumValuesAsync(new[] { 1, 2, 3 }.AsAsyncEnumerable()); Console.WriteLine(" SumValuesAsync(1 + 2 + 3) = {0}", sumValuesResult); // Range var rangeResult = new List <int>(); await foreach (var i in client.Range(0, 3)) { rangeResult.Add(i); } Console.WriteLine(" Range(0, 3) = {0}", string.Join(", ", rangeResult)); // MultiplyBy2 var multiplyBy2Result = new List <int>(); await foreach (var i in client.MultiplyBy2(new[] { 1, 2, 3 }.AsAsyncEnumerable())) { multiplyBy2Result.Add(i); } Console.WriteLine(" MultiplyBy2(1, 2, 3) = ({0})", string.Join(", ", multiplyBy2Result)); }
public ISimulationClient SayHello(string ip) { var client = clientFactory.CreateClient(ip); clients.AddClient(client); return(client); }
public override Task Tell(byte[] wrapBytes, byte[] dataBytes, IMessage data, MessageInfo msg) { if (data is IEventBase <long> evt) { return(clientFactory.CreateClient().GetGrain <IAccountDb>(evt.StateId).Tell(wrapBytes)); } return(Task.CompletedTask); }
private Client CreateClient() { string clientID = clientIDGenerator.GenerateClientID(); Client client = clientFactory.CreateClient(clientID); this.clientRepository.Add(client); return(client); }
public Guid AllocateClient() { var guid = Guid.NewGuid(); // TODO MN - handle null _clients[guid] = _clientFactory.CreateClient(); return(guid); }
private static async Task Run(ChannelBase channel) { var personService = DefaultClientFactory.CreateClient <IPersonService>(channel); var person = await personService.CreatePerson("John X", DateTime.Today.AddYears(-20)); Console.WriteLine(" Name: {0}", person.Name); Console.WriteLine(" BirthDay: {0}", person.BirthDay); Console.WriteLine(" CreatedBy: {0}", person.CreatedBy); }
public void RunSync() { var personService = _clientFactory.CreateClient <IPersonService>(_channel); Console.WriteLine("Invoke Create"); var person = personService.Create("John X", DateTime.Today.AddYears(-20)); Console.WriteLine(" Name: {0}", person.Name); Console.WriteLine(" BirthDay: {0}", person.BirthDay); Console.WriteLine("Invoke Update"); person = personService.Update(person, "John", DateTime.Today.AddYears(-21)); Console.WriteLine(" Name: {0}", person.Name); Console.WriteLine(" BirthDay: {0}", person.BirthDay); }
private void WorkerFetching(object sender, DoWorkEventArgs e) { using (IClient client = _clientFactory.CreateClient(e.Argument as ClientConfiguration)) { if (client.IsConnected) { e.Result = client.FetchBuilds(); } } }
public MovieWatcher( IOptions <MovieWatcherOptions> options, IQueueManager queue, ILogger <MovieRelease> logger, IMapper mapper, IClientFactory <RadarrClient> factory) : base(options, queue, logger, mapper) { this.Client = factory.CreateClient(new Uri(this.Options.Endpoint), this.Options.ApiKey); }
public IEnumerable <Build> GetBuildsFromCI() { if (!_config.AllDataExists) { return(new List <Build>()); } try { using (var client = _clientFactory.CreateClient(_config)) { if (!client.IsConnected) { return(new List <Build>()); } return(Settings.Default.Builds.Select(storedBuild => { try { var build = client.BuildByUniqueIdentifier(storedBuild.UniqueIdentifier); _pluginHandler.TriggerPlugins(storedBuild, build); var daysLastBuildHappened = DateTime.Now.Subtract(build.StartDate).Days; var happenedInLastWeeks = daysLastBuildHappened < Settings.Default.HideInactiveWeeks * 7; if (!Settings.Default.HideInactive) { return build; } if (Settings.Default.HideInactive && happenedInLastWeeks) { return build; } return null; // Build is hidden, based on rules above } catch (ClientLoadDocumentException) { // Return an error-info-containing build when the given build cannot be loaded return new Build { StatusText = "Could not obtain build info. Was this project removed on the server?" }; } }) .Where(b => b != null) .ToList()); } } catch (ClientConnectionException) { return(new List <Build>()); // TODO: Display error message } }
private void WorkerFetching(object sender, DoWorkEventArgs e) { using (IClient client = _clientFactory.CreateClient(e.Argument as ClientConfiguration)) { if (client.IsConnected) { ReadOnlyCollection <Build> builds = client.Builds(); e.Result = builds; } } }
public static IClient CreateClient(this IClientFactory clientFactory, string name, Uri baseUri) { if (clientFactory == null) { throw new ArgumentNullException(nameof(clientFactory)); } var client = clientFactory.CreateClient(name); client.BaseUri = baseUri; return(client); }
public static async Task CallPersonService(int port) { var channel = new Channel("localhost", port, ChannelCredentials.Insecure); var personService = DefaultClientFactory.CreateClient <IPersonService>(channel); var person = await personService.CreatePerson("John X", DateTime.Today.AddYears(-20)); Console.WriteLine(" Name: {0}", person.Name); Console.WriteLine(" BirthDay: {0}", person.BirthDay); Console.WriteLine(" CreatedBy: {0}", person.CreatedBy); }
public static async Task Main() { var aspNetCoreChannel = new Channel("localhost", SharedConfiguration.AspNetgRPCPersonServicePort, ChannelCredentials.Insecure); var proxy = DefaultClientFactory.CreateClient<IPersonService>(aspNetCoreChannel); Console.WriteLine("-- call AspNetServiceHost --"); await CallGet(proxy); await CallGetAll(proxy); var nativeChannel = new Channel("localhost", SharedConfiguration.NativegRPCPersonServicePort, ChannelCredentials.Insecure); proxy = DefaultClientFactory.CreateClient<IPersonService>(nativeChannel); Console.WriteLine(); Console.WriteLine("-- call NativeServiceHost --"); await CallGet(proxy); await CallGetAll(proxy); Console.WriteLine("..."); Console.ReadLine(); }
public async Task <IActionResult> OnPost([FromServices] IClientFactory <IOrderService> clientFactory) { var client = clientFactory.CreateClient("backend"); var order = new Order { OrderId = Guid.NewGuid(), CreatedTime = DateTime.UtcNow, UserId = User.Identity.Name }; await client.PlaceOrderAsync(order); return(Redirect("/")); }
public static async Task Main() { var aspNetCoreChannel = new Channel("localhost", SharedConfiguration.AspNetgRPCDebugServicePort, ChannelCredentials.Insecure); // register IDebugService proxy generated by ServiceModel.Grpc.DesignTime DefaultClientFactory.AddDebugServiceClient(); var proxy = DefaultClientFactory.CreateClient <IDebugService>(aspNetCoreChannel); Console.WriteLine("-- call AspNetServiceHost --"); await CallThrowApplicationException(proxy); await CallThrowInvalidOperationException(proxy); var nativeChannel = new Channel("localhost", SharedConfiguration.NativegRPCDebugServicePort, ChannelCredentials.Insecure); proxy = DefaultClientFactory.CreateClient <IDebugService>(nativeChannel); Console.WriteLine(); Console.WriteLine("-- call NativeServiceHost --"); await CallThrowApplicationException(proxy); await CallThrowInvalidOperationException(proxy); Console.WriteLine("..."); Console.ReadLine(); }
public ActionResult Create(Client client) { if (ModelState.IsValid) { clientFactory.CreateClient(client); //WillisAssociate/WillisAssociate/Wizard/ if (Request.QueryString["source"] != null && Request.QueryString["source"] == "wizard") { return(RedirectToAction("Wizard", "WillisAssociate", new { area = "WillisAssociate", ClientID = client.ClientID })); } return(RedirectToAction("Index")); } return(View(client)); }
private void ConnectAndRender() { UniformGridBuilds.Children.Clear(); UniformGridBuilds.Columns = Settings.Default.NumberOfColumns; ClientConfiguration clientConfiguration = LoadClientConfiguration(); if (!clientConfiguration.AllDataExists) { return; } try { using (IClient client = _clientFactory.CreateClient(clientConfiguration)) { if (client.IsConnected) { foreach (Build storedBuild in Settings.Default.Builds) { try { Build build = client.BuildByUniqueIdentifier(storedBuild.UniqueIdentifier); _pluginHandler.TriggerPlugins(storedBuild, build); int daysLastBuildHappened = DateTime.Now.Subtract(build.StartDate).Days; if (!Settings.Default.HideInactive || Settings.Default.HideInactive && daysLastBuildHappened < Settings.Default.HideInactiveWeeks * 7) { LoadGridWithBuilds(build); } } catch (ClientLoadDocumentException) { // TODO: One build could not get loaded via typeId, maybe it got deleted but is still in the settings; Display error message } } } } } catch (ClientConnectionException ex) { // Display error message MessageBox.Show("Der er sket en fejl: " + ex.Message); } }
public ServiceModelGrpcCombinedCallTest(IMarshallerFactory marshallerFactory, SomeObject payload) { _payload = payload; var builder = new WebHostBuilder().UseStartup(_ => new Startup(marshallerFactory)); _server = new TestServer(builder); _client = _server.CreateClient(); _channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions { HttpClient = _client }); _clientFactory = new ClientFactory(new ServiceModelGrpcClientOptions { MarshallerFactory = marshallerFactory }); _proxy = _clientFactory.CreateClient <ITestService>(_channel); }
public ServiceModelGrpcProtoCombinedCallTest(SomeObject payload) { _payload = DomainExtensions.CopyToProto(payload); var builder = new WebHostBuilder().UseStartup <Startup>(); _server = new TestServer(builder); _client = _server.CreateClient(); _channel = GrpcChannel.ForAddress("http://localhost", new GrpcChannelOptions { HttpClient = _client }); _clientFactory = new ClientFactory(new ServiceModelGrpcClientOptions { MarshallerFactory = GoogleProtoMarshallerFactory.Default }); _proxy = _clientFactory.CreateClient <ITestService>(_channel); }
public ValueTask PlaceOrderAsync(Order order) { var channel = _clientFactory.CreateClient("Rabbit"); channel.QueueDeclare(queue: "orders", durable: false, exclusive: false, autoDelete: false, arguments: null); var orderBytes = JsonSerializer.SerializeToUtf8Bytes(order); channel.BasicPublish(exchange: "", routingKey: "orders", basicProperties: null, body: orderBytes); return(default);
public static async Task Main(string[] args) { #if NETCOREAPP3_1 ServiceModel.Grpc.GrpcChannelExtensions.Http2UnencryptedSupport = true; #endif using var channel = GrpcChannel.ForAddress("http://localhost:5000"); var client = ClientFactory.CreateClient <ICounterService>(channel); await UnaryCallExample(client); await ClientStreamingCallExample(client); await ServerStreamingCallExample(client); Console.WriteLine("Press any key to exit..."); Console.ReadLine(); }
private static async Task Run() { // create gRPC channel var channel = new Channel("localhost", 5000, ChannelCredentials.Insecure); // create IGreeter client proxy var client = DefaultClientFactory.CreateClient <IGreeter>(channel); var person = new Person { FirstName = "John", SecondName = "X" }; var greet1 = await client.SayHelloAsync(person.FirstName, person.SecondName); Console.WriteLine(greet1); var greet2 = await client.SayHelloToAsync(person); Console.WriteLine(greet2); }
private PSAzureSubscriptionExtended ConstructPsAzureSubscriptionExtended(AzureSubscription subscription, IClientFactory clientFactory) { using (var client = clientFactory.CreateClient <ManagementClient>(Profile, subscription, AzureEnvironment.Endpoint.ServiceManagement)) { var response = client.Subscriptions.Get(); var environment = ProfileClient.GetEnvironmentOrDefault(subscription.Environment); var account = ProfileClient.Profile.Accounts[subscription.Account]; bool isCert = account.Type == AzureAccount.AccountType.Certificate; var psAzureSubscription = new PSAzureSubscription(subscription, ProfileClient.Profile); PSAzureSubscriptionExtended result = new PSAzureSubscriptionExtended(psAzureSubscription) { AccountAdminLiveEmailId = response.AccountAdminLiveEmailId, ActiveDirectoryUserId = subscription.Account, CurrentCoreCount = response.CurrentCoreCount, CurrentHostedServices = response.CurrentHostedServices, CurrentDnsServers = response.CurrentDnsServers, CurrentLocalNetworkSites = response.CurrentLocalNetworkSites, CurrentStorageAccounts = response.CurrentStorageAccounts, CurrentVirtualNetworkSites = response.CurrentVirtualNetworkSites, MaxCoreCount = response.MaximumCoreCount, MaxDnsServers = response.MaximumDnsServers, MaxHostedServices = response.MaximumHostedServices, MaxLocalNetworkSites = response.MaximumLocalNetworkSites, MaxStorageAccounts = response.MaximumStorageAccounts, MaxVirtualNetworkSites = response.MaximumVirtualNetworkSites, ServiceAdminLiveEmailId = response.ServiceAdminLiveEmailId, SubscriptionRealName = response.SubscriptionName, SubscriptionStatus = response.SubscriptionStatus.ToString(), ServiceEndpoint = environment.GetEndpoint(AzureEnvironment.Endpoint.ServiceManagement), ResourceManagerEndpoint = environment.GetEndpoint(AzureEnvironment.Endpoint.ResourceManager), IsDefault = subscription.GetProperty(AzureSubscription.Property.Default) != null, Account = account, Certificate = isCert ? AzureSession.DataStore.GetCertificate(subscription.Account) : null, CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount) }; return(result); } }
private PSAzureSubscriptionExtended ConstructPsAzureSubscriptionExtended(AzureSubscription subscription, IClientFactory clientFactory) { using (var client = clientFactory.CreateClient<ManagementClient>(Profile, subscription, AzureEnvironment.Endpoint.ServiceManagement)) { var response = client.Subscriptions.Get(); var environment = ProfileClient.GetEnvironmentOrDefault(subscription.Environment); var account = ProfileClient.Profile.Accounts[subscription.Account]; bool isCert = account.Type == AzureAccount.AccountType.Certificate; var psAzureSubscription = new PSAzureSubscription(subscription, ProfileClient.Profile); PSAzureSubscriptionExtended result = new PSAzureSubscriptionExtended(psAzureSubscription) { AccountAdminLiveEmailId = response.AccountAdminLiveEmailId, ActiveDirectoryUserId = subscription.Account, CurrentCoreCount = response.CurrentCoreCount, CurrentHostedServices = response.CurrentHostedServices, CurrentDnsServers = response.CurrentDnsServers, CurrentLocalNetworkSites = response.CurrentLocalNetworkSites, CurrentStorageAccounts = response.CurrentStorageAccounts, CurrentVirtualNetworkSites = response.CurrentVirtualNetworkSites, MaxCoreCount = response.MaximumCoreCount, MaxDnsServers = response.MaximumDnsServers, MaxHostedServices = response.MaximumHostedServices, MaxLocalNetworkSites = response.MaximumLocalNetworkSites, MaxStorageAccounts = response.MaximumStorageAccounts, MaxVirtualNetworkSites = response.MaximumVirtualNetworkSites, ServiceAdminLiveEmailId = response.ServiceAdminLiveEmailId, SubscriptionRealName = response.SubscriptionName, SubscriptionStatus = response.SubscriptionStatus.ToString(), ServiceEndpoint = environment.GetEndpoint(AzureEnvironment.Endpoint.ServiceManagement), ResourceManagerEndpoint = environment.GetEndpoint(AzureEnvironment.Endpoint.ResourceManager), IsDefault = subscription.GetProperty(AzureSubscription.Property.Default) != null, Account = account, Certificate = isCert ? AzureSession.DataStore.GetCertificate(subscription.Account) : null, CurrentStorageAccountName = subscription.GetProperty(AzureSubscription.Property.StorageAccount) }; return result; } }
protected override Task SendToAsyncGrain(byte[] bytes, IEventBase <long> evt) { var client = clientFactory.CreateClient(); return(client.GetGrain <IAccountFlow>(evt.StateId).Tell(bytes)); }