Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Merge pull request #227 from github/feature/metrics
Browse files Browse the repository at this point in the history
Collect anonymous metrics
  • Loading branch information
haacked committed Feb 25, 2016
2 parents a4673c1 + 427e315 commit 57bf0f7
Show file tree
Hide file tree
Showing 22 changed files with 1,023 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,4 @@ WiX.Toolset.DummyFile.txt
nunit-UnitTests.xml
nunit-TrackingCollectionTests.xml
GitHubVS.sln.DotSettings
**/generated/*.cs
Binary file added lib/Microsoft.TextTemplating.Build.Tasks.dll
Binary file not shown.
535 changes: 535 additions & 0 deletions lib/Microsoft.TextTemplating.targets

Large diffs are not rendered by default.

Binary file not shown.
20 changes: 20 additions & 0 deletions src/GitHub.Exports/GitHub.Exports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,17 @@
<None Include="..\..\script\Key.snk" Condition="$(Buildtype) == 'Internal'">
<Link>Key.snk</Link>
</None>
<None Include="..\common\settings.json">
<Link>Properties\settings.json</Link>
</None>
<Compile Include="Collections\ICopyable.cs" />
<Compile Include="ExceptionExtensions.cs" />
<Compile Include="Extensions\VSExtensions.cs" />
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Helpers\INotifyPropertySource.cs" />
<Compile Include="Extensions\PropertyNotifierExtensions.cs" />
<Compile Include="Extensions\SimpleRepositoryModelExtensions.cs" />
<Compile Include="Helpers\SettingsStore.cs" />
<Compile Include="Info\ApplicationInfo.cs" />
<Compile Include="Models\IAccount.cs" />
<Compile Include="Models\IConnectionManager.cs" />
Expand Down Expand Up @@ -134,6 +138,11 @@
<ItemGroup>
<Compile Include="Authentication\AuthenticationResultExtensions.cs" />
<Compile Include="Extensions\ServiceProviderExtensions.cs" />
<Compile Include="Settings\generated\IPackageSettings.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>IPackageSettings.tt</DependentUpon>
</Compile>
<Compile Include="ViewModels\IServiceProviderAware.cs" />
<Compile Include="UI\IView.cs" />
<Compile Include="UI\Octicon.cs" />
Expand Down Expand Up @@ -178,7 +187,18 @@
<Private>True</Private>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Content Include="Settings\generated\IPackageSettings.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>IPackageSettings.cs</LastGenOutput>
</Content>
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\src\common\t4.targets" />
<Import Project="$(SolutionDir)\lib\Microsoft.TextTemplating.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
83 changes: 83 additions & 0 deletions src/GitHub.Exports/Helpers/SettingsStore.cs
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() ?? "");
}
}
}
31 changes: 31 additions & 0 deletions src/GitHub.Exports/Settings/generated/IPackageSettings.tt
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; }
<#
}
#>
}
}
36 changes: 33 additions & 3 deletions src/GitHub.VisualStudio/GitHub.VisualStudio.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,21 @@
<Compile Include="Base\TeamExplorerNavigationItemBase.cs" />
<Compile Include="Base\TeamExplorerSectionBase.cs" />
<Compile Include="Helpers\Browser.cs" />
<Compile Include="Helpers\Colors.cs" />
<Compile Include="Helpers\Constants.cs" />
<Compile Include="Settings\Colors.cs" />
<Compile Include="Settings\Constants.cs" />
<Compile Include="Services\ConnectionManager.cs" />
<Compile Include="Settings\OptionsPage.cs">
<SubType>Component</SubType>
</Compile>
<Compile Include="Services\Program.cs" />
<Compile Include="Services\SharedResources.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Settings\PackageSettings.cs" />
<Compile Include="Settings\generated\PackageSettings.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>PackageSettings.tt</DependentUpon>
</Compile>
<Compile Include="Settings\Settings.cs" />
<Compile Include="Base\PackageBase.cs" />
<Compile Include="Resources.Designer.cs">
<AutoGen>True</AutoGen>
Expand All @@ -273,6 +282,9 @@
<Compile Include="Base\EnsureLoggedInSection.cs" />
<Compile Include="UI\DrawingExtensions.cs" />
<Compile Include="UI\GitHubPane.cs" />
<Compile Include="UI\Settings\OptionsControl.xaml.cs">
<DependentUpon>OptionsControl.xaml</DependentUpon>
</Compile>
<Compile Include="UI\Views\Controls\RepositoryCloneControl.xaml.cs">
<DependentUpon>RepositoryCloneControl.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -333,9 +345,16 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<IncludeInVSIX>true</IncludeInVSIX>
</Content>
<Content Include="Settings\generated\PackageSettings.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<CustomToolNamespace>GitHub.VisualStudio.Settings</CustomToolNamespace>
</Content>
<None Include="packages.config">
<SubType>Designer</SubType>
</None>
<None Include="..\common\settings.json">
<Link>Properties\settings.json</Link>
</None>
<None Include="source.extension.vsixmanifest">
<SubType>Designer</SubType>
</None>
Expand Down Expand Up @@ -410,6 +429,11 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Page Include="UI\Settings\OptionsControl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
<CustomToolNamespace>GitHub.VisualStudio.UI</CustomToolNamespace>
</Page>
<Page Include="UI\Views\Controls\ActionLinkButton.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -578,12 +602,18 @@
<IncludeOutputGroupsInVSIXLocalOnly>DebugSymbolsProjectOutputGroup;</IncludeOutputGroupsInVSIXLocalOnly>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{508349B6-6B84-4DF5-91F0-309BEEBAD82D}" />
</ItemGroup>
<PropertyGroup>
<UseCodebase>true</UseCodebase>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\VSSDK\Microsoft.VsSDK.targets" Condition="'$(VSToolsPath)' != ''" />
<Import Project="packaging.targets" />
<!-- For regenerating templates on build -->
<Import Project="$(SolutionDir)\src\common\t4.targets" />
<Import Project="$(SolutionDir)\lib\Microsoft.TextTemplating.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.VisualStudio/GitHubPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ namespace GitHub.VisualStudio
//[ProvideAutoLoad(UIContextGuids.NoSolution)]
[ProvideAutoLoad("11B8E6D7-C08B-4385-B321-321078CDD1F8")]
[ProvideToolWindow(typeof(GitHubPane), Orientation = ToolWindowOrientation.Right, Style = VsDockStyle.Tabbed, Window = EnvDTE.Constants.vsWindowKindSolutionExplorer)]
[ProvideOptionPage(typeof(OptionsPage), "GitHub for Visual Studio", "General", 0, 0, supportsAutomation: true)]
public class GitHubPackage : PackageBase
{
public GitHubPackage()
Expand Down
23 changes: 21 additions & 2 deletions src/GitHub.VisualStudio/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ IF YOU DO NOT AGREE TO ALL OF THE TERMS OF THIS EULA, DO NOT INSTALL, USE OR COP
• You must agree to all of the terms of this EULA to use this Software.
• If so, you may use the Software for free and for any lawful purpose.
• This Software automatically communicates with GitHub servers
for three reasons: (1) to receive and install updates; (2) to send error
reports; and (3) to send anonymized usage information. You can view
for two reasons: (1) to send error reports; and
(2) to send anonymized usage information. You can view
sample data to see what information is sent, and you may opt out of
sending the anonymized usage data.
• This Software is provided "as-is" with no warranties, and you agree
Expand Down Expand Up @@ -42,6 +42,25 @@ This EULA entitles you to install as many copies of the Software as you want, an
4. You may not remove or alter any proprietary notices or marks on
the Software.

PRIVACY NOTICES

The Software automatically communicates with GitHub servers for two purposes: (1) sending error reports; and (2) sending anonymized usage data so we may improve the Software. If you would like to learn more about the specific information we send, please visit https://visualstudio.github.com/samples.html. You may opt out of sending the anonymized usage data, but if you do not want the Software to send error reports, you must uninstall the Software.

1. ERROR REPORTS. In order to help us improve the Software, when the
Software encounters certain errors, it will automatically send some
information to GitHub about the error (as described at the URL
above).
This feature may not be disabled. If you do not want to send error
reports to GitHub, you must uninstall the Software.

2. ANONYMIZED USAGE DATA. GitHub collects anonymized data about
your usage of the Software to help us make it more awesome.
Approximately once a day the Software sends such data
(as described in more detail at the URL above) to GitHub's servers.
If you do not want to send anonymized usage data to GitHub,
you may opt out by changing your settings in the
Visual Studio Options dialog under the GitHub section.

OPEN-SOURCE NOTICES

Certain components of the Software may be subject to open-source software licenses ("Open-Source Components"), which means any software license approved as open-source licenses by the Open Source Initiative or any substantially similar licenses, including without limitation any license that, as a condition of distribution of the software licensed under such license, requires that the distributor make the software available in source code format. If you would like to see copies of the licenses applicable to the Open-Source Components, please visit https://visualstudio.github.com/credits.html.
Expand Down
18 changes: 18 additions & 0 deletions src/GitHub.VisualStudio/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/GitHub.VisualStudio/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,10 @@
<data name="Error_FailedToCopyToClipboard" xml:space="preserve">
<value>Could not copy to the clipboard. Please try again.</value>
</data>
<data name="Options_MetricsLabel" xml:space="preserve">
<value>Help us improve by sending anonymous usage data</value>
</data>
<data name="Options_PrivacyTitle" xml:space="preserve">
<value>Privacy</value>
</data>
</root>
52 changes: 52 additions & 0 deletions src/GitHub.VisualStudio/Settings/OptionsPage.cs
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);
}
}
}
Loading

0 comments on commit 57bf0f7

Please sign in to comment.