Skip to content

Commit

Permalink
Small code refactors and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
daleghent committed Jan 29, 2023
1 parent 0f09ca0 commit 415c962
Show file tree
Hide file tree
Showing 19 changed files with 69 additions and 69 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Ground Station

## 2.2.0.0 - UNRELEASED
* Small code refactors and cleanups

## 2.1.0.0 - 2022-11-26
* Pushover client library replaced with internal one (Credit: Stefan Berg)
* Replacing the internal Pushover client allows the implementation of Emergency priority messages for Pushover:
Expand Down
3 changes: 2 additions & 1 deletion Email/FailuresToEmailTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public override void Teardown() {

public void Dispose() {
queueWorker.Dispose();
GC.SuppressFinalize(this);
}

public override void AfterParentChanged() {
Expand Down Expand Up @@ -248,7 +249,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
2 changes: 1 addition & 1 deletion Email/SendToEmail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
2 changes: 1 addition & 1 deletion HTTP/HttpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
5 changes: 3 additions & 2 deletions IFTTT/FailuresToIftttTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public FailuresToIftttTrigger(FailuresToIftttTrigger copyMe) : this(
public string EventName {
get => eventName;
set {
if (value.Contains("/") || value.Contains(" ")) {
if (value.Contains('/') || value.Contains(' ')) {
RaisePropertyChanged();
return;
}
Expand All @@ -139,6 +139,7 @@ public override void Teardown() {

public void Dispose() {
queueWorker.Dispose();
GC.SuppressFinalize(this);
}

public override void AfterParentChanged() {
Expand Down Expand Up @@ -240,7 +241,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
6 changes: 3 additions & 3 deletions IFTTT/SendToIftttWebhook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace DaleGhent.NINA.GroundStation.SendToIftttWebhook {
[Export(typeof(ISequenceItem))]
[JsonObject(MemberSerialization.OptIn)]
public class SendToIftttWebhook : SequenceItem, IValidatable {
private IftttCommon ifttt;
private readonly IftttCommon ifttt;
private string eventName = "nina";
private string value1 = string.Empty;
private string value2 = string.Empty;
Expand Down Expand Up @@ -109,7 +109,7 @@ public SendToIftttWebhook(SendToIftttWebhook copyMe) : this(cameraMediator: copy
public string EventName {
get => eventName;
set {
if (!value.Contains("/")) {
if (!value.Contains('/')) {
eventName = value;
}

Expand Down Expand Up @@ -165,7 +165,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
5 changes: 3 additions & 2 deletions MQTT/FailuresToMqttTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public override void Teardown() {

public void Dispose() {
queueWorker.Dispose();
GC.SuppressFinalize(this);
}

public override void AfterParentChanged() {
Expand Down Expand Up @@ -179,7 +180,7 @@ private async Task WorkerFn(SequenceEntityFailureEventArgs item, CancellationTok
}
}

public IList<string> QoSLevels => MqttCommon.QoSLevels;
public static IList<string> QoSLevels => MqttCommon.QoSLevels;

public override Task Execute(ISequenceContainer context, IProgress<ApplicationStatus> progress, CancellationToken ct) {
return Task.CompletedTask;
Expand All @@ -204,7 +205,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
2 changes: 1 addition & 1 deletion MQTT/MqttClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This Source Code Form is subject to the terms of the Mozilla Public
namespace DaleGhent.NINA.GroundStation.Mqtt {

internal class MqttClient {
private IMqttClient mqttClient;
private readonly IMqttClient mqttClient;

public MqttClient() {
var mqttFactory = new MqttFactory();
Expand Down
6 changes: 3 additions & 3 deletions MQTT/SendToMqtt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace DaleGhent.NINA.GroundStation.SendToMqtt {
[Export(typeof(ISequenceItem))]
[JsonObject(MemberSerialization.OptIn)]
public class SendToMqtt : SequenceItem, IValidatable {
private MqttCommon mqtt;
private readonly MqttCommon mqtt;
private string topic;
private string payload = string.Empty;
private int qos = 0;
Expand Down Expand Up @@ -136,7 +136,7 @@ public int QoS {
}
}

public IList<string> QoSLevels => MqttCommon.QoSLevels;
public static IList<string> QoSLevels => MqttCommon.QoSLevels;

public override async Task Execute(IProgress<ApplicationStatus> progress, CancellationToken ct) {
var payload = Utilities.Utilities.ResolveTokens(Payload, this, metadata);
Expand All @@ -160,7 +160,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
9 changes: 2 additions & 7 deletions MetadataClient/Metadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,10 @@ This Source Code Form is subject to the terms of the Mozilla Public
using NINA.Equipment.Equipment.MyTelescope;
using NINA.Equipment.Equipment.MyWeatherData;
using NINA.Equipment.Interfaces.Mediator;
using NINA.WPF.Base.Mediator;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DaleGhent.NINA.GroundStation.MetadataClient {

public class Metadata : IMetadata {
private readonly ICameraMediator cameraMediator;
private readonly IDomeMediator domeMediator;
Expand Down Expand Up @@ -81,4 +76,4 @@ public Metadata(ICameraMediator cameraMediator,
public WeatherDataInfo WeatherDataInfo => weatherDataMediator.GetInfo();
public CultureInfo CultureInfo { get; set; } = CultureInfo.InvariantCulture;
}
}
}
7 changes: 4 additions & 3 deletions Pushover/FailuresToPushoverTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ public override void Teardown() {

public void Dispose() {
queueWorker.Dispose();
GC.SuppressFinalize(this);
}

public override void AfterParentChanged() {
Expand Down Expand Up @@ -223,8 +224,8 @@ public NotificationSound NotificationSound {
}
}

public Priority[] Priorities => Enum.GetValues(typeof(Priority)).Cast<Priority>().ToArray();
public NotificationSound[] NotificationSounds => Enum.GetValues(typeof(NotificationSound)).Cast<NotificationSound>().Where(p => p != NotificationSound.NotSet).ToArray();
public static Priority[] Priorities => Enum.GetValues(typeof(Priority)).Cast<Priority>().ToArray();
public static NotificationSound[] NotificationSounds => Enum.GetValues(typeof(NotificationSound)).Cast<NotificationSound>().Where(p => p != NotificationSound.NotSet).ToArray();

public override Task Execute(ISequenceContainer context, IProgress<ApplicationStatus> progress, CancellationToken ct) {
return Task.CompletedTask;
Expand All @@ -245,7 +246,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
4 changes: 2 additions & 2 deletions Pushover/SendToPushover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace DaleGhent.NINA.GroundStation.SendToPushover {
[Export(typeof(ISequenceItem))]
[JsonObject(MemberSerialization.OptIn)]
public class SendToPushover : SequenceItem, IValidatable {
private PushoverClient.PushoverClient pushover;
private readonly PushoverClient.PushoverClient pushover;
private string title = string.Empty;
private string message = string.Empty;
private Priority priority;
Expand Down Expand Up @@ -172,7 +172,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
3 changes: 2 additions & 1 deletion TTS/FailuresToTTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ public override void Teardown() {

public void Dispose() {
queueWorker.Dispose();
GC.SuppressFinalize(this);
}

public override void AfterParentChanged() {
Expand Down Expand Up @@ -217,7 +218,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
2 changes: 1 addition & 1 deletion TTS/SendToTTS.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
3 changes: 2 additions & 1 deletion Telegram/FailuresToTelegramTrigger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ public override void Teardown() {

public void Dispose() {
queueWorker.Dispose();
GC.SuppressFinalize(this);
}

public override void AfterParentChanged() {
Expand Down Expand Up @@ -214,7 +215,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
4 changes: 2 additions & 2 deletions Telegram/SendToTelegram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace DaleGhent.NINA.GroundStation.SendToTelegram {
[Export(typeof(ISequenceItem))]
[JsonObject(MemberSerialization.OptIn)]
public class SendToTelegram : SequenceItem, IValidatable {
private TelegramCommon telegram;
private readonly TelegramCommon telegram;
private string message = string.Empty;
private bool doNotNotify = false;

Expand Down Expand Up @@ -137,7 +137,7 @@ public bool Validate() {

if (i != Issues) {
Issues = i;
RaisePropertyChanged("Issues");
RaisePropertyChanged(nameof(Issues));
}

return i.Count == 0;
Expand Down
3 changes: 2 additions & 1 deletion Utilities/BackgroundQueueWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace DaleGhent.NINA.GroundStation.Utilities {

internal class BackgroundQueueWorker<T> : IDisposable {
private int queueSize;
private readonly int queueSize;
private CancellationTokenSource workerCts;
private AsyncProducerConsumerQueue<T> messageQueue;
private Func<T, CancellationToken, Task> workerFn;
Expand Down Expand Up @@ -73,6 +73,7 @@ public async Task Start() {

public void Dispose() {
semaphore?.Dispose();
GC.SuppressFinalize(this);
}
}
}
3 changes: 0 additions & 3 deletions Utilities/FailedItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@ This Source Code Form is subject to the terms of the Mozilla Public
using NINA.Sequencer.Validations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DaleGhent.NINA.GroundStation.Utilities {

Expand Down
Loading

0 comments on commit 415c962

Please sign in to comment.