From 7f4e302fb31cd168e5f9c69e50386624a3349256 Mon Sep 17 00:00:00 2001 From: rlittlesii <6969701+RLittlesII@users.noreply.github.com> Date: Wed, 10 Jan 2024 23:24:57 -0600 Subject: [PATCH 1/2] enhancement: add GeoCoordinate.Default --- src/Core/Locations/GeoCoordinate.cs | 1 + src/Core/Locations/MonitorState.cs | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Core/Locations/GeoCoordinate.cs b/src/Core/Locations/GeoCoordinate.cs index e9f4b113a..3b2d20d9e 100644 --- a/src/Core/Locations/GeoCoordinate.cs +++ b/src/Core/Locations/GeoCoordinate.cs @@ -38,6 +38,7 @@ public GeoCoordinate(double latitude, double longitude) /// Gets the longitude of the coordinate. /// public double Longitude { get; } + public static GeoCoordinate Default { get; } = new GeoCoordinate(0, 0); public static bool operator ==(GeoCoordinate? left, GeoCoordinate? right) => Equals(left, right); diff --git a/src/Core/Locations/MonitorState.cs b/src/Core/Locations/MonitorState.cs index 0cc0c4d63..a6d6c8601 100644 --- a/src/Core/Locations/MonitorState.cs +++ b/src/Core/Locations/MonitorState.cs @@ -20,10 +20,10 @@ public class MonitorState /// public double DistanceFilter { get; set; } - /// - /// Gets or sets the current location. - /// - public GeoLocation GeoLocation { get; set; } + /// + /// Gets or sets the current location. + /// + public GeoCoordinate Location { get; set; } /// /// Gets or sets a value indicating whether location services are enabled. From f8479ad9f1e7e3f0ad43cb4fe841ccd192f6cbdc Mon Sep 17 00:00:00 2001 From: rlittlesii <6969701+RLittlesII@users.noreply.github.com> Date: Sat, 10 Feb 2024 00:37:01 -0600 Subject: [PATCH 2/2] enhancement: enhancement: add GeoCoordinate Default --- src/Core/Geofence/GeofenceService.cs | 2 +- src/Core/Geofence/IGeofenceService.cs | 2 +- .../Locations/Events/LocationUpdatedEvent.cs | 2 +- .../Locations/Events/LocationsUpdatedEvent.cs | 2 +- src/Core/Locations/GeoCoordinate.cs | 6 +- src/Core/Locations/GeoLocation.cs | 28 ---------- src/Core/Locations/GpsLocation.cs | 4 +- src/Core/Locations/IGpsLocation.cs | 2 +- src/Core/Locations/MonitorState.cs | 8 +-- .../Operations/Startup/ApplicationStartup.cs | 2 +- ...onStartup.cs => ApplicationStartupBase.cs} | 22 ++++---- .../Startup/LoggableStartupOperation.cs | 55 ------------------- .../Startup/StartupOperationBase.cs | 30 ++++++++-- src/Core/Timers/IObservableTimer.cs | 4 +- .../Composition.Tests.csproj | 15 ----- .../Operations/Startup/TestOperation.cs | 4 +- 16 files changed, 59 insertions(+), 129 deletions(-) delete mode 100644 src/Core/Locations/GeoLocation.cs rename src/Core/Operations/Startup/{LoggableApplicationStartup.cs => ApplicationStartupBase.cs} (66%) delete mode 100644 src/Core/Operations/Startup/LoggableStartupOperation.cs diff --git a/src/Core/Geofence/GeofenceService.cs b/src/Core/Geofence/GeofenceService.cs index 12c2eb9db..fba196b50 100644 --- a/src/Core/Geofence/GeofenceService.cs +++ b/src/Core/Geofence/GeofenceService.cs @@ -12,7 +12,7 @@ public class GeofenceService : IGeofenceService, IGeofenceStore private readonly SourceCache _store = new SourceCache(region => region.Identifier); /// - public IObservable Location { get; } + public IObservable Location { get; } /// public IObservable Entered { get; } diff --git a/src/Core/Geofence/IGeofenceService.cs b/src/Core/Geofence/IGeofenceService.cs index f33320509..afee610eb 100644 --- a/src/Core/Geofence/IGeofenceService.cs +++ b/src/Core/Geofence/IGeofenceService.cs @@ -11,7 +11,7 @@ public interface IGeofenceService /// /// Gets an observable sequence that have been exited. /// - IObservable Location { get; } + IObservable Location { get; } /// /// Gets an observable sequence that have been entered. diff --git a/src/Core/Locations/Events/LocationUpdatedEvent.cs b/src/Core/Locations/Events/LocationUpdatedEvent.cs index 6c6c86eaa..562c05b72 100644 --- a/src/Core/Locations/Events/LocationUpdatedEvent.cs +++ b/src/Core/Locations/Events/LocationUpdatedEvent.cs @@ -1,7 +1,7 @@ namespace Rocket.Surgery.Airframe; /// -/// Notification of a update. +/// Notification of a update. /// public class LocationUpdatedEvent { diff --git a/src/Core/Locations/Events/LocationsUpdatedEvent.cs b/src/Core/Locations/Events/LocationsUpdatedEvent.cs index 3fea2e9ef..f3363de6f 100644 --- a/src/Core/Locations/Events/LocationsUpdatedEvent.cs +++ b/src/Core/Locations/Events/LocationsUpdatedEvent.cs @@ -3,7 +3,7 @@ namespace Rocket.Surgery.Airframe; /// -/// Represents a update event. +/// Represents a update event. /// public class LocationsUpdatedEvent { diff --git a/src/Core/Locations/GeoCoordinate.cs b/src/Core/Locations/GeoCoordinate.cs index 3b2d20d9e..3d3892568 100644 --- a/src/Core/Locations/GeoCoordinate.cs +++ b/src/Core/Locations/GeoCoordinate.cs @@ -29,6 +29,11 @@ public GeoCoordinate(double latitude, double longitude) Longitude = longitude; } + /// + /// Gets the default . + /// + public static GeoCoordinate Default { get; } = new GeoCoordinate(0, 0); + /// /// Gets the latitude of the coordinate. /// @@ -38,7 +43,6 @@ public GeoCoordinate(double latitude, double longitude) /// Gets the longitude of the coordinate. /// public double Longitude { get; } - public static GeoCoordinate Default { get; } = new GeoCoordinate(0, 0); public static bool operator ==(GeoCoordinate? left, GeoCoordinate? right) => Equals(left, right); diff --git a/src/Core/Locations/GeoLocation.cs b/src/Core/Locations/GeoLocation.cs deleted file mode 100644 index 5249ebc1e..000000000 --- a/src/Core/Locations/GeoLocation.cs +++ /dev/null @@ -1,28 +0,0 @@ -namespace Rocket.Surgery.Airframe; - -/// -/// Represents a latitude and longitude. -/// -public class GeoLocation -{ - /// - /// Initializes a new instance of the class. - /// - /// The latitude. - /// The longitude. - public GeoLocation(double latitude, double longitude) - { - Latitude = latitude; - Longitude = longitude; - } - - /// - /// Gets the latitude. - /// - public double Latitude { get; } - - /// - /// Gets the longitude. - /// - public double Longitude { get; } -} \ No newline at end of file diff --git a/src/Core/Locations/GpsLocation.cs b/src/Core/Locations/GpsLocation.cs index d00e1dcd8..f53e0d5f7 100644 --- a/src/Core/Locations/GpsLocation.cs +++ b/src/Core/Locations/GpsLocation.cs @@ -59,7 +59,7 @@ public GpsLocation( HeadingAccuracy = headingAccuracy; Speed = speed; SpeedAccuracy = speedAccuracy; - Position = position; + Coordinate = position; PositionAccuracy = positionAccuracy; Timestamp = timestamp; } @@ -80,7 +80,7 @@ public GpsLocation( public double SpeedAccuracy { get; } /// - public GeoCoordinate Position { get; } + public GeoCoordinate Coordinate { get; } /// public double PositionAccuracy { get; } diff --git a/src/Core/Locations/IGpsLocation.cs b/src/Core/Locations/IGpsLocation.cs index 6064b65ec..faf3d4af2 100644 --- a/src/Core/Locations/IGpsLocation.cs +++ b/src/Core/Locations/IGpsLocation.cs @@ -35,7 +35,7 @@ public interface IGpsLocation /// /// Gets the position of the reading. /// - GeoCoordinate Position { get; } + GeoCoordinate Coordinate { get; } /// /// Gets the position accuracy. diff --git a/src/Core/Locations/MonitorState.cs b/src/Core/Locations/MonitorState.cs index a6d6c8601..6f348efde 100644 --- a/src/Core/Locations/MonitorState.cs +++ b/src/Core/Locations/MonitorState.cs @@ -20,10 +20,10 @@ public class MonitorState /// public double DistanceFilter { get; set; } - /// - /// Gets or sets the current location. - /// - public GeoCoordinate Location { get; set; } + /// + /// Gets or sets the current location. + /// + public GeoCoordinate Location { get; set; } = GeoCoordinate.Default; /// /// Gets or sets a value indicating whether location services are enabled. diff --git a/src/Core/Operations/Startup/ApplicationStartup.cs b/src/Core/Operations/Startup/ApplicationStartup.cs index bf8ee7e5a..e7e7d30c3 100644 --- a/src/Core/Operations/Startup/ApplicationStartup.cs +++ b/src/Core/Operations/Startup/ApplicationStartup.cs @@ -6,7 +6,7 @@ namespace Rocket.Surgery.Airframe; /// /// Represents the application startup sequence. /// -public sealed class ApplicationStartup : LoggableApplicationStartup, IApplicationStartup +public sealed class ApplicationStartup : ApplicationStartupBase, IApplicationStartup { /// /// Initializes a new instance of the class. diff --git a/src/Core/Operations/Startup/LoggableApplicationStartup.cs b/src/Core/Operations/Startup/ApplicationStartupBase.cs similarity index 66% rename from src/Core/Operations/Startup/LoggableApplicationStartup.cs rename to src/Core/Operations/Startup/ApplicationStartupBase.cs index b271956a7..acc3c8b80 100644 --- a/src/Core/Operations/Startup/LoggableApplicationStartup.cs +++ b/src/Core/Operations/Startup/ApplicationStartupBase.cs @@ -11,37 +11,35 @@ namespace Rocket.Surgery.Airframe; /// /// Represents the application startup sequence. /// -public abstract class LoggableApplicationStartup : IApplicationStartup +public abstract class ApplicationStartupBase : IApplicationStartup { - private readonly ILogger _logger; - private readonly IEnumerable _startupOperations; - /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// /// The logger factory. /// The startup tasks. - protected LoggableApplicationStartup(ILoggerFactory loggerFactory, IEnumerable startupOperations) + protected ApplicationStartupBase(ILoggerFactory loggerFactory, IEnumerable startupOperations) { _logger = loggerFactory.CreateLogger(GetType()); _startupOperations = startupOperations; } /// - IObservable IApplicationStartup.Startup(int concurrentOperations) => Startup(concurrentOperations) + IObservable IApplicationStartup.Startup(int concurrentOperations) => Startup(_startupOperations, concurrentOperations, CurrentThreadScheduler.Instance) .Finally(() => _logger.LogTrace("Start Complete: {Startup}", GetType().Name)); /// - IObservable IApplicationStartup.Startup(int concurrentOperations, IScheduler scheduler) => Startup(concurrentOperations, scheduler) + IObservable IApplicationStartup.Startup(int concurrentOperations, IScheduler scheduler) => Startup(_startupOperations, concurrentOperations, scheduler) .Finally(() => _logger.LogTrace("Start Complete: {Startup}", GetType().Name)); /// /// Executes the provided . /// + /// The startup operations. /// The maximum concurrent operations. /// The scheduler. /// A completion notification of the startup operation execution. - protected virtual IObservable Startup(int concurrentOperations, IScheduler scheduler) => _startupOperations + protected virtual IObservable Startup(IEnumerable operations, int concurrentOperations, IScheduler scheduler) => operations .Where(operation => operation.CanExecute()) .Select(operation => operation.Start()) .Merge(concurrentOperations, scheduler) @@ -51,7 +49,11 @@ protected virtual IObservable Startup(int concurrentOperations, IScheduler /// /// Executes the provided . /// + /// The startup operations. /// The maximum concurrent operations. /// A completion notification of the startup operation execution. - protected virtual IObservable Startup(int concurrentOperations = 1) => Startup(concurrentOperations, CurrentThreadScheduler.Instance); + protected virtual IObservable Startup(IEnumerable operations, int concurrentOperations = 1) => Startup(operations, concurrentOperations, CurrentThreadScheduler.Instance); + + private readonly ILogger _logger; + private readonly IEnumerable _startupOperations; } \ No newline at end of file diff --git a/src/Core/Operations/Startup/LoggableStartupOperation.cs b/src/Core/Operations/Startup/LoggableStartupOperation.cs deleted file mode 100644 index 1e9b3eb22..000000000 --- a/src/Core/Operations/Startup/LoggableStartupOperation.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Reactive; -using System.Reactive.Linq; -using Microsoft.Extensions.Logging; - -namespace Rocket.Surgery.Airframe; - -/// -/// Represents a that logs using . -/// -public abstract class LoggableStartupOperation : IStartupOperation -{ - /// - /// Initializes a new instance of the class. - /// - /// The logger factory. - protected LoggableStartupOperation(ILoggerFactory factory) => Logger = factory.CreateLogger(GetType()); - - /// - /// Gets the logger. - /// - protected ILogger Logger { get; } - - /// - IObservable IStartupOperation.Start() => - - // Add logging. - Start().Finally(() => Logger.LogTrace("{StartupOperation}: Completed", GetType().Name)); - - /// - IObservable IOperation.Execute() => - - // Add logging. - ((IStartupOperation)this).Start(); - - /// - bool ICanExecute.CanExecute() - { - var canExecute = CanExecute(); - Logger.LogTrace("Can Execute: {CanExecute}", canExecute); - return canExecute; - } - - /// - /// Template method for the startup operation. - /// - /// A completion notification. - protected abstract IObservable Start(); - - /// - /// Template method for whether or not the startup operation will execute. - /// - /// A completion notification. - protected virtual bool CanExecute() => true; -} \ No newline at end of file diff --git a/src/Core/Operations/Startup/StartupOperationBase.cs b/src/Core/Operations/Startup/StartupOperationBase.cs index 8a55e7bf8..0c4b27354 100644 --- a/src/Core/Operations/Startup/StartupOperationBase.cs +++ b/src/Core/Operations/Startup/StartupOperationBase.cs @@ -1,23 +1,45 @@ using System; using System.Reactive; +using System.Reactive.Linq; +using JetBrains.Annotations; +using Microsoft.Extensions.Logging; namespace Rocket.Surgery.Airframe; /// -/// Represents a base startup operation. +/// Represents a that logs using . /// +[PublicAPI] public abstract class StartupOperationBase : IStartupOperation { + /// + /// Initializes a new instance of the class. + /// + /// The logger factory. + protected StartupOperationBase(ILoggerFactory factory) => Logger = factory.CreateLogger(GetType()); + + /// + /// Gets the logger. + /// + protected ILogger Logger { get; } + /// IObservable IStartupOperation.Start() => - Start(); + Start().Finally(() => Logger.LogTrace("{StartupOperation}: Completed", GetType().Name)); /// IObservable IOperation.Execute() => - Start(); + + // Add logging. + ((IStartupOperation)this).Start(); /// - bool ICanExecute.CanExecute() => CanExecute(); + bool ICanExecute.CanExecute() + { + var canExecute = CanExecute(); + Logger.LogTrace("Can Execute: {CanExecute}", canExecute); + return canExecute; + } /// /// Template method for the startup operation. diff --git a/src/Core/Timers/IObservableTimer.cs b/src/Core/Timers/IObservableTimer.cs index ceb502b8c..6652823e6 100644 --- a/src/Core/Timers/IObservableTimer.cs +++ b/src/Core/Timers/IObservableTimer.cs @@ -1,8 +1,6 @@ -using System; - namespace Rocket.Surgery.Airframe; /// /// Represents an that is observable. /// -public interface IObservableTimer : ITimer, IObservable; \ No newline at end of file +public interface IObservableTimer : ITimer; \ No newline at end of file diff --git a/test/Composition.Tests/Composition.Tests.csproj b/test/Composition.Tests/Composition.Tests.csproj index 267a5cbed..bd0ceef02 100644 --- a/test/Composition.Tests/Composition.Tests.csproj +++ b/test/Composition.Tests/Composition.Tests.csproj @@ -5,21 +5,6 @@ Rocket.Surgery.Airframe.Composition.Tests - - - - - - - - - - - - - - - diff --git a/test/Core.Tests/Operations/Startup/TestOperation.cs b/test/Core.Tests/Operations/Startup/TestOperation.cs index 8646c6434..10cbaf9d9 100644 --- a/test/Core.Tests/Operations/Startup/TestOperation.cs +++ b/test/Core.Tests/Operations/Startup/TestOperation.cs @@ -1,3 +1,4 @@ +using Microsoft.Extensions.Logging.Abstractions; using System; using System.Reactive; using System.Reactive.Linq; @@ -12,7 +13,8 @@ internal class TestOperation : StartupOperationBase /// Initializes a new instance of the class. /// /// Whether this instance can execute. - public TestOperation(bool canExecute = true) => _canExecute = canExecute; + public TestOperation(bool canExecute = true) + : base(NullLoggerFactory.Instance) => _canExecute = canExecute; public bool Executed { get; protected set; }