public static MemoryMappedBasedRetrievedSecrets ReadExposedSecrets(OperationContext context, string?fileName = null, int pollingIntervalInSeconds = 10)
        {
            string memoryMappedFileName = fileName ?? SecretsFileName;

            var secrets = context.PerformOperation(
                Tracer,
                () =>
            {
                var content = MemoryMappedFileHelper.ReadContent(memoryMappedFileName);
                return(RetrievedSecretsSerializer.Deserialize(content));
            },
                extraStartMessage: $"Obtaining secrets from '{memoryMappedFileName}'",
                messageFactory: _ => $"Obtained secrets from '{memoryMappedFileName}'").ThrowIfFailure();

            TimeSpan pollingInterval = TimeSpan.FromSeconds(pollingIntervalInSeconds);
            Timer?   timer           = null;

            var result = new MemoryMappedBasedRetrievedSecrets(secrets.Secrets, () => timer?.Dispose(), memoryMappedFileName);

            timer = new Timer(
                _ =>
            {
                result.RefreshSecrets(context);

                try
                {
                    timer?.Change(pollingInterval, Timeout.InfiniteTimeSpan);
                } catch (ObjectDisposedException) { }
            },
                state: null,
                dueTime: pollingInterval,
                period: Timeout.InfiniteTimeSpan);

            return(result);
        }
            public void RefreshSecrets(OperationContext context)
            {
                var newSecrets = context.PerformOperation(
                    Tracer,
                    () =>
                {
                    var content = MemoryMappedFileHelper.ReadContent(MemoryMappedFileName);
                    return(RetrievedSecretsSerializer.Deserialize(content));
                },
                    extraStartMessage: $"Refreshing secrets from '{MemoryMappedFileName}'",
                    messageFactory: _ => $"Refreshing secrets from '{MemoryMappedFileName}'");

                // Now we need to update the secrets originally read from file.
                if (newSecrets.Succeeded)
                {
                    context.PerformOperation(
                        Tracer,
                        () =>
                    {
                        UpdateSecrets(this, newSecrets.Value);
                        return(BoolResult.Success);
                    }).IgnoreFailure();     // the error was already traced.
                }
            }