Skip to content

Commit

Permalink
Merge pull request #100 from pyrocumulus/code-cleanup
Browse files Browse the repository at this point in the history
Cleaning up code analysis warnings
  • Loading branch information
pyrocumulus authored Dec 15, 2021
2 parents 5719005 + 3343378 commit 2b36de7
Show file tree
Hide file tree
Showing 11 changed files with 71 additions and 57 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@
All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## Unreleased

### Fixed

- **BREAKING**: Many methods with a parameter of `DateTime` used the parameter name `date`; those have been renamed [#100](https://github.com/pyrocumulus/pvoutput.net/pull/100)
- Logging is now more performant and async flow has been slightly improved [#100](https://github.com/pyrocumulus/pvoutput.net/pull/100)

## [0.9.2] - 2021-11-22

### Updated
Expand Down
18 changes: 9 additions & 9 deletions src/PVOutput.Net/Modules/InsolationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,46 @@ internal InsolationService(PVOutputClient client) : base(client)
}

/// <inheritdoc />
public Task<PVOutputArrayResponse<IInsolation>> GetInsolationForOwnSystemAsync(DateTime? date = null, CancellationToken cancellationToken = default)
public Task<PVOutputArrayResponse<IInsolation>> GetInsolationForOwnSystemAsync(DateTime? insolationDate = null, CancellationToken cancellationToken = default)
{
var loggingScope = new Dictionary<string, object>()
{
[LoggingEvents.RequestId] = LoggingEvents.InsolationService_GetInsolationForOwnSystem,
[LoggingEvents.Parameter_Date] = date
[LoggingEvents.Parameter_Date] = insolationDate
};

var handler = new RequestHandler(Client);
var response = handler.ExecuteArrayRequestAsync<IInsolation>(new InsolationRequest { Date = date }, loggingScope, cancellationToken);
var response = handler.ExecuteArrayRequestAsync<IInsolation>(new InsolationRequest { Date = insolationDate }, loggingScope, cancellationToken);
return response;
}

/// <inheritdoc />
public Task<PVOutputArrayResponse<IInsolation>> GetInsolationForSystemAsync(int systemId, DateTime? date = null, CancellationToken cancellationToken = default)
public Task<PVOutputArrayResponse<IInsolation>> GetInsolationForSystemAsync(int systemId, DateTime? insolationDate = null, CancellationToken cancellationToken = default)
{
var loggingScope = new Dictionary<string, object>()
{
[LoggingEvents.RequestId] = LoggingEvents.InsolationService_GetInsolationForSystem,
[LoggingEvents.Parameter_SystemId] = systemId,
[LoggingEvents.Parameter_Date] = date
[LoggingEvents.Parameter_Date] = insolationDate
};

var handler = new RequestHandler(Client);
var response = handler.ExecuteArrayRequestAsync<IInsolation>(new InsolationRequest { SystemId = systemId, Date = date }, loggingScope, cancellationToken);
var response = handler.ExecuteArrayRequestAsync<IInsolation>(new InsolationRequest { SystemId = systemId, Date = insolationDate }, loggingScope, cancellationToken);
return response;
}

/// <inheritdoc />
public Task<PVOutputArrayResponse<IInsolation>> GetInsolationForLocationAsync(PVCoordinate coordinate, DateTime? date = null, CancellationToken cancellationToken = default)
public Task<PVOutputArrayResponse<IInsolation>> GetInsolationForLocationAsync(PVCoordinate coordinate, DateTime? insolationDate = null, CancellationToken cancellationToken = default)
{
var loggingScope = new Dictionary<string, object>()
{
[LoggingEvents.RequestId] = LoggingEvents.InsolationService_GetInsolationForLocation,
[LoggingEvents.Parameter_Coordinate] = coordinate,
[LoggingEvents.Parameter_Date] = date
[LoggingEvents.Parameter_Date] = insolationDate
};

var handler = new RequestHandler(Client);
var response = handler.ExecuteArrayRequestAsync<IInsolation>(new InsolationRequest { Coordinate = coordinate, Date = date }, loggingScope, cancellationToken);
var response = handler.ExecuteArrayRequestAsync<IInsolation>(new InsolationRequest { Coordinate = coordinate, Date = insolationDate }, loggingScope, cancellationToken);
return response;
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/PVOutput.Net/Modules/Interfaces/IInsolationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,29 @@ public interface IInsolationService
/// Get insolation data for own system.
/// <para><strong>Note: this is a donation only request.</strong></para>
/// </summary>
/// <param name="date">The DateTime to calculate the insolation for. If empty, the current date will be calculated.</param>
/// <param name="insolationDate">The DateTime to calculate the insolation for. If empty, the current date will be calculated.</param>
/// <param name="cancellationToken">A cancellation token for the request.</param>
/// <returns>Insolation data for the owned system.</returns>
Task<PVOutputArrayResponse<IInsolation>> GetInsolationForOwnSystemAsync(DateTime? date = null, CancellationToken cancellationToken = default);
Task<PVOutputArrayResponse<IInsolation>> GetInsolationForOwnSystemAsync(DateTime? insolationDate = null, CancellationToken cancellationToken = default);

/// <summary>
/// Get insolation data for a system.
/// <para><strong>Note: this is a donation only request.</strong></para>
/// </summary>
/// <param name="systemId">Id of the system to get insolation for.</param>
/// <param name="date">The DateTime to calculate the insolation for. If empty, the current date will be calculated.</param>
/// <param name="insolationDate">The DateTime to calculate the insolation for. If empty, the current date will be calculated.</param>
/// <param name="cancellationToken">A cancellation token for the request.</param>
/// <returns>Insolation data for the requested system.</returns>
Task<PVOutputArrayResponse<IInsolation>> GetInsolationForSystemAsync(int systemId, DateTime? date = null, CancellationToken cancellationToken = default);
Task<PVOutputArrayResponse<IInsolation>> GetInsolationForSystemAsync(int systemId, DateTime? insolationDate = null, CancellationToken cancellationToken = default);

/// <summary>
/// Get insolation data for a location.
/// <para><strong>Note: this is a donation only request.</strong></para>
/// </summary>
/// <param name="coordinate">GPS coordinate, to request insolation for.</param>
/// <param name="date">The DateTime to calculate the insolation for. If empty, the current date will be calculated.</param>
/// <param name="insolationDate">The DateTime to calculate the insolation for. If empty, the current date will be calculated.</param>
/// <param name="cancellationToken">A cancellation token for the request.</param>
/// <returns>Insolation data for the requested location.</returns>
Task<PVOutputArrayResponse<IInsolation>> GetInsolationForLocationAsync(PVCoordinate coordinate, DateTime? date = null, CancellationToken cancellationToken = default);
Task<PVOutputArrayResponse<IInsolation>> GetInsolationForLocationAsync(PVCoordinate coordinate, DateTime? insolationDate = null, CancellationToken cancellationToken = default);
}
}
8 changes: 4 additions & 4 deletions src/PVOutput.Net/Modules/Interfaces/IOutputService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public interface IOutputService
/// <summary>
/// Retrieve daily output for a date.
/// </summary>
/// <param name="date">Date to retrieve the output for.</param>
/// <param name="outputDate">Date to retrieve the output for.</param>
/// <param name="getInsolation">Also retrieve insolation information. <strong>Note: this is a donation only parameter.</strong></param>
/// <param name="systemId">Retrieve output for a specific system. <strong>Note: this is a donation only parameter.</strong></param>
/// <param name="cancellationToken">A cancellation token for the request.</param>
/// <returns>Output for the requested date.</returns>
Task<PVOutputResponse<IOutput>> GetOutputForDateAsync(DateTime date, bool getInsolation = false, int? systemId = null, CancellationToken cancellationToken = default);
Task<PVOutputResponse<IOutput>> GetOutputForDateAsync(DateTime outputDate, bool getInsolation = false, int? systemId = null, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve daily outputs for a period.
Expand All @@ -39,11 +39,11 @@ public interface IOutputService
/// <summary>
/// Retrieve daily output for a team.
/// </summary>
/// <param name="date">Date to retrieve the output for.</param>
/// <param name="outputDate">Date to retrieve the output for.</param>
/// <param name="teamId">Team to retrieve the output for.</param>
/// <param name="cancellationToken">A cancellation token for the request.</param>
/// <returns>Team output for the requested date.</returns>
Task<PVOutputResponse<ITeamOutput>> GetTeamOutputForDateAsync(DateTime date, int teamId, CancellationToken cancellationToken = default);
Task<PVOutputResponse<ITeamOutput>> GetTeamOutputForDateAsync(DateTime outputDate, int teamId, CancellationToken cancellationToken = default);

/// <summary>
/// Retrieve daily team outputs for a period.
Expand Down
4 changes: 2 additions & 2 deletions src/PVOutput.Net/Modules/Interfaces/IStatusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ public interface IStatusService
/// Deletes all statuses on the specified date.
/// <para>See the official <see href="https://pvoutput.org/help.html#api-deletestatus">API information</see>.</para>
/// </summary>
/// <param name="date">The date to delete all statuses for. This can only be today or yesterday.</param>
/// <param name="statusDate">The date to delete all statuses for. This can only be today or yesterday.</param>
/// <param name="cancellationToken">A cancellation token for the request.</param>
/// <returns>If the operation succeeded.</returns>
Task<PVOutputBasicResponse> DeleteAllStatusesOnDateAsync(DateTime date, CancellationToken cancellationToken = default);
Task<PVOutputBasicResponse> DeleteAllStatusesOnDateAsync(DateTime statusDate, CancellationToken cancellationToken = default);
}
}
16 changes: 8 additions & 8 deletions src/PVOutput.Net/Modules/OutputService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,20 @@ internal OutputService(PVOutputClient client) : base(client)
}

/// <inheritdoc />
public Task<PVOutputResponse<IOutput>> GetOutputForDateAsync(DateTime date, bool getInsolation = false, int? systemId = null, CancellationToken cancellationToken = default)
public Task<PVOutputResponse<IOutput>> GetOutputForDateAsync(DateTime outputDate, bool getInsolation = false, int? systemId = null, CancellationToken cancellationToken = default)
{
var loggingScope = new Dictionary<string, object>()
{
[LoggingEvents.RequestId] = LoggingEvents.OutputService_GetOutputForDate,
[LoggingEvents.Parameter_Date] = date,
[LoggingEvents.Parameter_Date] = outputDate,
[LoggingEvents.Parameter_GetInsolation] = getInsolation,
[LoggingEvents.Parameter_SystemId] = systemId
};

Guard.Argument(date, nameof(date)).Max(DateTime.Today);
Guard.Argument(outputDate, nameof(outputDate)).Max(DateTime.Today);

var handler = new RequestHandler(Client);
return handler.ExecuteSingleItemRequestAsync<IOutput>(new OutputRequest { FromDate = date, ToDate = date, SystemId = systemId, Insolation = getInsolation }, loggingScope, cancellationToken);
return handler.ExecuteSingleItemRequestAsync<IOutput>(new OutputRequest { FromDate = outputDate, ToDate = outputDate, SystemId = systemId, Insolation = getInsolation }, loggingScope, cancellationToken);
}

/// <inheritdoc />
Expand All @@ -56,19 +56,19 @@ public Task<PVOutputArrayResponse<IOutput>> GetOutputsForPeriodAsync(DateTime fr
}

/// <inheritdoc />
public Task<PVOutputResponse<ITeamOutput>> GetTeamOutputForDateAsync(DateTime date, int teamId, CancellationToken cancellationToken = default)
public Task<PVOutputResponse<ITeamOutput>> GetTeamOutputForDateAsync(DateTime outputDate, int teamId, CancellationToken cancellationToken = default)
{
var loggingScope = new Dictionary<string, object>()
{
[LoggingEvents.RequestId] = LoggingEvents.OutputService_GetTeamOutputForDate,
[LoggingEvents.Parameter_Date] = date,
[LoggingEvents.Parameter_Date] = outputDate,
[LoggingEvents.Parameter_TeamId] = teamId
};

Guard.Argument(date, nameof(date)).Max(DateTime.Today);
Guard.Argument(outputDate, nameof(outputDate)).Max(DateTime.Today);

var handler = new RequestHandler(Client);
return handler.ExecuteSingleItemRequestAsync<ITeamOutput>(new OutputRequest { FromDate = date, ToDate = date, TeamId = teamId }, loggingScope, cancellationToken);
return handler.ExecuteSingleItemRequestAsync<ITeamOutput>(new OutputRequest { FromDate = outputDate, ToDate = outputDate, TeamId = teamId }, loggingScope, cancellationToken);
}

/// <inheritdoc />
Expand Down
8 changes: 4 additions & 4 deletions src/PVOutput.Net/Modules/StatusService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ public Task<PVOutputBasicResponse> DeleteStatusAsync(DateTime moment, Cancellati
}

/// <inheritdoc />
public Task<PVOutputBasicResponse> DeleteAllStatusesOnDateAsync(DateTime date, CancellationToken cancellationToken = default)
public Task<PVOutputBasicResponse> DeleteAllStatusesOnDateAsync(DateTime statusDate, CancellationToken cancellationToken = default)
{
var loggingScope = new Dictionary<string, object>()
{
[LoggingEvents.RequestId] = LoggingEvents.StatusService_DeleteStatus,
[LoggingEvents.Parameter_Date] = date
[LoggingEvents.Parameter_Date] = statusDate
};

Guard.Argument(date, nameof(date)).IsNoFutureDate().Min(DateTime.Today.AddDays(-1)).NoTimeComponent();
Guard.Argument(statusDate, nameof(statusDate)).IsNoFutureDate().Min(DateTime.Today.AddDays(-1)).NoTimeComponent();

var handler = new RequestHandler(Client);
return handler.ExecutePostRequestAsync(new DeleteStatusRequest() { Timestamp = date, CompleteDate = true }, loggingScope, cancellationToken);
return handler.ExecutePostRequestAsync(new DeleteStatusRequest() { Timestamp = statusDate, CompleteDate = true }, loggingScope, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public override async Task<IEnumerable<TObjectType>> ReadArrayAsync(TextReader r

while (reader.Peek() >= 0)
{
var line = reader.ReadLine();
var line = await reader.ReadLineAsync().ConfigureAwait(false);
await ReadAndAddObjectAsync(objectReader, results, line, cancellationToken).ConfigureAwait(false);
}

Expand Down
1 change: 1 addition & 0 deletions src/PVOutput.Net/Objects/Core/LoggingEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ internal class LoggingEvents
public static readonly EventId Handler_ReceivedResponseContent = new EventId(10002, "ReceivedResponseContent");
public static readonly EventId Handler_RequestStatusSuccesful = new EventId(10003, "RequestStatusSuccesful");
public static readonly EventId Handler_RequestStatusFailed = new EventId(10004, "RequestStatusFailed");
public static readonly EventId Handler_ApiInformation = new EventId(10005, "ApiInformation");

/*
* Module specific event IDs per request
Expand Down
Loading

0 comments on commit 2b36de7

Please sign in to comment.