From 0696def44c057772ebf5169278323e70b8618a06 Mon Sep 17 00:00:00 2001 From: Tyler Hughes Date: Sat, 17 Sep 2016 21:24:00 -0500 Subject: [PATCH] Added ability for user to opt-out of sending telemetry --- LigerShark.Templates/GoogleAnalyticsWizard.cs | 1 + .../LigerShark.Templates.csproj | 7 +++ .../xUnitTestProject/UnitTestProject.xproj | 2 +- TemplatePack/SettingsForm.Designer.cs | 48 ++++++++++++++-- TemplatePack/SettingsForm.cs | 55 +++++++++++++++++++ 5 files changed, 108 insertions(+), 5 deletions(-) diff --git a/LigerShark.Templates/GoogleAnalyticsWizard.cs b/LigerShark.Templates/GoogleAnalyticsWizard.cs index 0997e83e..3f11847e 100644 --- a/LigerShark.Templates/GoogleAnalyticsWizard.cs +++ b/LigerShark.Templates/GoogleAnalyticsWizard.cs @@ -73,6 +73,7 @@ private void TrackTemplate(string templateID, string templateName, string templa // Get the file path where the settings are being stored. var rootDir = Environment.ExpandEnvironmentVariables(@"%localappdata%\LigerShark\SideWaffle\"); var filePath = Path.Combine(rootDir, "SideWaffle-Settings.json"); + bool telemetry = SettingsStore.ReadJsonFile(filePath).SendTelemetry; if (telemetry) diff --git a/LigerShark.Templates/LigerShark.Templates.csproj b/LigerShark.Templates/LigerShark.Templates.csproj index acb3045a..d6484349 100644 --- a/LigerShark.Templates/LigerShark.Templates.csproj +++ b/LigerShark.Templates/LigerShark.Templates.csproj @@ -107,7 +107,14 @@ + + App.xaml + + + MSBuild:Compile + Designer + Designer MSBuild:Compile diff --git a/Project Templates/xUnitTestProject/UnitTestProject.xproj b/Project Templates/xUnitTestProject/UnitTestProject.xproj index 8ce15361..6b7d53a7 100644 --- a/Project Templates/xUnitTestProject/UnitTestProject.xproj +++ b/Project Templates/xUnitTestProject/UnitTestProject.xproj @@ -9,7 +9,7 @@ 650a5a85-5956-491e-9312-5e25a27d1108 UnitTestProject ..\..\artifacts\obj\$(MSBuildProjectName) - ..\..\artifacts\bin\$(MSBuildProjectName)\ + .\bin\ 2.0 diff --git a/TemplatePack/SettingsForm.Designer.cs b/TemplatePack/SettingsForm.Designer.cs index 2ed41513..af199877 100644 --- a/TemplatePack/SettingsForm.Designer.cs +++ b/TemplatePack/SettingsForm.Designer.cs @@ -61,6 +61,9 @@ private void InitializeComponent() this.onceAMonthRadioBtn = new System.Windows.Forms.RadioButton(); this.alwaysRadioBtn = new System.Windows.Forms.RadioButton(); this.onceAWeekRadioBtn = new System.Windows.Forms.RadioButton(); + this.label10 = new System.Windows.Forms.Label(); + this.telemetryCheckBox = new System.Windows.Forms.CheckBox(); + this.label9 = new System.Windows.Forms.Label(); ((System.ComponentModel.ISupportInitialize)(this.LoadingImage)).BeginInit(); this.scheduleGroupBox.SuspendLayout(); this.SuspendLayout(); @@ -237,7 +240,7 @@ private void InitializeComponent() // // OkBtn // - this.OkBtn.Location = new System.Drawing.Point(576, 515); + this.OkBtn.Location = new System.Drawing.Point(574, 592); this.OkBtn.Name = "OkBtn"; this.OkBtn.Size = new System.Drawing.Size(75, 25); this.OkBtn.TabIndex = 18; @@ -247,7 +250,7 @@ private void InitializeComponent() // // cancelBtn // - this.cancelBtn.Location = new System.Drawing.Point(657, 515); + this.cancelBtn.Location = new System.Drawing.Point(657, 592); this.cancelBtn.Name = "cancelBtn"; this.cancelBtn.Size = new System.Drawing.Size(75, 25); this.cancelBtn.TabIndex = 19; @@ -313,7 +316,7 @@ private void InitializeComponent() // ResetDefaultsBtn // this.ResetDefaultsBtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); - this.ResetDefaultsBtn.Location = new System.Drawing.Point(416, 515); + this.ResetDefaultsBtn.Location = new System.Drawing.Point(414, 592); this.ResetDefaultsBtn.Name = "ResetDefaultsBtn"; this.ResetDefaultsBtn.Size = new System.Drawing.Size(154, 25); this.ResetDefaultsBtn.TabIndex = 209; @@ -394,12 +397,46 @@ private void InitializeComponent() this.onceAWeekRadioBtn.TabStop = true; this.onceAWeekRadioBtn.Text = "Once A Week"; this.onceAWeekRadioBtn.UseVisualStyleBackColor = true; + // + // label10 + // + this.label10.AutoSize = true; + this.label10.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label10.Location = new System.Drawing.Point(29, 503); + this.label10.Name = "label10"; + this.label10.Size = new System.Drawing.Size(123, 16); + this.label10.TabIndex = 212; + this.label10.Text = "Telemetry Opt-In"; + // + // telemetryCheckBox + // + this.telemetryCheckBox.AutoSize = true; + this.telemetryCheckBox.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F); + this.telemetryCheckBox.Location = new System.Drawing.Point(32, 522); + this.telemetryCheckBox.Name = "telemetryCheckBox"; + this.telemetryCheckBox.Size = new System.Drawing.Size(260, 20); + this.telemetryCheckBox.TabIndex = 213; + this.telemetryCheckBox.Text = "Send feature usage data to SideWaffle.\r\n"; + this.telemetryCheckBox.UseVisualStyleBackColor = true; + // + // label9 + // + this.label9.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.label9.Location = new System.Drawing.Point(29, 545); + this.label9.Name = "label9"; + this.label9.Size = new System.Drawing.Size(552, 37); + this.label9.TabIndex = 214; + this.label9.Text = "Feature usage data includes information about what SideWaffle templates you use. " + + "It helps us prioritize which templates to keep up to-date."; // // SettingsForm // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.ClientSize = new System.Drawing.Size(744, 552); + this.ClientSize = new System.Drawing.Size(744, 629); + this.Controls.Add(this.label9); + this.Controls.Add(this.telemetryCheckBox); + this.Controls.Add(this.label10); this.Controls.Add(this.scheduleGroupBox); this.Controls.Add(this.ResetDefaultsBtn); this.Controls.Add(this.deleteBtn); @@ -468,5 +505,8 @@ private void InitializeComponent() private System.Windows.Forms.RadioButton alwaysRadioBtn; private System.Windows.Forms.RadioButton onceAWeekRadioBtn; private System.Windows.Forms.RadioButton neverRadioBtn; + private System.Windows.Forms.Label label10; + private System.Windows.Forms.CheckBox telemetryCheckBox; + private System.Windows.Forms.Label label9; } } \ No newline at end of file diff --git a/TemplatePack/SettingsForm.cs b/TemplatePack/SettingsForm.cs index 0525e0ac..1ae20dc8 100644 --- a/TemplatePack/SettingsForm.cs +++ b/TemplatePack/SettingsForm.cs @@ -3,8 +3,10 @@ using LigerShark.Templates.DynamicBuilder; using Microsoft.VisualStudio.Shell; using Microsoft.VisualStudio.Shell.Interop; +using Newtonsoft.Json; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text.RegularExpressions; using System.Windows.Forms; @@ -20,6 +22,8 @@ public partial class SettingsForm : Form private bool buildingTemplates = false; private bool newSourceAdded = false; private int _numSources; + private string swRootDir; + private string swFilePath; public SettingsForm() { @@ -43,6 +47,46 @@ public SettingsForm() onceAWeekRadioBtn.Tag = UpdateFrequency.OnceAWeek; onceAMonthRadioBtn.Tag = UpdateFrequency.OnceAMonth; neverRadioBtn.Tag = UpdateFrequency.Never; + + // Load the Google Analytics settings from it's JSON source + // telemetryCheckBox + swRootDir = Environment.ExpandEnvironmentVariables(@"%localappdata%\LigerShark\SideWaffle\"); + swFilePath = Path.Combine(swRootDir, "SideWaffle-Settings.json"); + + if (!File.Exists(swFilePath)) + { + try + { + var telemetryDefaults = new SettingsStore { SendTelemetry = true }; + var json = JsonConvert.SerializeObject(telemetryDefaults, Formatting.Indented); + File.WriteAllText(swFilePath, json); + + telemetryCheckBox.Checked = true; + } + catch (IOException ioe) + { + MessageBox.Show(ioe.Message, "Error Trying to Create Default Telemetry JSON File"); + } + } + else + { + try + { + var telemetry = SettingsStore.ReadJsonFile(swFilePath).SendTelemetry; + + if (telemetry) + { + telemetryCheckBox.Checked = true; + } + } + catch (Exception ex) + { + MessageBox.Show(ex.Message, "Error Trying to Read From Telemetry JSON File"); + } + + } + + } private void editBtn_click(object sender, EventArgs e) @@ -247,6 +291,17 @@ private async void OkBtn_Click(object sender, EventArgs e) // Here is where the .json file needs to be saved before calling ProcessTemplates templateBuilder.WriteJsonTemplateSettings(templateSettings); + // Update the JSON file on the Google Analytics setting. + var telemetry = telemetryCheckBox.Checked; + var data = new SettingsStore { SendTelemetry = telemetry }; + var json = JsonConvert.SerializeObject(data, Formatting.Indented); + if (!Directory.Exists(swRootDir)) + { + Directory.CreateDirectory(swRootDir); + } + File.WriteAllText(swFilePath, json); + + // Rebuild all templates before notifying the user await startRebuildingTemplates();