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

Commit f741b66

Browse files
authored
Merge 78ad9f4 into 0405986
2 parents 0405986 + 78ad9f4 commit f741b66

File tree

21 files changed

+1228
-403
lines changed

21 files changed

+1228
-403
lines changed

src/GitHub.Api/SimpleApiClient.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async Task<Repository> GetRepositoryInternal()
7272
if (repo != null)
7373
{
7474
hasWiki = await HasWikiInternal(repo);
75-
isEnterprise = await IsEnterpriseInternal();
75+
isEnterprise = isEnterprise ?? await IsEnterpriseInternal();
7676
repositoryCache = repo;
7777
}
7878
owner = ownerLogin;
@@ -99,9 +99,14 @@ public bool HasWiki()
9999
return hasWiki.HasValue && hasWiki.Value;
100100
}
101101

102-
public bool IsEnterprise()
102+
public async Task<bool> IsEnterprise()
103103
{
104-
return isEnterprise.HasValue && isEnterprise.Value;
104+
if (!isEnterprise.HasValue)
105+
{
106+
isEnterprise = await IsEnterpriseInternal();
107+
}
108+
109+
return isEnterprise ?? false;
105110
}
106111

107112
async Task<bool> HasWikiInternal(Repository repo)

src/GitHub.App/Api/ApiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static string GetMachineNameSafe()
157157
}
158158
catch (Exception e)
159159
{
160-
log.Information(e, "Failed to retrieve host name using `DNS.GetHostName`");
160+
log.Warning(e, "Failed to retrieve host name using `DNS.GetHostName`");
161161
try
162162
{
163163
return Environment.MachineName;

src/GitHub.App/Services/TeamExplorerContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void Refresh()
6565
{
6666
// Ignore when ActiveRepositories is empty and solution hasn't changed.
6767
// https://github.com/github/VisualStudio/issues/1421
68-
log.Information("Ignoring no ActiveRepository when solution hasn't changed");
68+
log.Debug("Ignoring no ActiveRepository when solution hasn't changed");
6969
}
7070
else
7171
{
@@ -76,22 +76,22 @@ void Refresh()
7676

7777
if (newRepositoryPath != repositoryPath)
7878
{
79-
log.Information("Fire PropertyChanged event for ActiveRepository");
79+
log.Debug("Fire PropertyChanged event for ActiveRepository");
8080
ActiveRepository = repo;
8181
}
8282
else if (newBranchName != branchName)
8383
{
84-
log.Information("Fire StatusChanged event when BranchName changes for ActiveRepository");
84+
log.Debug("Fire StatusChanged event when BranchName changes for ActiveRepository");
8585
StatusChanged?.Invoke(this, EventArgs.Empty);
8686
}
8787
else if (newHeadSha != headSha)
8888
{
89-
log.Information("Fire StatusChanged event when HeadSha changes for ActiveRepository");
89+
log.Debug("Fire StatusChanged event when HeadSha changes for ActiveRepository");
9090
StatusChanged?.Invoke(this, EventArgs.Empty);
9191
}
9292
else if (newTrackedSha != trackedSha)
9393
{
94-
log.Information("Fire StatusChanged event when TrackedSha changes for ActiveRepository");
94+
log.Debug("Fire StatusChanged event when TrackedSha changes for ActiveRepository");
9595
StatusChanged?.Invoke(this, EventArgs.Empty);
9696
}
9797

src/GitHub.App/ViewModels/Dialog/LoginTabViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void HandleError(Exception ex)
200200

201201
if (ex.IsCriticalException()) return;
202202

203-
log.Information(ex, "Error logging into '{BaseUri}' as '{UsernameOrEmail}'", BaseUri, UsernameOrEmail);
203+
log.Error(ex, "Error logging into '{BaseUri}' as '{UsernameOrEmail}'", BaseUri, UsernameOrEmail);
204204
if (ex is Octokit.ForbiddenException)
205205
{
206206
Error = new UserError(Resources.LoginFailedForbiddenMessage, ex.Message);

src/GitHub.App/ViewModels/GitHubPane/GitHubPaneViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ async Task UpdateContent(ILocalRepositoryModel repository)
379379
var repositoryUrl = repository.CloneUrl.ToRepositoryUrl();
380380
var isDotCom = HostAddress.IsGitHubDotComUri(repositoryUrl);
381381
var client = await apiClientFactory.Create(repository.CloneUrl);
382-
var isEnterprise = isDotCom ? false : client.IsEnterprise();
382+
var isEnterprise = isDotCom ? false : await client.IsEnterprise();
383383

384384
if ((isDotCom || isEnterprise) && await IsValidRepository(client))
385385
{

src/GitHub.Exports/Api/ISimpleApiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public interface ISimpleApiClient
1111
UriString OriginalUrl { get; }
1212
Task<Repository> GetRepository();
1313
bool HasWiki();
14-
bool IsEnterprise();
14+
Task<bool> IsEnterprise();
1515
bool IsAuthenticated();
1616
}
1717
}

src/GitHub.Exports/Models/UsageModel.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
using System;
2-
using System.Reflection;
3-
4-
namespace GitHub.Models
1+
namespace GitHub.Models
52
{
6-
public class UsageModel
3+
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1815:OverrideEqualsAndOperatorEqualsOnValueTypes", Justification = "It'll use reflection by default and we're fine with that")]
4+
public struct UsageModel
75
{
86
public bool IsGitHubUser { get; set; }
97
public bool IsEnterpriseUser { get; set; }
@@ -43,25 +41,27 @@ public class UsageModel
4341

4442
public UsageModel Clone(bool includeWeekly, bool includeMonthly)
4543
{
46-
var result = new UsageModel();
47-
var properties = result.GetType().GetRuntimeProperties();
48-
49-
foreach (var property in properties)
50-
{
51-
var cloneValue = property.PropertyType == typeof(int);
52-
53-
if (property.Name == nameof(result.NumberOfStartupsWeek))
54-
cloneValue = includeWeekly;
55-
else if (property.Name == nameof(result.NumberOfStartupsMonth))
56-
cloneValue = includeMonthly;
44+
var result = this;
45+
if (!includeWeekly)
46+
result.NumberOfStartupsWeek = 0;
47+
if (!includeMonthly)
48+
result.NumberOfStartupsMonth = 0;
49+
return result;
50+
}
5751

58-
if (cloneValue)
59-
{
60-
var value = property.GetValue(this);
61-
property.SetValue(result, value);
62-
}
63-
}
52+
public UsageModel ClearCounters(bool clearWeekly, bool clearMonthly)
53+
{
54+
var result = new UsageModel();
55+
if (!clearWeekly)
56+
result.NumberOfStartupsWeek = NumberOfStartupsWeek;
57+
if (!clearMonthly)
58+
result.NumberOfStartupsMonth = NumberOfStartupsMonth;
6459

60+
result.IsGitHubUser = IsGitHubUser;
61+
result.IsEnterpriseUser = IsEnterpriseUser;
62+
result.AppVersion = AppVersion;
63+
result.VSVersion = VSVersion;
64+
result.Lang = Lang;
6565
return result;
6666
}
6767
}

src/GitHub.Exports/SimpleJson.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
using System.Runtime.Serialization;
6868
using System.Text;
6969
using GitHub.Reflection;
70+
using System.Diagnostics;
7071

7172
// ReSharper disable LoopCanBeConvertedToQuery
7273
// ReSharper disable RedundantExplicitArrayCreation
@@ -1838,7 +1839,13 @@ public static ConstructorDelegate GetConstructorByReflection(ConstructorInfo con
18381839
public static ConstructorDelegate GetConstructorByReflection(Type type, params Type[] argsType)
18391840
{
18401841
ConstructorInfo constructorInfo = GetConstructorInfo(type, argsType);
1841-
return constructorInfo == null ? null : GetConstructorByReflection(constructorInfo);
1842+
// if it's a value type (i.e., struct), it won't have a default constructor, so use Activator instead
1843+
return constructorInfo == null ? (type.IsValueType ? GetConstructorForValueType(type) : null) : GetConstructorByReflection(constructorInfo);
1844+
}
1845+
1846+
static ConstructorDelegate GetConstructorForValueType(Type type)
1847+
{
1848+
return delegate (object[] args) { return Activator.CreateInstance(type); };
18421849
}
18431850

18441851
#if !SIMPLE_JSON_NO_LINQ_EXPRESSION
@@ -1865,7 +1872,8 @@ public static ConstructorDelegate GetConstructorByExpression(ConstructorInfo con
18651872
public static ConstructorDelegate GetConstructorByExpression(Type type, params Type[] argsType)
18661873
{
18671874
ConstructorInfo constructorInfo = GetConstructorInfo(type, argsType);
1868-
return constructorInfo == null ? null : GetConstructorByExpression(constructorInfo);
1875+
// if it's a value type (i.e., struct), it won't have a default constructor, so use Activator instead
1876+
return constructorInfo == null ? (type.IsValueType ? GetConstructorForValueType(type) : null) : GetConstructorByExpression(constructorInfo);
18691877
}
18701878

18711879
#endif
@@ -1925,6 +1933,9 @@ public static SetDelegate GetSetMethod(PropertyInfo propertyInfo)
19251933
#if SIMPLE_JSON_NO_LINQ_EXPRESSION
19261934
return GetSetMethodByReflection(propertyInfo);
19271935
#else
1936+
// if it's a struct, we want to use reflection, as linq expressions modify copies of the object and not the real thing
1937+
if (propertyInfo.DeclaringType.IsValueType)
1938+
return GetSetMethodByReflection(propertyInfo);
19281939
return GetSetMethodByExpression(propertyInfo);
19291940
#endif
19301941
}
@@ -1934,6 +1945,9 @@ public static SetDelegate GetSetMethod(FieldInfo fieldInfo)
19341945
#if SIMPLE_JSON_NO_LINQ_EXPRESSION
19351946
return GetSetMethodByReflection(fieldInfo);
19361947
#else
1948+
// if it's a struct, we want to use reflection, as linq expressions modify copies of the object and not the real thing
1949+
if (fieldInfo.DeclaringType.IsValueType)
1950+
return GetSetMethodByReflection(fieldInfo);
19371951
return GetSetMethodByExpression(fieldInfo);
19381952
#endif
19391953
}

src/GitHub.Logging/Logging/LogManager.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ static Logger CreateLogger()
2020

2121
return new LoggerConfiguration()
2222
.Enrich.WithThreadId()
23+
#if DEBUG
24+
.MinimumLevel.Debug()
25+
#else
2326
.MinimumLevel.Information()
27+
#endif
2428
.WriteTo.File(logPath,
2529
fileSizeLimitBytes: null,
2630
outputTemplate: outputTemplate)

src/GitHub.TeamFoundation.14/Connect/GitHubConnectSection.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -360,9 +360,7 @@ void ShowNotification(ILocalRepositoryModel newrepo, string msg)
360360
}
361361
})
362362
);
363-
#if DEBUG
364-
log.Information("Notification");
365-
#endif
363+
log.Debug("Notification");
366364
}
367365

368366
async Task RefreshRepositories()
@@ -496,12 +494,10 @@ void TrackState(object sender, PropertyChangedEventArgs e)
496494
{
497495
if (machine.PermittedTriggers.Contains(e.PropertyName))
498496
{
499-
#if DEBUG
500-
log.Information("{PropertyName} title:{Title} busy:{IsBusy}",
497+
log.Debug("{PropertyName} title:{Title} busy:{IsBusy}",
501498
e.PropertyName,
502499
((ITeamExplorerSection)sender).Title,
503500
((ITeamExplorerSection)sender).IsBusy);
504-
#endif
505501
machine.Fire(e.PropertyName);
506502
}
507503
}

0 commit comments

Comments
 (0)