public override void ExecuteCmdlet()

in src/PowerShell/Commands/GetPartnerInvoiceTaxReceiptStatement.cs [48:92]


        public override void ExecuteCmdlet()
        {
            Scheduler.RunTask(async () =>
            {
                IPartner partner = await PartnerSession.Instance.ClientFactory.CreatePartnerOperationsAsync(CorrelationId, CancellationToken).ConfigureAwait(false);

                if (string.IsNullOrEmpty(OutputPath))
                {
                    OutputPath = Directory.GetCurrentDirectory();
                }

                DirectoryInfo dirInfo = Directory.CreateDirectory(OutputPath);
                string filePath;

                if (dirInfo.FullName.EndsWith(Path.DirectorySeparatorChar.ToString(CultureInfo.CurrentCulture), System.StringComparison.CurrentCulture))
                {
                    filePath = dirInfo.FullName + InvoiceId + ".pdf";
                }
                else
                {
                    filePath = dirInfo.FullName + Path.DirectorySeparatorChar.ToString(CultureInfo.CurrentCulture) + InvoiceId + ".pdf";
                }

                if (File.Exists(filePath) && !Overwrite.IsPresent)
                {
                    throw new PSInvalidOperationException("The path already exists: " + filePath + ". Specify the -Overwrite switch to overwrite the file");
                }

                FileStream fileStream = null;

                try
                {
                    using (Stream stream = await partner.Invoices.ById(InvoiceId).Documents.Statement.GetAsync(CancellationToken).ConfigureAwait(false))
                    {
                        fileStream = File.Create(filePath);
                        stream.Seek(0, SeekOrigin.Begin);
                        stream.CopyTo(fileStream);
                    }
                }
                finally
                {
                    fileStream?.Dispose();
                }
            }, true);
        }