public override void ExecuteCmdlet()

in src/PowerShell/Commands/GetPartnerInvoiceStatement.cs [41:78]


        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");
                }

                using (Stream stream = await partner.Invoices.ById(InvoiceId).Documents.Statement.GetAsync(CancellationToken).ConfigureAwait(false))
                {
                    FileStream file = File.Create(filePath);
                    stream.Seek(0, SeekOrigin.Begin);
                    stream.CopyTo(file);

                    file.Close();
                }
            }, true);
        }