Skip to content

Commit

Permalink
Update Send-Feedback to open survey page
Browse files Browse the repository at this point in the history
  • Loading branch information
msJinLei committed Feb 20, 2020
1 parent e0950e9 commit 30dba8b
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 42 deletions.
54 changes: 27 additions & 27 deletions src/Accounts/Accounts.Test/SendFeedbackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,34 @@ public void SendFeedbackFailsInNonInteractive()
});
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void CanSerializeSimpleFeedbackPayloadIntoProperForm()
{
var payload = new PSAzureFeedback
{
ModuleName = "Module",
ModuleVersion = "1.0.0",
SubscriptionId = Guid.NewGuid().ToString(),
TenantId = Guid.NewGuid().ToString(),
Environment = "AzureCloud",
Recommendation = 10,
PositiveComments = "Positive",
NegativeComments = "Negative",
Email = "[email protected]"
};
//[Fact]
//[Trait(Category.AcceptanceType, Category.CheckIn)]
//public void CanSerializeSimpleFeedbackPayloadIntoProperForm()
//{
// var payload = new PSAzureFeedback
// {
// ModuleName = "Module",
// ModuleVersion = "1.0.0",
// SubscriptionId = Guid.NewGuid().ToString(),
// TenantId = Guid.NewGuid().ToString(),
// Environment = "AzureCloud",
// Recommendation = 10,
// PositiveComments = "Positive",
// NegativeComments = "Negative",
// Email = "[email protected]"
// };

var serializedPayload = MetricHelper.SerializeCustomEventPayload(payload);
// var serializedPayload = MetricHelper.SerializeCustomEventPayload(payload);

Assert.Equal(payload.ModuleName, serializedPayload["moduleName"]);
Assert.Equal(payload.ModuleVersion, serializedPayload["moduleVersion"]);
Assert.Equal(payload.SubscriptionId.ToString(), serializedPayload["subscriptionId"]);
Assert.Equal(payload.TenantId.ToString(), serializedPayload["tenantId"]);
Assert.Equal(payload.Environment, serializedPayload["environment"]);
Assert.Equal(payload.Recommendation.ToString(), serializedPayload["recommendation"]);
Assert.Equal(payload.PositiveComments, serializedPayload["positiveComments"]);
Assert.Equal(payload.NegativeComments, serializedPayload["negativeComments"]);
Assert.Equal(payload.Email, serializedPayload["email"]);
}
// Assert.Equal(payload.ModuleName, serializedPayload["moduleName"]);
// Assert.Equal(payload.ModuleVersion, serializedPayload["moduleVersion"]);
// Assert.Equal(payload.SubscriptionId.ToString(), serializedPayload["subscriptionId"]);
// Assert.Equal(payload.TenantId.ToString(), serializedPayload["tenantId"]);
// Assert.Equal(payload.Environment, serializedPayload["environment"]);
// Assert.Equal(payload.Recommendation.ToString(), serializedPayload["recommendation"]);
// Assert.Equal(payload.PositiveComments, serializedPayload["positiveComments"]);
// Assert.Equal(payload.NegativeComments, serializedPayload["negativeComments"]);
// Assert.Equal(payload.Email, serializedPayload["email"]);
//}
}
}
3 changes: 2 additions & 1 deletion src/Accounts/Accounts/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@

## Version 1.7.2
* Added SubscriptionId, TenantId, and execution time into data of client side telemetry
* Display Azure PowerShell survey url to Resolve-Error.
* Display AzurePowershell survey url to Resolve-Error.
* Open AzurePowershell survey page in Send-Feedback.

## Version 1.7.1
* Disable context auto saving when AzureRmContext.json not available
Expand Down
2 changes: 2 additions & 0 deletions src/Accounts/Accounts/Common/AzureProfileConstants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,7 @@ public static class AzureProfileConstants
public const string AzureSurveyUrl = "https://aka.ms/azpssurvey";

public static readonly string AzurePowerShellFeedbackMessage = string.Format(Resources.AzurePowerShellFeedback, AzureProfileConstants.AzureSurveyUrl);

public static readonly string AzurePowerShellFeedbackQuestion = string.Format(Resources.SendFeedbackOpenLinkAutomatically, AzureProfileConstants.AzureSurveyUrl);
}
}
70 changes: 57 additions & 13 deletions src/Accounts/Accounts/Feedback/SendFeedback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Profile.Models;
using Microsoft.Azure.Commands.Profile.Common;
using Microsoft.Azure.Commands.Profile.Properties;
using Microsoft.Azure.Commands.ResourceManager.Common;
using Microsoft.WindowsAzure.Commands.Common;
using System;
using System.Linq;
using System.Diagnostics;
using System.Management.Automation;
using System.Runtime.InteropServices;

namespace Microsoft.Azure.Commands.Profile
{
Expand All @@ -37,6 +37,7 @@ protected override void BeginProcessing()

public override void ExecuteCmdlet()
{
/*
this.WriteQuestion(Resources.SendFeedbackRecommendationQuestion);
int recommendation;
if (!int.TryParse(this.Host.UI.ReadLine(), out recommendation) || recommendation < 0 || recommendation > 10)
Expand All @@ -60,27 +61,70 @@ public override void ExecuteCmdlet()
var feedbackPayload = new PSAzureFeedback
{
ModuleName = this.ModuleName,
ModuleVersion = this.ModuleVersion,
SubscriptionId = loggedIn ? this.DefaultContext.Subscription.Id : Guid.Empty.ToString(),
TenantId = loggedIn ? this.DefaultContext.Tenant.Id : Guid.Empty.ToString(),
Environment = loggedIn ? this.DefaultContext.Environment.Name : null,
Recommendation = recommendation,
PositiveComments = positiveComments,
NegativeComments = negativeComments,
ModuleName = this.ModuleName,
ModuleVersion = this.ModuleVersion,
SubscriptionId = loggedIn ? this.DefaultContext.Subscription.Id : Guid.Empty.ToString(),
TenantId = loggedIn ? this.DefaultContext.Tenant.Id : Guid.Empty.ToString(),
Environment = loggedIn ? this.DefaultContext.Environment.Name : null,
Recommendation = recommendation,
PositiveComments = positiveComments,
NegativeComments = negativeComments,
Email = email
};
this.Host.UI.WriteLine();

*/
// Log the event with force since the user specifically issued this command to provide feedback.

this._metricHelper.LogCustomEvent(_eventName, feedbackPayload, true /* force */);
//this._metricHelper.LogCustomEvent(_eventName, feedbackPayload, true /* force */);

this.WriteQuestion(AzureProfileConstants.AzurePowerShellFeedbackQuestion);
var yesOrNo = this.Host.UI.ReadLine();
if(0 == String.Compare(yesOrNo, "yes", true) || 0 == String.Compare(yesOrNo, "y", true))
{
if (OpenBrowser(AzureProfileConstants.AzureSurveyUrl))
{
this.Host.UI.WriteLine();
return;
}
this.WriteWarning(Resources.DefaultBrowserOpenFailure);
}
this.Host.UI.WriteLine(this.Host.UI.RawUI.ForegroundColor, this.Host.UI.RawUI.BackgroundColor, $"{Environment.NewLine}{AzureProfileConstants.AzurePowerShellFeedbackMessage}{Environment.NewLine}");
}

private void WriteQuestion(string question)
{
this.Host.UI.WriteLine(ConsoleColor.Cyan, this.Host.UI.RawUI.BackgroundColor, $"{Environment.NewLine}{question}{Environment.NewLine}");
}

private bool OpenBrowser(string url)
{
try
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
url = url.Replace("&", "^&");
Process.Start(new ProcessStartInfo("cmd", $"/c start {url}") { CreateNoWindow = true });
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
Process.Start("xdg-open", url);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
Process.Start("open", url);
}
else
{
throw new PlatformNotSupportedException(RuntimeInformation.OSDescription);
}
}
catch
{
return false;
}

return true;
}
}
}
20 changes: 19 additions & 1 deletion src/Accounts/Accounts/Properties/Resources.Designer.cs

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

6 changes: 6 additions & 0 deletions src/Accounts/Accounts/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -474,4 +474,10 @@
<data name="AzurePowerShellFeedback" xml:space="preserve">
<value>The Azure PowerShell team is listening, please let us know how we are doing: {0}.</value>
</data>
<data name="SendFeedbackOpenLinkAutomatically" xml:space="preserve">
<value>Want to provide feedback about Azure PowerShell? Take a quick survey and let us know how we are doing: {0}. (Y/N)</value>
</data>
<data name="DefaultBrowserOpenFailure" xml:space="preserve">
<value>Fail to open the default browser.</value>
</data>
</root>

0 comments on commit 30dba8b

Please sign in to comment.