This repository has been 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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #227 from github/feature/metrics
Collect anonymous metrics
- Loading branch information
Showing
22 changed files
with
1,023 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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.