Use file scoped namespaces

This commit is contained in:
Peter Butzhammer
2024-02-07 09:54:18 +01:00
parent bacfbf05e2
commit e6cea1e04f
24 changed files with 1131 additions and 1191 deletions

View File

@@ -1,5 +1,4 @@
using System; using NUnit.Framework;
using NUnit.Framework;
using Sharp7.Rx.Interfaces; using Sharp7.Rx.Interfaces;
using Shouldly; using Shouldly;

View File

@@ -1,5 +1,4 @@
using System.Collections.Generic; using DeepEqual.Syntax;
using DeepEqual.Syntax;
using NUnit.Framework; using NUnit.Framework;
using Sharp7.Rx.Enums; using Sharp7.Rx.Enums;

View File

@@ -1,12 +1,10 @@
using System; using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Reactive; using System.Reactive;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Reactive.Subjects; using System.Reactive.Subjects;
namespace Sharp7.Rx.Basics namespace Sharp7.Rx.Basics;
{
internal class ConcurrentSubjectDictionary<TKey, TValue> : IDisposable internal class ConcurrentSubjectDictionary<TKey, TValue> : IDisposable
{ {
private readonly object dictionaryLock = new object(); private readonly object dictionaryLock = new object();
@@ -125,4 +123,3 @@ namespace Sharp7.Rx.Basics
public ISubject<TValue> Subject { get; set; } public ISubject<TValue> Subject { get; set; }
} }
} }
}

View File

@@ -1,7 +1,5 @@
using System; namespace Sharp7.Rx.Basics;
namespace Sharp7.Rx.Basics
{
internal class DisposableItem<TValue> : IDisposable internal class DisposableItem<TValue> : IDisposable
{ {
private readonly Action disposeAction; private readonly Action disposeAction;
@@ -34,4 +32,3 @@ namespace Sharp7.Rx.Basics
disposed = true; disposed = true;
} }
} }
}

View File

@@ -1,11 +1,5 @@
using System; namespace Sharp7.Rx.Basics;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace Sharp7.Rx.Basics
{
/// <summary> /// <summary>
/// Provides a task scheduler that ensures a maximum concurrency level while /// Provides a task scheduler that ensures a maximum concurrency level while
/// running on top of the ThreadPool. /// running on top of the ThreadPool.
@@ -143,4 +137,3 @@ namespace Sharp7.Rx.Basics
}, null); }, null);
} }
} }
}

View File

@@ -1,9 +1,8 @@
using System; using System.Collections.Concurrent;
using System.Collections.Concurrent;
using Sharp7.Rx.Interfaces; using Sharp7.Rx.Interfaces;
namespace Sharp7.Rx namespace Sharp7.Rx;
{
internal class CacheVariableNameParser : IS7VariableNameParser internal class CacheVariableNameParser : IS7VariableNameParser
{ {
private static readonly ConcurrentDictionary<string, S7VariableAddress> addressCache = new ConcurrentDictionary<string, S7VariableAddress>(StringComparer.OrdinalIgnoreCase); private static readonly ConcurrentDictionary<string, S7VariableAddress> addressCache = new ConcurrentDictionary<string, S7VariableAddress>(StringComparer.OrdinalIgnoreCase);
@@ -17,4 +16,3 @@ namespace Sharp7.Rx
public S7VariableAddress Parse(string input) => addressCache.GetOrAdd(input, inner.Parse); public S7VariableAddress Parse(string input) => addressCache.GetOrAdd(input, inner.Parse);
} }
}

View File

@@ -1,5 +1,5 @@
namespace Sharp7.Rx.Enums namespace Sharp7.Rx.Enums;
{
public enum ConnectionState public enum ConnectionState
{ {
Initial, Initial,
@@ -7,4 +7,3 @@
DisconnectedByUser, DisconnectedByUser,
ConnectionLost ConnectionLost
} }
}

View File

@@ -1,5 +1,5 @@
namespace Sharp7.Rx.Enums namespace Sharp7.Rx.Enums;
{
internal enum CpuType internal enum CpuType
{ {
S7_300, S7_300,
@@ -7,4 +7,3 @@
S7_1200, S7_1200,
S7_1500 S7_1500
} }
}

View File

@@ -1,5 +1,5 @@
namespace Sharp7.Rx.Enums namespace Sharp7.Rx.Enums;
{
internal enum DbType internal enum DbType
{ {
Bit, Bit,
@@ -10,4 +10,3 @@
DInteger, DInteger,
ULong ULong
} }
}

View File

@@ -1,5 +1,5 @@
namespace Sharp7.Rx.Enums namespace Sharp7.Rx.Enums;
{
internal enum Operand : byte internal enum Operand : byte
{ {
Input = 69, Input = 69,
@@ -7,4 +7,3 @@
Marker = 77, Marker = 77,
Db = 68, Db = 68,
} }
}

View File

@@ -1,8 +1,7 @@
namespace Sharp7.Rx.Enums namespace Sharp7.Rx.Enums;
{
public enum TransmissionMode public enum TransmissionMode
{ {
Cyclic = 3, Cyclic = 3,
OnChange = 4, OnChange = 4,
} }
}

View File

@@ -1,8 +1,7 @@
using System; using System.Reactive.Disposables;
using System.Reactive.Disposables;
namespace Sharp7.Rx.Extensions;
namespace Sharp7.Rx.Extensions
{
internal static class DisposableExtensions internal static class DisposableExtensions
{ {
public static void AddDisposableTo(this IDisposable disposable, CompositeDisposable compositeDisposable) public static void AddDisposableTo(this IDisposable disposable, CompositeDisposable compositeDisposable)
@@ -10,4 +9,3 @@ namespace Sharp7.Rx.Extensions
compositeDisposable.Add(disposable); compositeDisposable.Add(disposable);
} }
} }
}

View File

@@ -1,11 +1,10 @@
using System; using System.Reactive.Concurrency;
using System.Reactive.Concurrency;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
namespace Sharp7.Rx.Extensions namespace Sharp7.Rx.Extensions;
{
internal static class ObservableExtensions internal static class ObservableExtensions
{ {
public static IObservable<T> DisposeMany<T>(this IObservable<T> source) public static IObservable<T> DisposeMany<T>(this IObservable<T> source)
@@ -80,4 +79,3 @@ namespace Sharp7.Rx.Extensions
return retryCount > 0 ? reDoCount(deferedObs, retryCount) : reDo(deferedObs); return retryCount > 0 ? reDoCount(deferedObs, retryCount) : reDo(deferedObs);
} }
} }
}

View File

@@ -1,14 +1,12 @@
using System; using System.Reactive;
using System.Reactive;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Reactive.Threading.Tasks; using System.Reactive.Threading.Tasks;
using System.Threading.Tasks;
using Sharp7.Rx.Enums; using Sharp7.Rx.Enums;
using Sharp7.Rx.Interfaces; using Sharp7.Rx.Interfaces;
namespace Sharp7.Rx.Extensions namespace Sharp7.Rx.Extensions;
{
public static class PlcExtensions public static class PlcExtensions
{ {
public static IObservable<TReturn> CreateDatatransferWithHandshake<TReturn>(this IPlc plc, string triggerAddress, string ackTriggerAddress, Func<IPlc, Task<TReturn>> readData, bool initialTransfer) public static IObservable<TReturn> CreateDatatransferWithHandshake<TReturn>(this IPlc plc, string triggerAddress, string ackTriggerAddress, Func<IPlc, Task<TReturn>> readData, bool initialTransfer)
@@ -71,4 +69,3 @@ namespace Sharp7.Rx.Extensions
} }
} }
} }
}

View File

@@ -1,11 +1,9 @@
using System; using JetBrains.Annotations;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Sharp7.Rx.Enums; using Sharp7.Rx.Enums;
namespace Sharp7.Rx.Interfaces namespace Sharp7.Rx.Interfaces;
{
[NoReorder] [NoReorder]
public interface IPlc : IDisposable public interface IPlc : IDisposable
{ {
@@ -15,4 +13,3 @@ namespace Sharp7.Rx.Interfaces
IObservable<ConnectionState> ConnectionState { get; } IObservable<ConnectionState> ConnectionState { get; }
ILogger Logger { get; } ILogger Logger { get; }
} }
}

View File

@@ -1,12 +1,8 @@
using System; using JetBrains.Annotations;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using Sharp7.Rx.Enums; using Sharp7.Rx.Enums;
namespace Sharp7.Rx.Interfaces namespace Sharp7.Rx.Interfaces;
{
[NoReorder] [NoReorder]
internal interface IS7Connector : IDisposable internal interface IS7Connector : IDisposable
{ {
@@ -23,4 +19,3 @@ namespace Sharp7.Rx.Interfaces
Task<Dictionary<string, byte[]>> ExecuteMultiVarRequest(IReadOnlyList<string> variableNames); Task<Dictionary<string, byte[]>> ExecuteMultiVarRequest(IReadOnlyList<string> variableNames);
} }
}

View File

@@ -1,7 +1,6 @@
namespace Sharp7.Rx.Interfaces namespace Sharp7.Rx.Interfaces;
{
internal interface IS7VariableNameParser internal interface IS7VariableNameParser
{ {
S7VariableAddress Parse(string input); S7VariableAddress Parse(string input);
} }
}

View File

@@ -1,7 +1,5 @@
using System.Collections.Generic; namespace Sharp7.Rx;
namespace Sharp7.Rx
{
public static class S7ErrorCodes public static class S7ErrorCodes
{ {
/// <summary> /// <summary>
@@ -24,4 +22,3 @@ namespace Sharp7.Rx
return !notDisconnectedErrorCodes.Contains(errorCode); return !notDisconnectedErrorCodes.Contains(errorCode);
} }
} }
}

View File

@@ -1,11 +1,10 @@
using System; using System.Buffers.Binary;
using System.Buffers.Binary;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using Sharp7.Rx.Enums; using Sharp7.Rx.Enums;
namespace Sharp7.Rx namespace Sharp7.Rx;
{
internal static class S7ValueConverter internal static class S7ValueConverter
{ {
public static TValue ConvertToType<TValue>(byte[] buffer, S7VariableAddress address) public static TValue ConvertToType<TValue>(byte[] buffer, S7VariableAddress address)
@@ -82,4 +81,3 @@ namespace Sharp7.Rx
[FieldOffset(0)] public float Single; [FieldOffset(0)] public float Single;
} }
} }
}

View File

@@ -1,8 +1,8 @@
using JetBrains.Annotations; using JetBrains.Annotations;
using Sharp7.Rx.Enums; using Sharp7.Rx.Enums;
namespace Sharp7.Rx namespace Sharp7.Rx;
{
[NoReorder] [NoReorder]
internal class S7VariableAddress internal class S7VariableAddress
{ {
@@ -13,4 +13,3 @@ namespace Sharp7.Rx
public byte Bit { get; set; } public byte Bit { get; set; }
public DbType Type { get; set; } public DbType Type { get; set; }
} }
}

View File

@@ -1,12 +1,10 @@
using System; using System.Globalization;
using System.Collections.Generic;
using System.Globalization;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using Sharp7.Rx.Enums; using Sharp7.Rx.Enums;
using Sharp7.Rx.Interfaces; using Sharp7.Rx.Interfaces;
namespace Sharp7.Rx namespace Sharp7.Rx;
{
internal class S7VariableNameParser : IS7VariableNameParser internal class S7VariableNameParser : IS7VariableNameParser
{ {
private static readonly Regex regex = new Regex(@"^(?<operand>db{1})(?<dbNr>\d{1,4})\.?(?<type>dbx|x|s|string|b|dbb|d|int|dbw|w|dint|dul|dulint|dulong|){1}(?<start>\d+)(\.(?<bitOrLength>\d+))?$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.CultureInvariant); private static readonly Regex regex = new Regex(@"^(?<operand>db{1})(?<dbNr>\d{1,4})\.?(?<type>dbx|x|s|string|b|dbb|d|int|dbw|w|dint|dul|dulint|dulong|){1}(?<start>\d+)(\.(?<bitOrLength>\d+))?$", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.CultureInvariant);
@@ -81,4 +79,3 @@ namespace Sharp7.Rx
return null; return null;
} }
} }
}

View File

@@ -1,5 +1,5 @@
namespace Sharp7.Rx.Settings namespace Sharp7.Rx.Settings;
{
internal class PlcConnectionSettings internal class PlcConnectionSettings
{ {
public int CpuMpiAddress { get; set; } public int CpuMpiAddress { get; set; }
@@ -7,4 +7,3 @@
public int Port { get; set; } public int Port { get; set; }
public int RackNumber { get; set; } public int RackNumber { get; set; }
} }
}

View File

@@ -1,11 +1,6 @@
using System; using System.Reactive.Disposables;
using System.Collections.Generic;
using System.Linq;
using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Reactive.Subjects; using System.Reactive.Subjects;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Sharp7.Rx.Basics; using Sharp7.Rx.Basics;
using Sharp7.Rx.Enums; using Sharp7.Rx.Enums;
@@ -14,8 +9,8 @@ using Sharp7.Rx.Interfaces;
using Sharp7.Rx.Resources; using Sharp7.Rx.Resources;
using Sharp7.Rx.Settings; using Sharp7.Rx.Settings;
namespace Sharp7.Rx namespace Sharp7.Rx;
{
internal class Sharp7Connector : IS7Connector internal class Sharp7Connector : IS7Connector
{ {
private readonly BehaviorSubject<ConnectionState> connectionStateSubject = new BehaviorSubject<ConnectionState>(Enums.ConnectionState.Initial); private readonly BehaviorSubject<ConnectionState> connectionStateSubject = new BehaviorSubject<ConnectionState>(Enums.ConnectionState.Initial);
@@ -276,4 +271,3 @@ namespace Sharp7.Rx
Dispose(false); Dispose(false);
} }
} }
}

View File

@@ -1,13 +1,8 @@
using System; using System.Diagnostics;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reactive; using System.Reactive;
using System.Reactive.Disposables; using System.Reactive.Disposables;
using System.Reactive.Linq; using System.Reactive.Linq;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using Sharp7.Rx.Basics; using Sharp7.Rx.Basics;
using Sharp7.Rx.Enums; using Sharp7.Rx.Enums;
@@ -15,8 +10,8 @@ using Sharp7.Rx.Extensions;
using Sharp7.Rx.Interfaces; using Sharp7.Rx.Interfaces;
using Sharp7.Rx.Settings; using Sharp7.Rx.Settings;
namespace Sharp7.Rx namespace Sharp7.Rx;
{
public class Sharp7Plc : IPlc public class Sharp7Plc : IPlc
{ {
protected readonly CompositeDisposable Disposables = new CompositeDisposable(); protected readonly CompositeDisposable Disposables = new CompositeDisposable();
@@ -281,4 +276,3 @@ namespace Sharp7.Rx
Dispose(false); Dispose(false);
} }
} }
}