示例#1
0
        private async Task <RepositoryDescription> GetRepositoryDescription(ServiceInvocationContext context)
        {
            // We use ConfigureAwait(false) to prevent .NET from trying to synchronize back to our current Sync Context (UI Thread/HttpContext/etc)
            // when continuing from await. We don't care about Sync Context, so this saves the perf hit of syncing back. Our caller will still
            // sync back to their current Sync Context when they await us, so this doesn't affect them.
            using (context.Trace.EnterExit())
            {
                try
                {
                    // Invoke the request
                    var url      = new Uri("/", UriKind.Relative);
                    var response = await context.GetAsync(url, context.CancellationToken)
                                   .ConfigureAwait(continueOnCapturedContext: false);

                    context.CancellationToken.ThrowIfCancellationRequested();
                    response.EnsureSuccessStatusCode();

                    // Parse the response as JSON
                    var json = JObject.Parse(await response.Content.ReadAsStringAsync()
                                             .ConfigureAwait(continueOnCapturedContext: false));

                    // Load the json in to a result
                    return(RepositoryDescription.FromJson(json, context.Trace, context.ResolveUrl(url)));
                }
                catch (Exception ex)
                {
                    context.Trace.Error(ex);
                    throw;
                }
            }
        }
示例#2
0
        private async Task <ServiceClient> CreateClient(string serviceName, ServiceInvocationContext context)
        {
            using (context.Trace.EnterExit())
            {
                var service = await GetService(serviceName, context);

                return(new ServiceClient(service, this));
            }
        }
示例#3
0
        private async Task <ServiceDescription> GetService(string serviceName, ServiceInvocationContext context)
        {
            using (context.Trace.EnterExit())
            {
                // TODO: Caching!
                var repoDesc = await GetRepositoryDescription(context);

                context.CancellationToken.ThrowIfCancellationRequested();
                return(repoDesc.Services.FirstOrDefault(svc => String.Equals(svc.Name, serviceName, StringComparison.OrdinalIgnoreCase)));
            }
        }
        private async Task<RepositoryDescription> GetRepositoryDescription(ServiceInvocationContext context)
        {
            // We use ConfigureAwait(false) to prevent .NET from trying to synchronize back to our current Sync Context (UI Thread/HttpContext/etc)
            // when continuing from await. We don't care about Sync Context, so this saves the perf hit of syncing back. Our caller will still 
            // sync back to their current Sync Context when they await us, so this doesn't affect them.
            using (context.Trace.EnterExit())
            {
                try
                {
                    // Invoke the request
                    var url = new Uri("/", UriKind.Relative);
                    var response = await context.GetAsync(url, context.CancellationToken)
                        .ConfigureAwait(continueOnCapturedContext: false);
                    context.CancellationToken.ThrowIfCancellationRequested();
                    response.EnsureSuccessStatusCode();

                    // Parse the response as JSON
                    var json = JObject.Parse(await response.Content.ReadAsStringAsync()
                        .ConfigureAwait(continueOnCapturedContext: false));

                    // Load the json in to a result
                    return RepositoryDescription.FromJson(json, context.Trace, context.ResolveUrl(url));
                }
                catch (Exception ex)
                {
                    context.Trace.Error(ex);
                    throw;
                }
            }
        }
 private async Task<ServiceClient> CreateClient(string serviceName, ServiceInvocationContext context)
 {
     using (context.Trace.EnterExit())
     {
         var service = await GetService(serviceName, context);
         return new ServiceClient(service, this);
     }
 }
 private async Task<ServiceDescription> GetService(string serviceName, ServiceInvocationContext context)
 {
     using (context.Trace.EnterExit())
     {
         // TODO: Caching!
         var repoDesc = await GetRepositoryDescription(context);
         context.CancellationToken.ThrowIfCancellationRequested();
         return repoDesc.Services.FirstOrDefault(svc => String.Equals(svc.Name, serviceName, StringComparison.OrdinalIgnoreCase));
     }
 }