Skip to content

Commit 6bb0997

Browse files
author
Aman Orazaev
committed
Add -Force, use DataStore functions to write file
1 parent 7cfe76f commit 6bb0997

File tree

5 files changed

+54
-3
lines changed

5 files changed

+54
-3
lines changed

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Dataplane/Commands/Export-AzureAsInstanceLog.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@
1414

1515
using System;
1616
using System.IO;
17+
using System.Globalization;
1718
using System.Linq;
1819
using System.Management.Automation;
1920
using System.Management.Instrumentation;
2021
using System.Net.Http;
2122
using System.Net.Http.Headers;
2223
using System.Threading.Tasks;
24+
using Microsoft.Azure.Commands.Common.Authentication;
2325
using Microsoft.Azure.Commands.AnalysisServices.Dataplane.Models;
2426
using Microsoft.Azure.Commands.AnalysisServices.Dataplane.Properties;
2527
using Microsoft.Azure.Commands.Common.Authentication.Abstractions;
@@ -30,6 +32,7 @@
3032

3133
namespace Microsoft.Azure.Commands.AnalysisServices.Dataplane
3234
{
35+
3336
/// <summary>
3437
/// Cmdlet to export an Analysis Services server log to file
3538
/// </summary>
@@ -48,6 +51,10 @@ public class ExportAzureAnalysisServerLog : AzurePSCmdlet
4851
[ValidateNotNullOrEmpty]
4952
public string OutputPath { get; set; }
5053

54+
[Parameter(Mandatory = false, HelpMessage = "Overwrite file if exists")]
55+
[ValidateNotNullOrEmpty]
56+
public SwitchParameter Force { get; set; }
57+
5158
public IAsAzureHttpClient AsAzureHttpClient { get; private set; }
5259

5360
public ITokenCacheItemProvider TokenCacheItemProvider { get; private set; }
@@ -159,10 +166,15 @@ public override void ExecuteCmdlet()
159166
using (HttpResponseMessage message = AsAzureHttpClient.CallGetAsync(
160167
resolvedUriBuilder.Uri,
161168
logfileEndpoint,
162-
accessToken).Result)
169+
accessToken).ConfigureAwait(false).GetAwaiter().GetResult())
163170
{
164171
message.EnsureSuccessStatusCode();
165-
File.WriteAllText(this.OutputPath, message.Content.ReadAsStringAsync().Result);
172+
string actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.ExportingLogOverwriteWarning, this.OutputPath);
173+
if (AzureSession.Instance.DataStore.FileExists(this.OutputPath) && !this.Force.IsPresent && !ShouldContinue(actionWarning, Resources.Confirm))
174+
{
175+
return;
176+
}
177+
AzureSession.Instance.DataStore.WriteFile(this.OutputPath, message.Content.ReadAsStringAsync().Result);
166178
}
167179
}
168180
}

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Dataplane/Properties/Resources.Designer.cs

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Dataplane/Properties/Resources.resx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,12 @@
132132
<data name="ExportingLogFromAnalysisServicesServer" xml:space="preserve">
133133
<value>Export log from Analysis Services server</value>
134134
</data>
135+
<data name="ExportingLogOverwriteWarning" xml:space="preserve">
136+
<value>Writing log to file {0}</value>
137+
</data>
138+
<data name="Confirm" xml:space="preserve">
139+
<value>Confirm</value>
140+
</data>
135141
<data name="UnknownEnvironment" xml:space="preserve">
136142
<value>Unknown Analysis Services environment name specified.</value>
137143
</data>

src/ResourceManager/AnalysisServices/Commands.AnalysisServices.Dataplane/help/Export-AzureAnalysisServicesInstanceLog.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Exports a log from an instance of Analysis Services server in the currently logg
1212
## SYNTAX
1313

1414
```
15-
Export-AzureAnalysisServicesInstanceLog [-Instance] <String> [-OutputPath] <String> [-WhatIf]
15+
Export-AzureAnalysisServicesInstanceLog [-Instance] <String> [-OutputPath] <String> [-WhatIf] [-Force]
1616
```
1717

1818
## DESCRIPTION
@@ -60,6 +60,21 @@ Accept pipeline input: False
6060
Accept wildcard characters: False
6161
```
6262
63+
### -Force
64+
Overwrite file if exists without asking
65+
66+
```yaml
67+
Type: SwitchParameter
68+
Parameter Sets: (All)
69+
Aliases:
70+
71+
Required: False
72+
Position: Named
73+
Default value: None
74+
Accept pipeline input: False
75+
Accept wildcard characters: False
76+
```
77+
6378
## INPUTS
6479
6580
## OUTPUTS

tools/PS-VSPrompt.lnk

68 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)