in src/Modules/Profile/Commands.Profile/InvokePowerBIRestMethod.cs [66:118]
public override void ExecuteCmdlet()
{
if(string.IsNullOrWhiteSpace(this.ContentType))
{
this.ContentType = "application/json";
}
if(!string.IsNullOrEmpty(this.OutFile))
{
this.OutFile = this.ResolveFilePath(this.OutFile, false);
if(File.Exists(this.OutFile))
{
this.Logger.ThrowTerminatingError(new NotSupportedException($"OutFile '{this.OutFile}' already exists, specify a new file path"), ErrorCategory.InvalidArgument);
}
}
if(Uri.TryCreate(this.Url, UriKind.Absolute, out Uri testUri))
{
this.Url = testUri.AbsoluteUri;
}
else
{
this.Url = $"{this.Version}/{this.Organization}/" + this.Url;
}
if((this.Body == null) && (this.Method == PowerBIWebRequestMethod.Patch || this.Method == PowerBIWebRequestMethod.Post))
{
this.Logger.WriteWarning($"The {nameof(this.Body)} parameter was null, the request may be invalid when {nameof(this.Method)} parameter is {this.Method}.");
this.Body = string.Empty;
}
var response = this.InvokeRestMethod(this.Url, this.Body, this.Method).Result;
if (string.IsNullOrEmpty(this.OutFile))
{
var result = response.Content;
if (result != null)
{
this.Logger.WriteObject(result);
}
}
else
{
using (var fileStream = new FileStream(this.OutFile, FileMode.CreateNew, FileAccess.Write, FileShare.None))
{
using (var responseStream = response.ContentStream)
{
responseStream.CopyTo(fileStream);
}
}
this.Logger.WriteVerbose($"OutFile '{this.OutFile}' created");
}
}