コード例 #1
0
        public override async Task ExecuteResultAsync(ActionContext context)
        {
            ILogger <EgressStreamResult> logger = context.HttpContext.RequestServices
                                                  .GetRequiredService <ILoggerFactory>()
                                                  .CreateLogger <EgressStreamResult>();

            using var _ = logger.BeginScope(_scope);

            await context.InvokeAsync(async (token) =>
            {
                IEgressService egressService = context.HttpContext.RequestServices
                                               .GetRequiredService <IEgressService>();

                EgressResult egressResult = await _egress(egressService, token);

                logger.LogInformation("Egressed to {0}", egressResult.Value);

                // The remaining code is creating a JSON object with a single property and scalar value
                // that indiates where the stream data was egressed. Because the name of the artifact is
                // automatically generated by the REST API and the caller of the endpoint might not know
                // the specific configuration information for the egress provider, this value allows the
                // caller to more easily find the artifact after egress has completed.
                IDictionary <string, string> data = new Dictionary <string, string>(StringComparer.Ordinal);
                data.Add(egressResult.Name, egressResult.Value);

                ActionResult jsonResult = new JsonResult(data);
                await jsonResult.ExecuteResultAsync(context);
            }, logger);
        }
コード例 #2
0
        public async Task <ExecutionResult <EgressResult> > ExecuteAsync(IServiceProvider serviceProvider, CancellationToken token)
        {
            ILogger <EgressOperation> logger = serviceProvider
                                               .GetRequiredService <ILoggerFactory>()
                                               .CreateLogger <EgressOperation>();

            using var _ = logger.BeginScope(_scope);

            return(await ExecutionHelper.InvokeAsync(async (token) =>
            {
                IEgressService egressService = serviceProvider
                                               .GetRequiredService <IEgressService>();

                EgressResult egressResult = await _egress(egressService, token);

                logger.EgressedArtifact(egressResult.Value);

                // The remaining code is creating a JSON object with a single property and scalar value
                // that indiates where the stream data was egressed. Because the name of the artifact is
                // automatically generated by the REST API and the caller of the endpoint might not know
                // the specific configuration information for the egress provider, this value allows the
                // caller to more easily find the artifact after egress has completed.
                return ExecutionResult <EgressResult> .Succeeded(egressResult);
            }, logger, token));
        }
コード例 #3
0
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            string egressProvider = (string)value;

            IEgressService egressService = validationContext.GetRequiredService <IEgressService>();

            try
            {
                egressService.ValidateProvider(egressProvider);
            }
            catch (Exception)
            {
                return(new ValidationResult(
                           string.Format(
                               CultureInfo.InvariantCulture,
                               Strings.ErrorMessage_EgressProviderDoesNotExist,
                               egressProvider)));
            }

            return(ValidationResult.Success);
        }