Skip to content

Commit

Permalink
Configure and run dotnet format on everything (#704)
Browse files Browse the repository at this point in the history
* Configure and run dotnet format on everything

* Review comments

* Verify no changes

* Less stupid dictionary init
  • Loading branch information
einarmo authored Sep 17, 2024
1 parent 0710664 commit 0679249
Show file tree
Hide file tree
Showing 91 changed files with 374 additions and 461 deletions.
23 changes: 22 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,25 @@ dotnet_diagnostic.IDE0090.severity = none
dotnet_diagnostic.CA1851.severity = none

# CA1861: Prefer static readonly fields over constant array arguments. Not really that important where this pops up, and there are tons of false positives.
dotnet_diagnostic.CA1861.severity = none
dotnet_diagnostic.CA1861.severity = none

# IDE0057: Use range operator.
dotnet_diagnostic.IDE0057.severity = none
# IDE0300: Use collection expression [1, 2, 3]
dotnet_diagnostic.IDE0300.severity = none
# IDE0290: Use primary constructor, this syntax is insane
dotnet_diagnostic.IDE0290.severity = none

# IDE1006: Naming style
dotnet_diagnostic.IDE1006.severity = warning

dotnet_diagnostic.IDE0052.severity = warning
dotnet_diagnostic.xUnit1045.severity = warning
dotnet_diagnostic.IDE0060.severity = warning

indent_size = 4
indent_style = space
tab_width = 4

insert_final_newline = true

3 changes: 3 additions & 0 deletions .github/workflows/common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ jobs:
- name: Build
run: dotnet build ExtractorLauncher/

- name: Lint
run: dotnet format --verify-no-changes

- name: Install release dependencies
run: sudo apt-get install -y rpm build-essential sed
- name: Build release binary
Expand Down
2 changes: 1 addition & 1 deletion ConfigurationTool/UAServerExplorer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public void OnCreatedSubscription(SubscriptionName subscription)

public FullConfig FinalConfig => baseConfig;

private PeriodicScheduler scheduler = null!;
private readonly PeriodicScheduler scheduler = null!;
public PeriodicScheduler TaskScheduler => scheduler;
}
}
2 changes: 1 addition & 1 deletion Extractor/Browse/BrowseParams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ public BrowseNode(NodeId id, BrowseNode parent)
public BrowseResult? Result { get; private set; }
public void AddReferences(ReferenceDescriptionCollection references)
{
if (references == null) references = new ReferenceDescriptionCollection();
references ??= new ReferenceDescriptionCollection();
if (Result == null)
{
Result = new BrowseResult(this, references);
Expand Down
2 changes: 1 addition & 1 deletion Extractor/Browse/BrowseScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public BrowseScheduler(
callback = options.Callback;

if (options == null) throw new ArgumentNullException(nameof(options));
if (options.InitialParams?.Nodes == null) throw new ArgumentException("options.InitialParams.Nodes is required");
if (options.InitialParams?.Nodes == null) throw new InvalidOperationException("options.InitialParams.Nodes is required");

baseParams = options.InitialParams;

Expand Down
3 changes: 1 addition & 2 deletions Extractor/Browse/Browser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public sealed class Browser : IDisposable
private readonly ILogger<Browser> log;
private readonly UAClient uaClient;
private readonly FullConfig config;
private readonly object visitedNodesLock = new object();

private readonly ContinuationPointThrottlingConfig throttling;
private readonly TaskThrottler throttler;
Expand Down Expand Up @@ -190,7 +189,7 @@ await uaClient.GetReferences(new BrowseParams
return roots.Values;
}

public async Task GetRootNodes(IEnumerable<NodeId> ids, Action<ReferenceDescription, NodeId, bool> callback, CancellationToken token, string purpose = "")
public async Task GetRootNodes(IEnumerable<NodeId> ids, Action<ReferenceDescription, NodeId, bool> callback, CancellationToken token)
{
var refs = await GetRootNodes(ids, token);
foreach (var rf in refs)
Expand Down
2 changes: 1 addition & 1 deletion Extractor/Config/ConfigToggles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ public ConfigToggles(FullConfig config)
/// </summary>
public bool LoadTypeReferences => FdmEnabled;
}
}
}
6 changes: 3 additions & 3 deletions Extractor/Config/EventConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public IEnumerable<string> BaseExcludeProperties
public Dictionary<string, string> DestinationNameMap { get => destinationNameMap; set => destinationNameMap = value ?? destinationNameMap; }
private Dictionary<string, string> destinationNameMap = new Dictionary<string, string>();

public HashSet<NodeId>? GetWhitelist(SessionContext context, ILogger logger)
public HashSet<NodeId>? GetWhitelist(SessionContext context)
{
if (EventIds == null || !EventIds.Any()) return null;
var whitelist = new HashSet<NodeId>();
Expand All @@ -114,7 +114,7 @@ public IEnumerable<string> BaseExcludeProperties
return whitelist;
}

public HashSet<NodeId> GetEmitterIds(SessionContext context, ILogger logger)
public HashSet<NodeId> GetEmitterIds(SessionContext context)
{
if (EmitterIds == null || !EmitterIds.Any()) return new HashSet<NodeId>();
var ids = new HashSet<NodeId>();
Expand All @@ -131,7 +131,7 @@ public HashSet<NodeId> GetEmitterIds(SessionContext context, ILogger logger)
return ids;
}

public HashSet<NodeId> GetHistorizingEmitterIds(SessionContext context, ILogger logger)
public HashSet<NodeId> GetHistorizingEmitterIds(SessionContext context)
{
if (HistorizingEmitterIds == null || !HistorizingEmitterIds.Any()) return new HashSet<NodeId>();
var ids = new HashSet<NodeId>();
Expand Down
7 changes: 2 additions & 5 deletions Extractor/Config/ExtractionConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */

using Cognite.Extensions.DataModels.QueryBuilder;
using Cognite.Extractor.Common;
using Cognite.OpcUa.Nodes;
using Cognite.OpcUa.NodeSources;
using Microsoft.Extensions.Logging;
using Opc.Ua;
using Serilog.Debugging;
using System;
using System.Collections.Generic;
using System.IO;
Expand Down Expand Up @@ -373,7 +370,7 @@ public class RebrowseTriggersConfig

public class RebrowseTriggerTargets
{
private List<string> ToBeSubscribed = new List<string>();
private readonly List<string> ToBeSubscribed = new List<string>();

public bool NamespacePublicationDate
{
Expand Down Expand Up @@ -453,7 +450,7 @@ public override string ToString()
first = false;
builder.AppendFormat("\"{0}\"", entry);
}
builder.Append("]");
builder.Append(']');
return base.ToString();
}
}
Expand Down
22 changes: 11 additions & 11 deletions Extractor/Config/FullConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,24 +113,24 @@ public FullConfig() : base()
public bool DryRun { get; set; }
public override void GenerateDefaults()
{
if (Source == null) Source = new SourceConfig();
if (Logger == null) Logger = new UALoggerConfig();
if (Metrics == null) Metrics = new UAMetricsConfig();
Source ??= new SourceConfig();
Logger ??= new UALoggerConfig();
Metrics ??= new UAMetricsConfig();
if (Cognite != null)
{
if (Cognite.CdfChunking == null) Cognite.CdfChunking = new ChunkingConfig();
if (Cognite.CdfThrottling == null) Cognite.CdfThrottling = new ThrottlingConfig();
if (Cognite.CdfRetries == null) Cognite.CdfRetries = new RetryConfig();
if (Cognite.SdkLogging == null) Cognite.SdkLogging = new SdkLoggingConfig();
}
if (Extraction == null) Extraction = new ExtractionConfig();
if (Events == null) Events = new EventConfig();
if (FailureBuffer == null) FailureBuffer = new FailureBufferConfig();
if (History == null) History = new HistoryConfig();
if (StateStorage == null) StateStorage = new StateStorageConfig();
if (Subscriptions == null) Subscriptions = new SubscriptionConfig();
if (PubSub == null) PubSub = new PubSubConfig();
if (HighAvailability == null) HighAvailability = new HighAvailabilityConfig();
Extraction ??= new ExtractionConfig();
Events ??= new EventConfig();
FailureBuffer ??= new FailureBufferConfig();
History ??= new HistoryConfig();
StateStorage ??= new StateStorageConfig();
Subscriptions ??= new SubscriptionConfig();
PubSub ??= new PubSubConfig();
HighAvailability ??= new HighAvailabilityConfig();
}
}
public class UAMetricsConfig : MetricsConfig
Expand Down
4 changes: 2 additions & 2 deletions Extractor/Config/SourceConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -318,14 +318,14 @@ public HashSet<uint> FinalRetryStatusCodes
}
}

private static HashSet<Type> retryExceptions = new HashSet<Type>
private static readonly HashSet<Type> retryExceptions = new HashSet<Type>
{
typeof(ArgumentNullException),
typeof(NullReferenceException),
typeof(InvalidOperationException)
};

public bool ShouldRetryException(Exception ex, IEnumerable<uint> statusCodes)
public static bool ShouldRetryException(Exception ex, IEnumerable<uint> statusCodes)
{
if (ex is ServiceResultException serviceExc)
{
Expand Down
6 changes: 3 additions & 3 deletions Extractor/Deletes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private async Task<IEnumerable<KnownNodesState>> GetDeletedItems(string? tableNa
}

var newStates = states.Values.Where(s => !oldStates.ContainsKey(s.Id)).ToList();
if (newStates.Any())
if (newStates.Count != 0)
{
logger.LogInformation("Found {New} new nodes in {Tab}, adding to state store...", newStates.Count, tableName);
if (!config.DryRun) await stateStore.StoreExtractionState(newStates, tableName,
Expand All @@ -136,10 +136,10 @@ public async Task<DeletedNodes> GetDiffAndStoreIds(NodeSourceResult result, Sess
var time = DateTime.UtcNow.AddSeconds(-1);
var newVariables = result.DestinationVariables.Select(v => (v.Id, v.GetUniqueId(context)!)).ToDictionary(
i => i.Item2,
i => new NodeExistsState(i.Item2, i.Item1, context, time));
i => new NodeExistsState(i.Item2, i.Id, context, time));
var newObjects = result.DestinationObjects.Select(o => (o.Id, o.GetUniqueId(context)!)).ToDictionary(
i => i.Item2,
i => new NodeExistsState(i.Item2, i.Item1, context, time));
i => new NodeExistsState(i.Item2, i.Id, context, time));
var newReferences = result.DestinationReferences.Select(r => client.GetRelationshipId(r)!).ToDictionary(
i => i,
i => new NodeExistsState(i, null, null, time));
Expand Down
2 changes: 1 addition & 1 deletion Extractor/ExtractorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public enum SourceOp

public static void LogException(ILogger log, Exception? e, string message, string? silentMessage = null)
{
if (silentMessage == null) silentMessage = message;
silentMessage ??= message;
if (e == null)
{
log.LogError("Unknown error: {Message}", message);
Expand Down
7 changes: 1 addition & 6 deletions Extractor/History/HistoryReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,12 @@ You should have received a copy of the GNU General Public License
using Cognite.Extractor.Common;
using Cognite.OpcUa.Config;
using Cognite.OpcUa.TypeCollectors;
using Google.Protobuf.WellKnownTypes;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.ObjectPool;
using Opc.Ua;
using System;
using System.Collections.Generic;
using System.CommandLine.Parsing;
using System.Linq;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;

Expand Down Expand Up @@ -209,7 +204,7 @@ private async Task RunAllHistory()

class State
{
private HashSet<StateIssue> issues = new();
private readonly HashSet<StateIssue> issues = new();

public bool AddIssue(StateIssue issue)
{
Expand Down
91 changes: 37 additions & 54 deletions Extractor/History/HistoryScheduler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,8 @@ private DateTime DefaultEndTime()
private static DateTime GetStartTime(string? start)
{
if (string.IsNullOrWhiteSpace(start)) return CogniteTime.DateTimeEpoch;
var parsed = CogniteTime.ParseTimestampString(start);
if (parsed == null) throw new ArgumentException($"Invalid history start time: {start}");
return parsed!.Value;
var parsed = CogniteTime.ParseTimestampString(start) ?? throw new ArgumentException($"Invalid history start time: {start}");
return parsed;
}

private static IEnumerable<HistoryReadNode> GetNodes(
Expand Down Expand Up @@ -254,53 +253,43 @@ private static DateTime Max(DateTime t1, DateTime t2)

private (HistoryReadDetails, DateTime, DateTime) GetReadDetails(IEnumerable<HistoryReadNode> nodes)
{
HistoryReadDetails details;
var (min, max) = GetReadRange(nodes);
log.LogDebug("Read {Type} history chunk for {Count} nodes from {Min} to {Max}",
type, nodes.Count(), min, max);
switch (type)
HistoryReadDetails details = type switch
{
case HistoryReadType.FrontfillData:
details = new ReadRawModifiedDetails
{
IsReadModified = false,
StartTime = min,
EndTime = max,
NumValuesPerNode = (uint)Config.DataChunk,
ReturnBounds = false,
};
break;
case HistoryReadType.BackfillData:
details = new ReadRawModifiedDetails
{
IsReadModified = false,
StartTime = min,
EndTime = max,
NumValuesPerNode = (uint)Config.DataChunk,
ReturnBounds = false,
};
break;
case HistoryReadType.FrontfillEvents:
details = new ReadEventDetails
{
StartTime = min,
EndTime = max,
NumValuesPerNode = (uint)Config.EventChunk,
Filter = uaClient.BuildEventFilter(typeManager.EventFields),
};
break;
case HistoryReadType.BackfillEvents:
details = new ReadEventDetails
{
StartTime = min,
EndTime = max,
NumValuesPerNode = (uint)Config.EventChunk,
Filter = uaClient.BuildEventFilter(typeManager.EventFields)
};
break;
default:
throw new InvalidOperationException();
}
HistoryReadType.FrontfillData => new ReadRawModifiedDetails
{
IsReadModified = false,
StartTime = min,
EndTime = max,
NumValuesPerNode = (uint)Config.DataChunk,
ReturnBounds = false,
},
HistoryReadType.BackfillData => new ReadRawModifiedDetails
{
IsReadModified = false,
StartTime = min,
EndTime = max,
NumValuesPerNode = (uint)Config.DataChunk,
ReturnBounds = false,
},
HistoryReadType.FrontfillEvents => new ReadEventDetails
{
StartTime = min,
EndTime = max,
NumValuesPerNode = (uint)Config.EventChunk,
Filter = uaClient.BuildEventFilter(typeManager.EventFields),
},
HistoryReadType.BackfillEvents => new ReadEventDetails
{
StartTime = min,
EndTime = max,
NumValuesPerNode = (uint)Config.EventChunk,
Filter = uaClient.BuildEventFilter(typeManager.EventFields)
},
_ => throw new InvalidOperationException(),
};
return (details, min, max);
}

Expand Down Expand Up @@ -557,10 +546,7 @@ private async Task HistoryDataHandler(HistoryReadNode node)
var data = node.LastResult as HistoryData;
node.LastResult = null;

if (node.State == null)
{
node.State = extractor.State.GetNodeState(node.Id);
}
node.State ??= extractor.State.GetNodeState(node.Id);

if (node.State == null)
{
Expand Down Expand Up @@ -699,10 +685,7 @@ private async Task HistoryEventHandler(HistoryReadNode node, HistoryReadDetails
log.LogWarning("No event filter when reading from history, ignoring");
return;
}
if (node.State == null)
{
node.State = extractor.State.GetEmitterState(node.Id);
}
node.State ??= extractor.State.GetEmitterState(node.Id);

if (node.State == null)
{
Expand Down
2 changes: 1 addition & 1 deletion Extractor/History/SmartAggregateException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,4 @@ public SmartAggregateException(AggregateException aex) : base(AggregateException
{
}
}
}
}
2 changes: 1 addition & 1 deletion Extractor/Looper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ await Task.WhenAll(

numPushes.Inc();

if (pushWaiterSource != null) pushWaiterSource.TrySetResult(true);
pushWaiterSource?.TrySetResult(true);
}


Expand Down
Loading

0 comments on commit 0679249

Please sign in to comment.