public override void ExecuteCmdlet()

in src/Modules/Data/Commands.Data/ExportPowerBIDataflow.cs [61:108]


        public override void ExecuteCmdlet()
        {
            if (!string.IsNullOrEmpty(this.OutFile))
            {
                this.OutFile = this.ResolveFilePath(this.OutFile, false);
                if (File.Exists(this.OutFile))
                {
                    this.Logger.ThrowTerminatingError(new IOException($"OutFile '{this.OutFile}' already exists, specify a new file path"), ErrorCategory.ResourceExists);
                }
            }

            if (this.Dataflow != null)
            {
                this.Id = this.Dataflow.Id;

                this.Logger.WriteDebug($"Using {nameof(this.Dataflow)} object to get {nameof(this.Id)} parameter. Value: {this.Id}");
            }

            using (var client = this.CreateClient())
            {
                using (var dataflowStream = this.Scope == PowerBIUserScope.Organization ?
                    client.Dataflows.ExportDataflowAsAdmin(this.Id) :
                    client.Dataflows.GetDataflow(this.WorkspaceId, this.Id))
                {
                    if (dataflowStream != null)
                    {
                        try
                        {
                            using (var fileStream = new FileStream(this.OutFile, FileMode.CreateNew, FileAccess.Write, FileShare.None))
                            {
                                dataflowStream.CopyTo(fileStream);
                            }

                            this.Logger.WriteVerbose($"OutFile '{this.OutFile}' created");
                        }
                        catch (Exception ex)
                        {
                            this.Logger.WriteError($"Failed to write dataflow with ID {this.Id} to file {this.OutFile}. Message: {ex.Message}");
                        }
                    }
                    else
                    {
                        var workspaceMessage = this.WorkspaceId != default ? $" with workspace ID {this.WorkspaceId}" : string.Empty;
                        this.Logger.WriteError($"Failed to export dataflow with ID {this.Id}{workspaceMessage}");
                    }
                }
            }
        }