Ejemplo n.º 1
0
        private IOriginReader CreateS3Reader(Uri uri)
        {
            var context = S3Utils.CreateContext(uri);

            return(new OriginReader(
                       Trace(
                           Count(
                               new S3ObjectSource(context),
                               "origin.s3")),
                       Robust(
                           Trace(
                               Count(
                                   new S3ObjectReader(context),
                                   "s3")))));
        }
        private IDestinationWriter CreateS3Writer(string?recycleAddress, Uri uri)
        {
            var            context = S3Utils.CreateWriteContext(uri);
            S3WriteContext?recycleContext;

            if (recycleAddress is object)
            {
                if (!Uri.TryCreate(recycleAddress, UriKind.Absolute, out var recycleUri))
                {
                    throw new ArgumentOutOfRangeException(nameof(recycleAddress), "Invalid S3 recycle address.");
                }

                recycleContext = S3Utils.CreateWriteContext(recycleUri);
            }
            else
            {
                recycleContext = null;
            }

            var        destinationAddress = context.S3.ServiceUrl.AbsoluteUri;
            var        lockName           = FormattableString.Invariant($"{Environment.MachineName.ToUpperInvariant()}_{Environment.ProcessId}_{Guid.NewGuid():N}");
            const byte S3Retries          = 30;

            return(new DestinationWriter(
                       destinationAddress,
                       Retry(
                           Trace(
                               Count(
                                   new S3ObjectSource(context),
                                   "destination.s3"),
                               "destination"),
                           S3Retries),
                       Robust(
                           Trace(
                               Count(
                                   new S3ObjectWriter(context, recycleContext),
                                   "s3"))),
                       Lock(
                           Cache(
                               Retry(
                                   Trace(
                                       new S3ObjectWriterLocker(context, lockName)),
                                   S3Retries)))));
        }