This repository was archived by the owner on Jun 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Collect anonymous metrics #227
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
9262022
Add options page for storing user settings
shana 8a889c6
Add some debug assertions
shana 44938c4
Guard against nulls and things
shana 9752a19
Aggregate all the different settings files in one place
shana 0c62477
Generate settings classes from a json file
shana ecf259c
Make sure files are regenerated on build when the json changes
shana 67f4178
Update EULA with privacy notice
shana 1aa3dce
Add link to sample usage data
shana 728fc2c
Don't include generated files in source control
shana 1754557
Avoid religious wars
shana 51479a7
Avoid more religious wars
shana 427e315
Move things around
shana File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| using System.IO; | ||
| using Microsoft.VisualStudio.Settings; | ||
| using GitHub.Extensions; | ||
|
|
||
| namespace GitHub.Helpers | ||
| { | ||
| public class SettingsStore | ||
| { | ||
| readonly WritableSettingsStore store; | ||
| readonly string root; | ||
| public SettingsStore(WritableSettingsStore store, string root) | ||
| { | ||
| Guard.ArgumentNotNull(store, nameof(store)); | ||
| Guard.ArgumentNotNull(root, nameof(root)); | ||
| Guard.ArgumentNotEmptyString(root, nameof(root)); | ||
| this.store = store; | ||
| this.root = root; | ||
| } | ||
|
|
||
| public object Read(string property, object defaultValue) | ||
| { | ||
| return Read(null, property, defaultValue); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Read from a settings store | ||
| /// </summary> | ||
| /// <typeparam name="T"></typeparam> | ||
| /// <param name="subpath">The subcollection path (appended to the path passed to the constructor)</param> | ||
| /// <param name="property">The property name to read</param> | ||
| /// <param name="defaultValue">The default value to use in case the property doesn't exist. | ||
| /// The type of the default value will be used to figure out the proper way to read the property, so if pass null, | ||
| /// the property will be read as a string (which may or may not be what you want)</param> | ||
| /// <returns></returns> | ||
| public object Read(string subpath, string property, object defaultValue) | ||
| { | ||
| Guard.ArgumentNotNull(property, nameof(property)); | ||
| Guard.ArgumentNotEmptyString(property, nameof(property)); | ||
|
|
||
| var collection = subpath != null ? Path.Combine(root, subpath) : root; | ||
| store.CreateCollection(collection); | ||
|
|
||
| if (defaultValue is bool) | ||
| return store.GetBoolean(collection, property, (bool)defaultValue); | ||
| else if (defaultValue is int) | ||
| return store.GetInt32(collection, property, (int)defaultValue); | ||
| else if (defaultValue is uint) | ||
| return store.GetUInt32(collection, property, (uint)defaultValue); | ||
| else if (defaultValue is long) | ||
| return store.GetInt64(collection, property, (long)defaultValue); | ||
| else if (defaultValue is ulong) | ||
| return store.GetUInt64(collection, property, (ulong)defaultValue); | ||
| return store.GetString(collection, property, defaultValue?.ToString() ?? ""); | ||
| } | ||
|
|
||
| public void Write(string property, object value) | ||
| { | ||
| Write(null, property, value); | ||
| } | ||
|
|
||
| public void Write(string subpath, string property, object value) | ||
| { | ||
| Guard.ArgumentNotNull(property, nameof(property)); | ||
| Guard.ArgumentNotEmptyString(property, nameof(property)); | ||
|
|
||
| var collection = subpath != null ? Path.Combine(root, subpath) : root; | ||
| store.CreateCollection(collection); | ||
|
|
||
| if (value is bool) | ||
| store.SetBoolean(collection, property, (bool)value); | ||
| else if (value is int) | ||
| store.SetInt32(collection, property, (int)value); | ||
| else if (value is uint) | ||
| store.SetUInt32(collection, property, (uint)value); | ||
| else if (value is long) | ||
| store.SetInt64(collection, property, (long)value); | ||
| else if (value is ulong) | ||
| store.SetUInt64(collection, property, (ulong)value); | ||
| else | ||
| store.SetString(collection, property, value?.ToString() ?? ""); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <#@ template debug="false" hostspecific="true" language="C#" #> | ||
| <#@ assembly name="System.Core" #> | ||
| <#@ import namespace="System.Linq" #> | ||
| <#@ import namespace="System.Text" #> | ||
| <#@ import namespace="System.Collections.Generic" #> | ||
| <#@ import namespace="System.IO" #> | ||
| <#@ assembly name="$(PackageDir)\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll" #> | ||
| <#@ import namespace="Newtonsoft.Json.Linq" #> | ||
| <#@ output extension=".cs" #> | ||
| <# | ||
| var file = this.Host.ResolvePath(@"..\..\..\common\settings.json"); | ||
| var json = JObject.Parse(File.ReadAllText(file)); | ||
| #> | ||
| // This is an automatically generated file, based on settings.json and PackageSettingsGen.tt | ||
| /* settings.json content: | ||
| <#@ include file="..\..\..\common\settings.json" #> | ||
| */ | ||
| namespace GitHub.Settings | ||
| { | ||
| public interface IPackageSettings | ||
| { | ||
| void Save(); | ||
| <# | ||
| foreach (var j in json["settings"].Children()) { | ||
| #> | ||
| <#= j["type"] #> <#= j["name"] #> { get; set; } | ||
| <# | ||
| } | ||
| #> | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| using GitHub.Settings; | ||
| using GitHub.VisualStudio.UI; | ||
| using Microsoft.VisualStudio.Shell; | ||
| using System; | ||
| using System.ComponentModel; | ||
| using System.Runtime.InteropServices; | ||
| using System.Windows; | ||
|
|
||
| namespace GitHub.VisualStudio | ||
| { | ||
| [ClassInterface(ClassInterfaceType.AutoDual)] | ||
| [ComVisible(true)] | ||
| [Guid("68C87C7B-0212-4256-BB6D-6A6BB847A3A7")] | ||
| public class OptionsPage : UIElementDialogPage | ||
| { | ||
| OptionsControl child; | ||
| IPackageSettings packageSettings; | ||
|
|
||
| protected override UIElement Child | ||
| { | ||
| get { return child ?? (child = new OptionsControl()); } | ||
| } | ||
|
|
||
| protected override void OnActivate(CancelEventArgs e) | ||
| { | ||
| base.OnActivate(e); | ||
| packageSettings = Services.DefaultExportProvider.GetExportedValue<IPackageSettings>(); | ||
| LoadSettings(); | ||
| } | ||
|
|
||
| void LoadSettings() | ||
| { | ||
| child.CollectMetrics = packageSettings.CollectMetrics; | ||
| } | ||
|
|
||
| void SaveSettings() | ||
| { | ||
| packageSettings.CollectMetrics = child.CollectMetrics; | ||
| packageSettings.Save(); | ||
| } | ||
|
|
||
| protected override void OnApply(PageApplyEventArgs args) | ||
| { | ||
| if (args.ApplyBehavior == ApplyKind.Apply) | ||
| { | ||
| SaveSettings(); | ||
| } | ||
|
|
||
| base.OnApply(args); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed we're not using
NullGuardfor this project so we should probably validate that these arguments are not null here. Otherwise, we could get aNullReferenceExceptionon line 34.