Skip to content

Clutest1 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ internal static PSResourceObject ToPSResourceObject(this Resource<JToken> resour
psObject.SubscriptionId = string.IsNullOrEmpty(resource.Id) ? null : ResourceIdUtility.GetSubscriptionId(resource.Id);
psObject.Tags = TagsHelper.GetTagsHashtables(resource.Tags);


var objectProperties = objectDefinition.Where(kvp => kvp.Value != null).SelectManyArray(kvp => new[] { kvp.Key, kvp.Value });

for(int i=0; i< objectProperties.Length; i+=2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,7 @@ private bool TryGetTenantSubscription(IAccessToken accessToken,
if (subscriptions.Any())
{
WriteWarningMessage(string.Format(
"TenantId '{0}' contains more than one subscription. First one will be selected for further use. " +
"To select another subscription, use Set-AzureRmContext.",
Resources.TooManyTenants,
tenantId));
}
subscriptionFromServer = subscriptions.First();
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@
<data name="TenantIdNotFound" xml:space="preserve">
<value>Unable to find tenant '{0}'.</value>
</data>
<data name="TooManyTenants" xml:space="preserve">
<value>TenantId '{0}' contains more than one subscription. First one will be selected for further use. To select another subscription, use 'context set' cmdlet.</value>
</data>
<data name="TypeNotAccessToken" xml:space="preserve">
<value>To create an access token credential, you must provide an access token account.</value>
</data>
Expand Down
66 changes: 65 additions & 1 deletion src/CLU/Microsoft.CLU/CommandBinder/CmdletBinderAndCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using Microsoft.CLU.Help;
using Microsoft.CLU.Metadata;
using Microsoft.CLU.Common.Properties;
using Microsoft.ApplicationInsights;
using System.Management.Automation.Host;

namespace Microsoft.CLU.CommandBinder
{
Expand Down Expand Up @@ -63,6 +65,7 @@ public CmdletBinderAndCommand(ConfigurationDictionary commandConfiguration, ICom
_runtime = runtime;
_commandConfiguration = commandConfiguration;
_staticParameterBindInProgress = true;
InitTelemetry();
InitCmdlet(cmdletValue.LoadCmdlet(), cmdletValue.PackageAssembly.FullPath);
Action<Type, uint, string> discriminatorBindFinished = (Type cmdletType, uint seekBackOffset, string fullPath) =>
{
Expand All @@ -83,6 +86,7 @@ public CmdletBinderAndCommand(ConfigurationDictionary commandConfiguration, ICom
Debug.Assert(runtime != null);
_runtime = runtime;
_commandConfiguration = commandConfiguration;
InitTelemetry();
Action<Type, uint, string> discriminatorBindFinished = (Type cmdletType, uint seekBackOffset, string fullPath) =>
{
_staticParameterBindInProgress = true;
Expand Down Expand Up @@ -253,12 +257,18 @@ public void Invoke()
}
catch (CmdletTerminateException terminateException)
{
_telemetryClient.TrackException(terminateException, GetErrorTelemetryProperties());
_cmdlet.CommandRuntime.WriteError(terminateException.ErrorRecord);
}
catch (Exception exception)
{
_telemetryClient.TrackException(exception, GetErrorTelemetryProperties());
_cmdlet.CommandRuntime.WriteError(new ErrorRecord(exception, "", ErrorCategory.InvalidResult, _cmdlet));
}
finally
{
_telemetryClient.Flush();
}
}

/// <summary>
Expand Down Expand Up @@ -341,6 +351,56 @@ private void InitCmdlet(Type cmdletType, string assemblyLocation)
_staticParametersBindHandler = new BindHandler(_cmdlet, _staticParametersBindState);
}

private IDictionary<string, string> GetErrorTelemetryProperties()
{
Dictionary<string, string> eventProperties = new Dictionary<string, string>();
eventProperties.Add("IsSuccess", "False");
if (_cmdlet != null)
{
eventProperties.Add("ModuleName", _cmdlet.GetType().GetTypeInfo().Assembly.GetName().Name);
eventProperties.Add("ModuleVersion", _cmdlet.GetType().GetTypeInfo().Assembly.GetName().Version.ToString());
var cmdletAliasAttribute = _cmdlet.GetType().GetTypeInfo().GetCustomAttributes()
.FirstOrDefault((at) => at.GetType().FullName.Equals("System.Management.Automation.CliCommandAliasAttribute"));

if (cmdletAliasAttribute != null)
{
var attrType = cmdletAliasAttribute.GetType();
eventProperties.Add("CommandName", "az " + (string)attrType.GetProperty("CommandName").GetValue(cmdletAliasAttribute));
}
}
var _cluHost = _runtime as CLUHost;
if (_cluHost != null)
{
eventProperties.Add("HostVersion", _cluHost.Version.ToString());
eventProperties.Add("InputFromPipeline", _cluHost.IsInputRedirected.ToString());
eventProperties.Add("OutputToPipeline", _cluHost.IsOutputRedirected.ToString());
}
if (CLUEnvironment.Platform.IsMacOSX)
{
eventProperties.Add("OS", "MacOS");
}
else if (CLUEnvironment.Platform.IsUnix)
{
eventProperties.Add("OS", "Unix");
}
else
{
eventProperties.Add("OS", "Windows");
}
return eventProperties;
}

/// <summary>
/// Initializes TelemetryClient using default channel.
/// </summary>
private void InitTelemetry()
{
_telemetryClient = new TelemetryClient
{
InstrumentationKey = "963c4276-ec20-48ad-b9ab-3968e9da5578"
};
}

/// <summary>
/// Bind the dynamic parameters if cmdlet instance supports dynamic parameters.
/// </summary>
Expand Down Expand Up @@ -533,7 +593,11 @@ private static bool MatchesParameterSet(ParameterMetadata parameter, string para
return parameterSet == null || parameter.ParameterSets.ContainsKey(parameterSet);
}

#region Private fields
#region Private fields
/// <summary>
/// Telemetry client.
/// </summary>
private TelemetryClient _telemetryClient;

/// <summary>
/// Configuration of the current command.
Expand Down
3 changes: 2 additions & 1 deletion src/CLU/Microsoft.CLU/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
"System.IO": "4.0.11-beta-23516",
"System.Reflection": "4.1.0-beta-23516",
"System.Reflection.TypeExtensions": "4.1.0-beta-23516",
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516"
"System.Runtime.Serialization.Primitives": "4.1.0-beta-23516",
"Microsoft.ApplicationInsights": "2.0.0-beta3"
},
"contentExclude": [
"*.xproj*"
Expand Down