Skip to content

Commit

Permalink
Merge pull request Azure#7712 from MiYanni/ifdef-tagging
Browse files Browse the repository at this point in the history
Tagging #if statements for Az
  • Loading branch information
MiYanni authored Nov 28, 2018
2 parents 40ab3ed + 55900e5 commit 3471c65
Show file tree
Hide file tree
Showing 152 changed files with 11,301 additions and 2,045 deletions.
1 change: 1 addition & 0 deletions src/ResourceManager/Aks/Commands.Aks/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Current Release
* Minor changes for upcoming AzureRM to Az transition

## Version 0.0.7
* Update dependencies for type mapping issue
Expand Down
1 change: 1 addition & 0 deletions src/ResourceManager/Aks/Commands.Aks/Commands.Aks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,34 +178,27 @@ public override void ExecuteCmdlet()

private void PopBrowser(string uri)
{
#if NETSTANDARD

var browserProcess = new Process
{
StartInfo = new ProcessStartInfo
{
UseShellExecute = true,
Arguments = uri
}
StartInfo = new ProcessStartInfo { Arguments = uri }
};

var verboseMessage = Resources.StartingOnDefault;
// TODO: Remove IfDef
#if NETSTANDARD
if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
WriteVerbose("Starting on OSX with open");
verboseMessage = "Starting on OSX with open";
browserProcess.StartInfo.FileName = "open";
browserProcess.Start();
return;
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
WriteVerbose("Starting on Unix with xdg-open");
verboseMessage = "Starting on Unix with xdg-open";
browserProcess.StartInfo.FileName = "xdg-open";
browserProcess.Start();
return;
}
#endif
WriteVerbose(Resources.StartingOnDefault);
Process.Start(uri);

WriteVerbose(verboseMessage);
browserProcess.Start();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected override IAzureContext DefaultContext
{
get
{
// Nothing to do with Azure Resource Managment context
// Nothing to do with Azure Resource Management context
return null;
}
}
Expand Down Expand Up @@ -141,8 +141,10 @@ protected override void TearDownHttpClientPipeline()

public override void ExecuteCmdlet()
{
AsAzureAccount azureAccount = new AsAzureAccount();
azureAccount.Type = ServicePrincipal ? AsAzureAccount.AccountType.ServicePrincipal : AsAzureAccount.AccountType.User;
var azureAccount = new AsAzureAccount
{
Type = ServicePrincipal ? AsAzureAccount.AccountType.ServicePrincipal : AsAzureAccount.AccountType.User
};

SecureString password = null;
if (Credential != null)
Expand Down Expand Up @@ -183,6 +185,7 @@ public override void ExecuteCmdlet()
{
AsAzureClientSession.Instance.SetCurrentContext(azureAccount, AsEnvironment);
}
// TODO: Remove IfDef
#if NETSTANDARD
var asAzureProfile = AsAzureClientSession.Instance.Login(currentProfile.Context, password, WriteWarning);
#else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

namespace Microsoft.Azure.Commands.AnalysisServices.Dataplane
{

/// <summary>
/// Cmdlet to export an Analysis Services server log to file
/// </summary>
Expand All @@ -35,7 +34,7 @@ namespace Microsoft.Azure.Commands.AnalysisServices.Dataplane
[OutputType(typeof(void))]
public class ExportAzureAnalysisServerLog : AzurePSCmdlet
{
private string serverName;
private string _serverName;

[Parameter(Mandatory = true, HelpMessage = "Name of the Azure Analysis Services which log will be fetched")]
[ValidateNotNullOrEmpty]
Expand All @@ -55,21 +54,21 @@ public class ExportAzureAnalysisServerLog : AzurePSCmdlet

public ExportAzureAnalysisServerLog()
{
this.AsAzureHttpClient = new AsAzureHttpClient(() => new HttpClient());
this.TokenCacheItemProvider = new TokenCacheItemProvider();
AsAzureHttpClient = new AsAzureHttpClient(() => new HttpClient());
TokenCacheItemProvider = new TokenCacheItemProvider();
}

public ExportAzureAnalysisServerLog(IAsAzureHttpClient AsAzureHttpClient, ITokenCacheItemProvider TokenCacheItemProvider)
public ExportAzureAnalysisServerLog(IAsAzureHttpClient asAzureHttpClient, ITokenCacheItemProvider tokenCacheItemProvider)
{
this.AsAzureHttpClient = AsAzureHttpClient;
this.TokenCacheItemProvider = TokenCacheItemProvider;
AsAzureHttpClient = asAzureHttpClient;
TokenCacheItemProvider = tokenCacheItemProvider;
}

protected override IAzureContext DefaultContext
{
get
{
// Nothing to do with Azure Resource Managment context
// Nothing to do with Azure Resource Management context
return null;
}
}
Expand All @@ -91,14 +90,14 @@ protected override void BeginProcessing()
throw new PSInvalidOperationException(string.Format(Resources.NotLoggedInMessage, ""));
}

serverName = Instance;
_serverName = Instance;
Uri uriResult;

// if the user specifies the FQN of the server, then extract the servername out of that.
// if the user specifies the FQN of the server, then extract the server name out of that.
// and set the current context
if (Uri.TryCreate(Instance, UriKind.Absolute, out uriResult) && uriResult.Scheme == "asazure")
{
serverName = uriResult.PathAndQuery.Trim('/');
_serverName = uriResult.PathAndQuery.Trim('/');
if (string.Compare(AsAzureClientSession.Instance.Profile.Context.Environment.Name, uriResult.DnsSafeHost, StringComparison.InvariantCultureIgnoreCase) != 0)
{
AsAzureClientSession.Instance.SetCurrentContext(
Expand All @@ -112,21 +111,18 @@ protected override void BeginProcessing()
if (currentContext != null
&& AsAzureClientSession.AsAzureRolloutEnvironmentMapping.ContainsKey(currentContext.Environment.Name))
{
throw new PSInvalidOperationException(string.Format(Resources.InvalidServerName, serverName));
throw new PSInvalidOperationException(string.Format(Resources.InvalidServerName, _serverName));
}
}

if (this.AsAzureHttpClient == null)
if (AsAzureHttpClient == null)
{
this.AsAzureHttpClient = new AsAzureHttpClient(() =>
{
return new HttpClient();
});
AsAzureHttpClient = new AsAzureHttpClient(() => new HttpClient());
}

if (this.TokenCacheItemProvider == null)
if (TokenCacheItemProvider == null)
{
this.TokenCacheItemProvider = new TokenCacheItemProvider();
TokenCacheItemProvider = new TokenCacheItemProvider();
}
}

Expand All @@ -140,48 +136,46 @@ public override void ExecuteCmdlet()
if (ShouldProcess(Instance, Resources.ExportingLogFromAnalysisServicesServer))
{
var context = AsAzureClientSession.Instance.Profile.Context;
#if NETSTANDARD
AsAzureClientSession.Instance.Login(context, null, null);
#else
AsAzureClientSession.Instance.Login(context, null);
#endif
string accessToken = this.TokenCacheItemProvider.GetTokenFromTokenCache(

var accessToken = TokenCacheItemProvider.GetTokenFromTokenCache(
AsAzureClientSession.TokenCache, context.Account.UniqueId);

Uri logfileBaseUri =
new Uri(string.Format("{0}{1}{2}", Uri.UriSchemeHttps, Uri.SchemeDelimiter, context.Environment.Name));
var logfileBaseUri = new Uri($"{Uri.UriSchemeHttps}{Uri.SchemeDelimiter}{context.Environment.Name}");

UriBuilder resolvedUriBuilder = new UriBuilder(logfileBaseUri);
resolvedUriBuilder.Host = ClusterResolve(logfileBaseUri, accessToken, serverName);
var resolvedUriBuilder = new UriBuilder(logfileBaseUri)
{
Host = ClusterResolve(logfileBaseUri, accessToken, _serverName)
};

var logfileEndpoint = string.Format(
(string) context.Environment.Endpoints[AsAzureEnvironment.AsRolloutEndpoints.LogfileEndpointFormat],
serverName);
_serverName);

this.AsAzureHttpClient.resetHttpClient();
using (HttpResponseMessage message = AsAzureHttpClient.CallGetAsync(
AsAzureHttpClient.resetHttpClient();
using (var message = AsAzureHttpClient.CallGetAsync(
resolvedUriBuilder.Uri,
logfileEndpoint,
accessToken).ConfigureAwait(false).GetAwaiter().GetResult())
{
message.EnsureSuccessStatusCode();
string actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.ExportingLogOverwriteWarning, this.OutputPath);
if (AzureSession.Instance.DataStore.FileExists(this.OutputPath) && !this.Force.IsPresent && !ShouldContinue(actionWarning, Resources.Confirm))
var actionWarning = string.Format(CultureInfo.CurrentCulture, Resources.ExportingLogOverwriteWarning, OutputPath);
if (AzureSession.Instance.DataStore.FileExists(OutputPath) && !Force.IsPresent && !ShouldContinue(actionWarning, Resources.Confirm))
{
return;
}
AzureSession.Instance.DataStore.WriteFile(this.OutputPath, message.Content.ReadAsStringAsync().Result);
AzureSession.Instance.DataStore.WriteFile(OutputPath, message.Content.ReadAsStringAsync().Result);
}
}
}

private string ClusterResolve(Uri clusterUri, string accessToken, string serverName)
{
var resolveEndpoint = "/webapi/clusterResolve";
const string resolveEndpoint = "/webapi/clusterResolve";
var content = new StringContent($"ServerName={serverName}");
content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");

using (HttpResponseMessage message = AsAzureHttpClient.CallPostAsync(
using (var message = AsAzureHttpClient.CallPostAsync(
clusterUri,
resolveEndpoint,
accessToken,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ namespace Microsoft.Azure.Commands.AnalysisServices.Dataplane
[OutputType(typeof(bool))]
public class RestartAzureAnalysisServer : AzurePSCmdlet
{
private string serverName;
private string _serverName;

[Parameter(Mandatory = true, HelpMessage = "Name of the Azure Analysis Services server to restart")]
[ValidateNotNullOrEmpty]
Expand All @@ -45,22 +45,22 @@ public class RestartAzureAnalysisServer : AzurePSCmdlet

public RestartAzureAnalysisServer()
{
this.AsAzureHttpClient = new AsAzureHttpClient(() => new HttpClient());
this.TokenCacheItemProvider = new TokenCacheItemProvider();
AsAzureHttpClient = new AsAzureHttpClient(() => new HttpClient());
TokenCacheItemProvider = new TokenCacheItemProvider();

}

public RestartAzureAnalysisServer(IAsAzureHttpClient AsAzureHttpClient, ITokenCacheItemProvider TokenCacheItemProvider)
public RestartAzureAnalysisServer(IAsAzureHttpClient asAzureHttpClient, ITokenCacheItemProvider tokenCacheItemProvider)
{
this.AsAzureHttpClient = AsAzureHttpClient;
this.TokenCacheItemProvider = TokenCacheItemProvider;
AsAzureHttpClient = asAzureHttpClient;
TokenCacheItemProvider = tokenCacheItemProvider;
}

protected override IAzureContext DefaultContext
{
get
{
// Nothing to do with Azure Resource Managment context
// Nothing to do with Azure Resource Management context
return null;
}
}
Expand All @@ -82,14 +82,14 @@ protected override void BeginProcessing()
throw new PSInvalidOperationException(string.Format(Resources.NotLoggedInMessage, ""));
}

serverName = Instance;
_serverName = Instance;
Uri uriResult;

// if the user specifies the FQN of the server, then extract the servername out of that.
// if the user specifies the FQN of the server, then extract the server name out of that.
// and set the current context
if (Uri.TryCreate(Instance, UriKind.Absolute, out uriResult) && uriResult.Scheme == "asazure")
{
serverName = uriResult.PathAndQuery.Trim('/');
_serverName = uriResult.PathAndQuery.Trim('/');
if (string.Compare(AsAzureClientSession.Instance.Profile.Context.Environment.Name, uriResult.DnsSafeHost, StringComparison.InvariantCultureIgnoreCase) != 0)
{
AsAzureClientSession.Instance.SetCurrentContext(
Expand All @@ -103,21 +103,18 @@ protected override void BeginProcessing()
if (currentContext != null
&& AsAzureClientSession.AsAzureRolloutEnvironmentMapping.ContainsKey(currentContext.Environment.Name))
{
throw new PSInvalidOperationException(string.Format(Resources.InvalidServerName, serverName));
throw new PSInvalidOperationException(string.Format(Resources.InvalidServerName, _serverName));
}
}

if (this.AsAzureHttpClient == null)
if (AsAzureHttpClient == null)
{
this.AsAzureHttpClient = new AsAzureHttpClient(() =>
{
return new HttpClient();
});
AsAzureHttpClient = new AsAzureHttpClient(() => new HttpClient());
}

if (this.TokenCacheItemProvider == null)
if (TokenCacheItemProvider == null)
{
this.TokenCacheItemProvider = new TokenCacheItemProvider();
TokenCacheItemProvider = new TokenCacheItemProvider();
}
}

Expand All @@ -131,18 +128,15 @@ public override void ExecuteCmdlet()
if (ShouldProcess(Instance, Resources.RestartingAnalysisServicesServer))
{
var context = AsAzureClientSession.Instance.Profile.Context;
#if NETSTANDARD
AsAzureClientSession.Instance.Login(context, null, null);
#else
AsAzureClientSession.Instance.Login(context, null);
#endif
string accessToken = this.TokenCacheItemProvider.GetTokenFromTokenCache(AsAzureClientSession.TokenCache, context.Account.UniqueId);

Uri restartBaseUri = new Uri(string.Format("{0}{1}{2}", Uri.UriSchemeHttps, Uri.SchemeDelimiter, context.Environment.Name));
var accessToken = TokenCacheItemProvider.GetTokenFromTokenCache(AsAzureClientSession.TokenCache, context.Account.UniqueId);

var restartBaseUri = new Uri($"{Uri.UriSchemeHttps}{Uri.SchemeDelimiter}{context.Environment.Name}");

var restartEndpoint = string.Format((string)context.Environment.Endpoints[AsAzureEnvironment.AsRolloutEndpoints.RestartEndpointFormat], serverName);
var restartEndpoint = string.Format((string)context.Environment.Endpoints[AsAzureEnvironment.AsRolloutEndpoints.RestartEndpointFormat], _serverName);

using (HttpResponseMessage message = AsAzureHttpClient.CallPostAsync(
using (var message = AsAzureHttpClient.CallPostAsync(
restartBaseUri,
restartEndpoint,
accessToken).Result)
Expand Down
Loading

0 comments on commit 3471c65

Please sign in to comment.