Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: add GeoCoordinate.Default #250

Merged
merged 4 commits into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Core/Geofence/GeofenceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class GeofenceService : IGeofenceService, IGeofenceStore
private readonly SourceCache<GeofenceRegion, string> _store = new SourceCache<GeofenceRegion, string>(region => region.Identifier);

/// <inheritdoc/>
public IObservable<GeoLocation> Location { get; }
public IObservable<GeoCoordinate> Location { get; }

/// <inheritdoc/>
public IObservable<GeofenceRegion> Entered { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Geofence/IGeofenceService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface IGeofenceService
/// <summary>
/// Gets an observable sequence <see cref="Location"/> that have been exited.
/// </summary>
IObservable<GeoLocation> Location { get; }
IObservable<GeoCoordinate> Location { get; }

/// <summary>
/// Gets an observable sequence <see cref="GeofenceRegion"/> that have been entered.
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Locations/Events/LocationUpdatedEvent.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Rocket.Surgery.Airframe;

/// <summary>
/// Notification of a <see cref="GeoLocation"/> update.
/// Notification of a <see cref="IGpsLocation"/> update.
/// </summary>
public class LocationUpdatedEvent
{
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Locations/Events/LocationsUpdatedEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Rocket.Surgery.Airframe;

/// <summary>
/// Represents a <see cref="GeoLocation"/> update event.
/// Represents a <see cref="IGpsLocation"/> update event.
/// </summary>
public class LocationsUpdatedEvent
{
Expand Down
5 changes: 5 additions & 0 deletions src/Core/Locations/GeoCoordinate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ public GeoCoordinate(double latitude, double longitude)
Longitude = longitude;
}

/// <summary>
/// Gets the default <see cref="GeoCoordinate"/>.
/// </summary>
public static GeoCoordinate Default { get; } = new GeoCoordinate(0, 0);

/// <summary>
/// Gets the latitude of the coordinate.
/// </summary>
Expand Down
28 changes: 0 additions & 28 deletions src/Core/Locations/GeoLocation.cs

This file was deleted.

4 changes: 2 additions & 2 deletions src/Core/Locations/GpsLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public GpsLocation(
HeadingAccuracy = headingAccuracy;
Speed = speed;
SpeedAccuracy = speedAccuracy;
Position = position;
Coordinate = position;
PositionAccuracy = positionAccuracy;
Timestamp = timestamp;
}
Expand All @@ -80,7 +80,7 @@ public GpsLocation(
public double SpeedAccuracy { get; }

/// <inheritdoc/>
public GeoCoordinate Position { get; }
public GeoCoordinate Coordinate { get; }

/// <inheritdoc/>
public double PositionAccuracy { get; }
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Locations/IGpsLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public interface IGpsLocation
/// <summary>
/// Gets the position of the reading.
/// </summary>
GeoCoordinate Position { get; }
GeoCoordinate Coordinate { get; }

/// <summary>
/// Gets the position accuracy.
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Locations/MonitorState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MonitorState
/// <summary>
/// Gets or sets the current location.
/// </summary>
public GeoLocation GeoLocation { get; set; }
public GeoCoordinate Location { get; set; } = GeoCoordinate.Default;

/// <summary>
/// Gets or sets a value indicating whether location services are enabled.
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Operations/Startup/ApplicationStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/// <summary>
/// Represents the application startup sequence.
/// </summary>
public sealed class ApplicationStartup : LoggableApplicationStartup, IApplicationStartup
public sealed class ApplicationStartup : ApplicationStartupBase, IApplicationStartup

Check warning on line 9 in src/Core/Operations/Startup/ApplicationStartup.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant class or interface specification in base types list

Base interface 'IApplicationStartup' is redundant because Rocket.Surgery.Airframe.ApplicationStartup inherits 'ApplicationStartupBase'
{
/// <summary>
/// Initializes a new instance of the <see cref="ApplicationStartup"/> class.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,35 @@ namespace Rocket.Surgery.Airframe;
/// <summary>
/// Represents the application startup sequence.
/// </summary>
public abstract class LoggableApplicationStartup : IApplicationStartup
public abstract class ApplicationStartupBase : IApplicationStartup
{
private readonly ILogger _logger;
private readonly IEnumerable<IStartupOperation> _startupOperations;

/// <summary>
/// Initializes a new instance of the <see cref="LoggableApplicationStartup"/> class.
/// Initializes a new instance of the <see cref="ApplicationStartupBase"/> class.
/// </summary>
/// <param name="loggerFactory">The logger factory.</param>
/// <param name="startupOperations">The startup tasks.</param>
protected LoggableApplicationStartup(ILoggerFactory loggerFactory, IEnumerable<IStartupOperation> startupOperations)
protected ApplicationStartupBase(ILoggerFactory loggerFactory, IEnumerable<IStartupOperation> startupOperations)
{
_logger = loggerFactory.CreateLogger(GetType());
_startupOperations = startupOperations;
}

/// <inheritdoc/>
IObservable<Unit> IApplicationStartup.Startup(int concurrentOperations) => Startup(concurrentOperations)
IObservable<Unit> IApplicationStartup.Startup(int concurrentOperations) => Startup(_startupOperations, concurrentOperations, CurrentThreadScheduler.Instance)
.Finally(() => _logger.LogTrace("Start Complete: {Startup}", GetType().Name));

/// <inheritdoc/>
IObservable<Unit> IApplicationStartup.Startup(int concurrentOperations, IScheduler scheduler) => Startup(concurrentOperations, scheduler)
IObservable<Unit> IApplicationStartup.Startup(int concurrentOperations, IScheduler scheduler) => Startup(_startupOperations, concurrentOperations, scheduler)
.Finally(() => _logger.LogTrace("Start Complete: {Startup}", GetType().Name));

/// <summary>
/// Executes the provided <see cref="IStartupOperation"/>.
/// </summary>
/// <param name="operations">The startup operations.</param>
/// <param name="concurrentOperations">The maximum concurrent operations.</param>
/// <param name="scheduler">The scheduler.</param>
/// <returns>A completion notification of the startup operation execution.</returns>
protected virtual IObservable<Unit> Startup(int concurrentOperations, IScheduler scheduler) => _startupOperations
protected virtual IObservable<Unit> Startup(IEnumerable<IStartupOperation> operations, int concurrentOperations, IScheduler scheduler) => operations
.Where(operation => operation.CanExecute())
.Select(operation => operation.Start())
.Merge(concurrentOperations, scheduler)
Expand All @@ -51,7 +49,11 @@ protected virtual IObservable<Unit> Startup(int concurrentOperations, IScheduler
/// <summary>
/// Executes the provided <see cref="IStartupOperation"/>.
/// </summary>
/// <param name="operations">The startup operations.</param>
/// <param name="concurrentOperations">The maximum concurrent operations.</param>
/// <returns>A completion notification of the startup operation execution.</returns>
protected virtual IObservable<Unit> Startup(int concurrentOperations = 1) => Startup(concurrentOperations, CurrentThreadScheduler.Instance);
protected virtual IObservable<Unit> Startup(IEnumerable<IStartupOperation> operations, int concurrentOperations = 1) => Startup(operations, concurrentOperations, CurrentThreadScheduler.Instance);

private readonly ILogger _logger;
private readonly IEnumerable<IStartupOperation> _startupOperations;
}
55 changes: 0 additions & 55 deletions src/Core/Operations/Startup/LoggableStartupOperation.cs

This file was deleted.

30 changes: 26 additions & 4 deletions src/Core/Operations/Startup/StartupOperationBase.cs
Original file line number Diff line number Diff line change
@@ -1,23 +1,45 @@
using System;
using System.Reactive;
using System.Reactive.Linq;

Check warning on line 3 in src/Core/Operations/Startup/StartupOperationBase.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using JetBrains.Annotations;

Check warning on line 4 in src/Core/Operations/Startup/StartupOperationBase.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using Microsoft.Extensions.Logging;

Check warning on line 5 in src/Core/Operations/Startup/StartupOperationBase.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed

namespace Rocket.Surgery.Airframe;

/// <summary>
/// Represents a base startup operation.
/// Represents a <see cref="IStartupOperation"/> that logs using <see cref="ILogger{TCategoryName}"/>.

Check warning on line 10 in src/Core/Operations/Startup/StartupOperationBase.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Invalid XML documentation comment

Cannot resolve symbol 'ILogger'
/// </summary>
[PublicAPI]
public abstract class StartupOperationBase : IStartupOperation
{
/// <summary>
/// Initializes a new instance of the <see cref="StartupOperationBase"/> class.
/// </summary>
/// <param name="factory">The logger factory.</param>
protected StartupOperationBase(ILoggerFactory factory) => Logger = factory.CreateLogger(GetType());

/// <summary>
/// Gets the logger.
/// </summary>
protected ILogger Logger { get; }

/// <inheritdoc/>
IObservable<Unit> IStartupOperation.Start() =>
Start();
Start().Finally(() => Logger.LogTrace("{StartupOperation}: Completed", GetType().Name));

/// <inheritdoc/>
IObservable<Unit> IOperation<Unit>.Execute() =>
Start();

// Add logging.
((IStartupOperation)this).Start();

/// <inheritdoc/>
bool ICanExecute.CanExecute() => CanExecute();
bool ICanExecute.CanExecute()
{
var canExecute = CanExecute();
Logger.LogTrace("Can Execute: {CanExecute}", canExecute);
return canExecute;
}

/// <summary>
/// Template method for the startup operation.
Expand Down
4 changes: 1 addition & 3 deletions src/Core/Timers/IObservableTimer.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System;

namespace Rocket.Surgery.Airframe;

/// <summary>
/// Represents an <see cref="ITimer"/> that is observable.
/// </summary>
public interface IObservableTimer : ITimer, IObservable<TimeSpan>;
public interface IObservableTimer : ITimer;
15 changes: 0 additions & 15 deletions test/Composition.Tests/Composition.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,6 @@
<RootNamespace>Rocket.Surgery.Airframe.Composition.Tests</RootNamespace>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.collector" />
<PackageReference Include="coverlet.msbuild" />
<PackageReference Include="FluentAssertions" />
<PackageReference Include="Microsoft.NET.Test.Sdk" />
<PackageReference Include="ReactiveUI" />
<PackageReference Include="Rocket.Surgery.Extensions.Testing.Fixtures" />
<PackageReference Include="Splat" />
<PackageReference Include="Splat.DryIoc" />
<PackageReference Include="System.ComponentModel" />
<PackageReference Include="System.Reactive" />
<PackageReference Include="xunit" />
<PackageReference Include="xunit.runner.visualstudio" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\Composition\Composition.csproj" />
</ItemGroup>
Expand Down
4 changes: 3 additions & 1 deletion test/Core.Tests/Operations/Startup/TestOperation.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Logging.Abstractions;

Check warning on line 1 in test/Core.Tests/Operations/Startup/TestOperation.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Redundant using directive

Using directive is not required by the code and can be safely removed
using System;
using System.Reactive;
using System.Reactive.Linq;
Expand All @@ -12,7 +13,8 @@
/// Initializes a new instance of the <see cref="TestOperation"/> class.
/// </summary>
/// <param name="canExecute">Whether this instance can execute.</param>
public TestOperation(bool canExecute = true) => _canExecute = canExecute;
public TestOperation(bool canExecute = true)
: base(NullLoggerFactory.Instance) => _canExecute = canExecute;

public bool Executed { get; protected set; }

Expand Down
Loading