Skip to content

Commit

Permalink
Update widget code to comply with naming rules (#222)
Browse files Browse the repository at this point in the history
  • Loading branch information
krschau authored Jun 19, 2024
1 parent 3bdbeab commit d86ff56
Show file tree
Hide file tree
Showing 25 changed files with 291 additions and 269 deletions.
33 changes: 27 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,13 @@ csharp_style_var_elsewhere = true:suggestion
csharp_style_var_for_built_in_types = true:suggestion
#prefer var when the type is already mentioned on the right-hand side of a declaration expression
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning

#Style - language keyword and framework type options

#prefer the language keyword for local variables, method parameters, and class members, instead of the type name, for types that have a keyword to represent them
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion

#Style - Language rules
csharp_style_implicit_object_creation_when_type_is_apparent = true:warning
csharp_style_var_for_built_in_types = true:warning

#Style - modifier options

#prefer accessibility modifiers to be declared except for public interface members. This will currently not differ from always and will act as future proofing for if C# adds default interface methods.
Expand Down Expand Up @@ -132,6 +129,9 @@ csharp_style_expression_bodied_indexers = true:silent
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent

# IDE0290: Use primary constructor
dotnet_diagnostic.IDE0290.severity = silent

[*.{cs,vb}]
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
Expand All @@ -146,7 +146,6 @@ dotnet_style_collection_initializer = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
[*.{cs,vb}]

#Style - Unnecessary code rules
csharp_style_unused_value_assignment_preference = discard_variable:warning
Expand Down Expand Up @@ -203,10 +202,32 @@ dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:warning
dotnet_style_prefer_simplified_interpolation = true:suggestion

# Define what we will treat as private fields.
dotnet_naming_symbols.private_fields.applicable_kinds = field
dotnet_naming_symbols.private_fields.applicable_accessibilities = private

dotnet_naming_symbols.const_private_fields.applicable_kinds = field
dotnet_naming_symbols.const_private_fields.applicable_accessibilities = private
dotnet_naming_symbols.const_private_fields.required_modifiers = const

# Define rule that something must begin with an underscore and be in camel case.
dotnet_naming_style.require_underscore_prefix_and_camel_case.required_prefix = _
dotnet_naming_style.require_underscore_prefix_and_camel_case.capitalization = camel_case

dotnet_naming_style.requre_no_prefix_and_pascal_case.required_prefix =
dotnet_naming_style.requre_no_prefix_and_pascal_case.capitalization = pascal_case

# Appy our rule to private fields.
dotnet_naming_rule.private_fields_must_begin_with_underscore_and_be_in_camel_case.symbols = private_fields
dotnet_naming_rule.private_fields_must_begin_with_underscore_and_be_in_camel_case.style = require_underscore_prefix_and_camel_case
dotnet_naming_rule.private_fields_must_begin_with_underscore_and_be_in_camel_case.severity = warning

dotnet_naming_rule.const_fields_must_begin_with_no_prefix_and_be_in_pascal_case.symbols = const_private_fields
dotnet_naming_rule.const_fields_must_begin_with_no_prefix_and_be_in_pascal_case.style = requre_no_prefix_and_pascal_case
dotnet_naming_rule.const_fields_must_begin_with_no_prefix_and_be_in_pascal_case.severity = warning
# Spelling

spelling_exclusion_path = .\exclusion.dic
spelling_error_severity = warning

# Diagnostic configuration

Expand Down
14 changes: 9 additions & 5 deletions exclusion.dic
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@ brokerplugin
Entra
riid
enums
enums
Stdout
visualstudio
vssps
Entra
riid
foobar
msix
yaml
Quickstart
Tensorflow
vscode
codespace
codespaces
dhlog
appsettings
56 changes: 28 additions & 28 deletions src/AzureExtension/DataManager/AzureDataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ public partial class AzureDataManager : IAzureDataManager, IDisposable
public static readonly int QueryResultLimit = 25;

// Most data that has not been updated within this time will be removed.
private static readonly TimeSpan DataRetentionTime = TimeSpan.FromDays(1);
private static readonly TimeSpan _dataRetentionTime = TimeSpan.FromDays(1);

private static readonly string LastUpdatedKeyName = "LastUpdated";
private static readonly string _lastUpdatedKeyName = "LastUpdated";

private static readonly string Name = nameof(AzureDataManager);
private static readonly string _name = nameof(AzureDataManager);

private static readonly ConcurrentDictionary<string, Guid> Instances = new();
private static readonly ConcurrentDictionary<string, Guid> _instances = new();

// Connections are a pairing of DeveloperId and a Uri.
private static readonly ConcurrentDictionary<Tuple<Uri, DeveloperId.DeveloperId>, VssConnection> Connections = new();
private static readonly ConcurrentDictionary<Tuple<Uri, DeveloperId.DeveloperId>, VssConnection> _connections = new();

private readonly ILogger _log;

Expand All @@ -74,7 +74,7 @@ public partial class AzureDataManager : IAzureDataManager, IDisposable
}
catch (Exception e)
{
var log = Log.ForContext("SourceContext", Name);
var log = Log.ForContext("SourceContext", _name);
log.Error(e, $"Failed creating AzureDataManager for {identifier}");
return null;
}
Expand All @@ -88,7 +88,7 @@ public AzureDataManager(string identifier, DataStoreOptions dataStoreOptions)
}

InstanceName = identifier;
_log = Log.ForContext("SourceContext", $"{Name}/{InstanceName}");
_log = Log.ForContext("SourceContext", $"{_name}/{InstanceName}");
DataStoreOptions = dataStoreOptions;
DataStore = new DataStore(
"DataStore",
Expand All @@ -111,7 +111,7 @@ public AzureDataManager(string identifier, DataStoreOptions dataStoreOptions)
_log.Warning(ex, "Failed setting DeveloperId change handler.");
}

if (Instances.TryGetValue(InstanceName, out var instanceIdentifier))
if (_instances.TryGetValue(InstanceName, out var instanceIdentifier))
{
// We should not have duplicate AzureDataManagers, as every client should have one,
// but the identifiers may not be unique if using partial Guids. Note in the log
Expand All @@ -121,7 +121,7 @@ public AzureDataManager(string identifier, DataStoreOptions dataStoreOptions)
}
else
{
Instances.TryAdd(InstanceName, UniqueName);
_instances.TryAdd(InstanceName, UniqueName);
}

_log.Information($"Created AzureDataManager: {UniqueName}.");
Expand All @@ -144,7 +144,7 @@ public DateTime LastUpdated
get
{
ValidateDataStore();
var lastUpdated = MetaData.Get(DataStore, LastUpdatedKeyName);
var lastUpdated = MetaData.Get(DataStore, _lastUpdatedKeyName);
if (lastUpdated == null)
{
return DateTime.MinValue;
Expand All @@ -154,7 +154,7 @@ public DateTime LastUpdated
}
}

public override string ToString() => $"{Name}/{InstanceName}";
public override string ToString() => $"{_name}/{InstanceName}";

public async Task UpdateDataForQueriesAsync(IEnumerable<AzureUri> queryUris, string developerLogin, RequestOptions? options = null, Guid? requestor = null)
{
Expand Down Expand Up @@ -710,12 +710,12 @@ private static void SendUpdateEvent(ILogger logger, object? source, DataManagerU
// the bad connection issue can be reliably detected and solved.
public static ConnectionResult GetConnection(Uri connectionUri, DeveloperId.DeveloperId developerId, bool forceNewConnection = true)
{
var log = Log.ForContext("SourceContext", Name);
var log = Log.ForContext("SourceContext", _name);
VssConnection? connection;
var connectionKey = Tuple.Create(connectionUri, developerId);
if (Connections.ContainsKey(connectionKey))
if (_connections.ContainsKey(connectionKey))
{
if (Connections.TryGetValue(connectionKey, out connection))
if (_connections.TryGetValue(connectionKey, out connection))
{
// If not forcing a new connection and it has authenticated, reuse it.
if (!forceNewConnection && connection.HasAuthenticated)
Expand All @@ -726,7 +726,7 @@ public static ConnectionResult GetConnection(Uri connectionUri, DeveloperId.Deve
else
{
// Remove the bad connection.
if (Connections.TryRemove(new KeyValuePair<Tuple<Uri, DeveloperId.DeveloperId>, VssConnection>(connectionKey, connection)))
if (_connections.TryRemove(new KeyValuePair<Tuple<Uri, DeveloperId.DeveloperId>, VssConnection>(connectionKey, connection)))
{
log.Debug($"Removed bad connection to {connectionUri} with {developerId.LoginId}");
}
Expand All @@ -744,7 +744,7 @@ public static ConnectionResult GetConnection(Uri connectionUri, DeveloperId.Deve
var result = AzureClientProvider.CreateVssConnection(connectionUri, developerId);
if (result.Result == ResultType.Success)
{
if (Connections.TryAdd(connectionKey, result.Connection!))
if (_connections.TryAdd(connectionKey, result.Connection!))
{
log.Debug($"Added connection for {connectionUri} with {developerId.LoginId}");
}
Expand All @@ -760,10 +760,10 @@ public static ConnectionResult GetConnection(Uri connectionUri, DeveloperId.Deve
// Removes unused data from the datastore.
private void PruneObsoleteData()
{
Query.DeleteBefore(DataStore, DateTime.UtcNow - DataRetentionTime);
PullRequests.DeleteBefore(DataStore, DateTime.UtcNow - DataRetentionTime);
WorkItemType.DeleteBefore(DataStore, DateTime.UtcNow - DataRetentionTime);
Identity.DeleteBefore(DataStore, DateTime.UtcNow - DataRetentionTime);
Query.DeleteBefore(DataStore, DateTime.UtcNow - _dataRetentionTime);
PullRequests.DeleteBefore(DataStore, DateTime.UtcNow - _dataRetentionTime);
WorkItemType.DeleteBefore(DataStore, DateTime.UtcNow - _dataRetentionTime);
Identity.DeleteBefore(DataStore, DateTime.UtcNow - _dataRetentionTime);

// The following are not yet pruned, need to ensure there are no current key references
// before deletion.
Expand All @@ -774,7 +774,7 @@ private void PruneObsoleteData()
// Sets a last-updated in the MetaData.
private void SetLastUpdatedInMetaData()
{
MetaData.AddOrUpdate(DataStore, LastUpdatedKeyName, DateTime.Now.ToDataStoreString());
MetaData.AddOrUpdate(DataStore, _lastUpdatedKeyName, DateTime.Now.ToDataStoreString());
}

private void ValidateDataStore()
Expand Down Expand Up @@ -808,9 +808,9 @@ private void HandleDeveloperIdChange(IDeveloperIdProvider sender, IDeveloperId a

// Making the default options a singleton to avoid repeatedly calling the storage APIs and
// creating a new AzureDataStoreSchema when not necessary.
private static readonly Lazy<DataStoreOptions> LazyDataStoreOptions = new(DefaultOptionsInit);
private static readonly Lazy<DataStoreOptions> _lazyDataStoreOptions = new(DefaultOptionsInit);

public static DataStoreOptions DefaultOptions => LazyDataStoreOptions.Value;
public static DataStoreOptions DefaultOptions => _lazyDataStoreOptions.Value;

private static DataStoreOptions DefaultOptionsInit()
{
Expand All @@ -821,20 +821,20 @@ private static DataStoreOptions DefaultOptionsInit()
};
}

private bool disposed; // To detect redundant calls.
private bool _disposed; // To detect redundant calls.

protected virtual void Dispose(bool disposing)
{
if (!disposed)
if (!_disposed)
{
if (disposing)
{
try
{
_log.Debug("Disposing of all Disposable resources.");
if (Instances.TryGetValue(InstanceName, out var instanceName) && instanceName == UniqueName)
if (_instances.TryGetValue(InstanceName, out var instanceName) && instanceName == UniqueName)
{
Instances.TryRemove(InstanceName, out _);
_instances.TryRemove(InstanceName, out _);
_log.Information($"Removed AzureDataManager: {UniqueName}.");
}

Expand All @@ -845,7 +845,7 @@ protected virtual void Dispose(bool disposing)
}
}

disposed = true;
_disposed = true;
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/AzureExtension/DataManager/DataUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace DevHomeAzureExtension.DataManager;
public class DataUpdater : IDisposable
{
// This is the default interval the timer will run. It is not the interval that we necessarily do work.
private static readonly TimeSpan TimerUpdateInterval = TimeSpan.FromSeconds(5);
private static readonly TimeSpan _timerUpdateInterval = TimeSpan.FromSeconds(5);

private readonly ILogger _logger;
private readonly PeriodicTimer _timer;
Expand All @@ -28,7 +28,7 @@ public DataUpdater(TimeSpan interval, Func<Task> action)
}

public DataUpdater(Func<Task> action)
: this(TimerUpdateInterval, action)
: this(_timerUpdateInterval, action)
{
}

Expand Down Expand Up @@ -62,11 +62,11 @@ public void Stop()

public override string ToString() => "DataUpdater";

private bool disposed; // To detect redundant calls.
private bool _disposed; // To detect redundant calls.

protected virtual void Dispose(bool disposing)
{
if (!disposed)
if (!_disposed)
{
_logger.Debug("Disposing of all updater resources.");

Expand All @@ -75,7 +75,7 @@ protected virtual void Dispose(bool disposing)
_timer.Dispose();
}

disposed = true;
_disposed = true;
}
}

Expand Down
18 changes: 9 additions & 9 deletions src/AzureExtension/DataModel/AzureDataStoreSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class AzureDataStoreSchema : IDataStoreSchema
{
public long SchemaVersion => SchemaVersionValue;

public List<string> SchemaSqls => SchemaSqlsValue;
public List<string> SchemaSqls => _schemaSqlsValue;

public AzureDataStoreSchema()
{
Expand All @@ -16,15 +16,15 @@ public AzureDataStoreSchema()
// Update this anytime incompatible changes happen with a released version.
private const long SchemaVersionValue = 0x0003;

private static readonly string Metadata =
private const string Metadata =
@"CREATE TABLE Metadata (" +
"Id INTEGER PRIMARY KEY NOT NULL," +
"Key TEXT NOT NULL COLLATE NOCASE," +
"Value TEXT NOT NULL" +
");" +
"CREATE UNIQUE INDEX IDX_Metadata_Key ON Metadata (Key);";

private static readonly string Identity =
private const string Identity =
@"CREATE TABLE Identity (" +
"Id INTEGER PRIMARY KEY NOT NULL," +
"Name TEXT NOT NULL COLLATE NOCASE," +
Expand All @@ -36,7 +36,7 @@ public AzureDataStoreSchema()
// InternalId is a Guid from the server, so by definition is unique.
"CREATE UNIQUE INDEX IDX_Identity_InternalId ON Identity (InternalId);";

private static readonly string Project =
private const string Project =
@"CREATE TABLE Project (" +
"Id INTEGER PRIMARY KEY NOT NULL," +
"Name TEXT NOT NULL COLLATE NOCASE," +
Expand All @@ -50,7 +50,7 @@ public AzureDataStoreSchema()
// Project Name can be renamed and reused per DevOps documentation, so it is not safe.
"CREATE UNIQUE INDEX IDX_Project_InternalId ON Project (InternalId);";

private static readonly string Organization =
private const string Organization =
@"CREATE TABLE Organization (" +
"Id INTEGER PRIMARY KEY NOT NULL," +
"Name TEXT NOT NULL COLLATE NOCASE," +
Expand All @@ -65,7 +65,7 @@ public AzureDataStoreSchema()
// each connection should correspond to only one organization.
"CREATE UNIQUE INDEX IDX_Organization_Connection ON Organization (Connection);";

private static readonly string Query =
private const string Query =
@"CREATE TABLE Query (" +
"Id INTEGER PRIMARY KEY NOT NULL," +
"QueryId TEXT NOT NULL COLLATE NOCASE," +
Expand All @@ -82,7 +82,7 @@ public AzureDataStoreSchema()
// the query. Therefore we make unique constraint on QueryId AND DeveloperLogin.
"CREATE UNIQUE INDEX IDX_Query_QueryIdDeveloperLogin ON Query (QueryId, DeveloperLogin);";

private static readonly string WorkItemType =
private const string WorkItemType =
@"CREATE TABLE WorkItemType (" +
"Id INTEGER PRIMARY KEY NOT NULL," +
"Name TEXT NOT NULL COLLATE NOCASE," +
Expand All @@ -97,7 +97,7 @@ public AzureDataStoreSchema()
// constraint on Name and ProjectId is consistent and safe.
"CREATE UNIQUE INDEX IDX_WorkItemType_NameProjectId ON WorkItemType (Name, ProjectId);";

private static readonly string PullRequests =
private const string PullRequests =
@"CREATE TABLE PullRequests (" +
"Id INTEGER PRIMARY KEY NOT NULL," +
"RepositoryName TEXT NOT NULL COLLATE NOCASE," +
Expand All @@ -113,7 +113,7 @@ public AzureDataStoreSchema()
"CREATE UNIQUE INDEX IDX_PullRequests_ProjectIdRepositoryNameDeveloperLoginViewId ON PullRequests (ProjectId, RepositoryName, DeveloperLogin, ViewId);";

// All Sqls together.
private static readonly List<string> SchemaSqlsValue = new()
private static readonly List<string> _schemaSqlsValue = new()
{
Metadata,
Identity,
Expand Down
Loading

0 comments on commit d86ff56

Please sign in to comment.