Skip to content

Commit

Permalink
Fix all errors and made a lot of class internal
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenjonc committed Jan 4, 2023
1 parent ebcdfe3 commit 68db37f
Show file tree
Hide file tree
Showing 50 changed files with 76 additions and 71 deletions.
2 changes: 1 addition & 1 deletion SynoAI.Tests/SynoAI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<IsPackable>false</IsPackable>
<ImplicitUsings>enable</ImplicitUsings>
<RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
<AnalysisLevel>latest-recommended</AnalysisLevel>
<AnalysisLevel>6.0-recommended</AnalysisLevel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/AIs/AI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SynoAI.AIs
{
public abstract class AI
internal abstract class AI
{
public abstract Task<IEnumerable<AIPrediction>> Process(ILogger logger, Camera camera, byte[] image);
}
Expand Down
8 changes: 4 additions & 4 deletions SynoAI/AIs/DeepStack/DeepStackAI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

namespace SynoAI.AIs.DeepStack
{
public class DeepStackAI : AI
internal class DeepStackAI : AI
{
public async override Task<IEnumerable<AIPrediction>> Process(ILogger logger, Camera camera, byte[] image)
public override async Task<IEnumerable<AIPrediction>> Process(ILogger logger, Camera camera, byte[] image)
{
Stopwatch stopwatch = Stopwatch.StartNew();

Expand Down Expand Up @@ -69,7 +69,7 @@ public async override Task<IEnumerable<AIPrediction>> Process(ILogger logger, Ca
/// <param name="basePath"></param>
/// <param name="resourcePath"></param>
/// <returns>A <see cref="Uri"/> for the combined base and resource.</returns>
protected Uri GetUri(string basePath, string resourcePath)
protected static Uri GetUri(string basePath, string resourcePath)
{
Uri baseUri = new(basePath);
return new Uri(baseUri, resourcePath);
Expand All @@ -82,7 +82,7 @@ protected Uri GetUri(string basePath, string resourcePath)
/// <param name="message">The message to parse.</param>
/// <param name="logger"></param>
/// <returns>A usable object.</returns>
private async Task<DeepStackResponse> GetResponse(ILogger logger, Camera camera, HttpResponseMessage message)
private static async Task<DeepStackResponse> GetResponse(ILogger logger, Camera camera, HttpResponseMessage message)
{
string content = await message.Content.ReadAsStringAsync();
logger.LogDebug($"{camera.Name}: DeepStackAI: Responded with {content}.");
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/App/HttpClientWrapper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.App
{
public class HttpClientWrapper : HttpClient, IHttpClient
internal class HttpClientWrapper : HttpClient, IHttpClient
{
}
}
2 changes: 1 addition & 1 deletion SynoAI/App/Shared.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.App
{
public static class Shared
internal static class Shared
{
public static IHttpClient HttpClient = new HttpClientWrapper();
}
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SynoAI
/// <summary>
/// Represents the system configuration.
/// </summary>
public static class Config
internal static class Config
{
/// <summary>
/// The URL to the synology API.
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Constants.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI
{
public static class Constants
internal static class Constants
{
public const string DIRECTORY_CAPTURES = "Captures";
}
Expand Down
8 changes: 4 additions & 4 deletions SynoAI/Controllers/CameraController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ public async void Get(string id)

// Save the original unprocessed image if required
if (Config.SaveOriginalSnapshot == SaveSnapshotMode.Always ||
(Config.SaveOriginalSnapshot == SaveSnapshotMode.WithPredictions && predictions.Count() > 0) ||
(Config.SaveOriginalSnapshot == SaveSnapshotMode.WithValidPredictions && validPredictions.Count() > 0))
(Config.SaveOriginalSnapshot == SaveSnapshotMode.WithPredictions && predictions.Any()) ||
(Config.SaveOriginalSnapshot == SaveSnapshotMode.WithValidPredictions && validPredictions.Any()))
{
_logger.LogInformation($"{id}: Saving original image");
SnapshotManager.SaveOriginalImage(_logger, camera, snapshot);
Expand Down Expand Up @@ -271,7 +271,7 @@ public void Post(string id, [FromBody]CameraOptionsDto options)
private bool ShouldIncludePrediction(string id, Camera camera, Stopwatch overallStopwatch, AIPrediction prediction)
{
// Check if the prediction falls within the exclusion zones
if (camera.Exclusions != null && camera.Exclusions.Count() > 0)
if (camera.Exclusions != null && camera.Exclusions.Any())
{
Rectangle boundary = new(prediction.MinX, prediction.MinY, prediction.SizeX, prediction.SizeY);
foreach (Zone exclusion in camera.Exclusions)
Expand Down Expand Up @@ -390,7 +390,7 @@ private byte[] PreProcessSnapshot(Camera camera, byte[] snapshot)
/// <param name="bitmap">The bitmap to rotate.</param>
/// <param name="angle">The angle to rotate to.</param>
/// <returns>The rotated bitmap.</returns>
private SKBitmap Rotate(SKBitmap bitmap, double angle)
private static SKBitmap Rotate(SKBitmap bitmap, double angle)
{
double radians = Math.PI * angle / 180;
float sine = (float)Math.Abs(Math.Sin(radians));
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private static int GetObjects(string filename)
if (index != -1)
{
//try to extract the number of valid objects predicted inside this snapshot
if (!int.TryParse(name.Substring(index + 1), out objects))
if (!int.TryParse(name.AsSpan(index + 1), out objects))
objects = 0;
}
else
Expand Down
4 changes: 2 additions & 2 deletions SynoAI/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace SynoAI.Extensions
{
public static class StringExtensions
internal static class StringExtensions
{
public static string FirstCharToUpper(this string input) =>
input switch
{
null => throw new ArgumentNullException(nameof(input)),
"" => throw new ArgumentException($"{nameof(input)} cannot be empty", nameof(input)),
_ => input.First().ToString().ToUpper() + input.Substring(1)
_ => string.Concat(input.First().ToString().ToUpper(), input.AsSpan(1))
};
}
}
1 change: 1 addition & 0 deletions SynoAI/Models/Camera.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ public int GetDelayAfterSuccess()
return DelayAfterSuccess ?? Config.DelayAfterSuccess ?? GetDelay();
}

/// <inheritdoc />
public override string ToString()
{
return Name;
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Models/CameraQuality.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.Models
{
public enum CameraQuality
internal enum CameraQuality
{
High = 0,
Balanced = 1,
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Models/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SynoAI.Models
{
public class Notification
internal class Notification
{
/// <summary>
/// Object for fetching the processed image
Expand Down
5 changes: 5 additions & 0 deletions SynoAI/Models/ProcessedImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ public class ProcessedImage
/// </summary>
public readonly string FileName;

/// <summary>
/// Create a ProcessedImage
/// </summary>
/// <param name="filePath"></param>
/// <exception cref="ArgumentNullException">When filePath is null</exception>
public ProcessedImage(string filePath)
{
if (string.IsNullOrWhiteSpace(filePath)) throw new ArgumentNullException(nameof(filePath));
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Models/SaveSnapshotMode.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.Models
{
public enum SaveSnapshotMode
internal enum SaveSnapshotMode
{
/// <summary>
/// The snapshots are never saved.
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Models/SynologyApiInfoResponse.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.Models
{
public class SynologyApiInfoResponse : Dictionary<string, SynologyApiInfo>
internal class SynologyApiInfoResponse : Dictionary<string, SynologyApiInfo>
{
}
}
2 changes: 1 addition & 1 deletion SynoAI/Models/SynologyCameras.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.Models
{
public class SynologyCameras
internal class SynologyCameras
{
public IEnumerable<SynologyCamera> Cameras { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Models/SynologyError.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.Models
{
public class SynologyError
internal class SynologyError
{
public string Code { get; set; }
}
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Models/SynologyLogin.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.Models
{
public class SynologyLogin
internal class SynologyLogin
{
public string SID { get; set; }
}
Expand Down
4 changes: 2 additions & 2 deletions SynoAI/Models/SynologyResponse.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
namespace SynoAI.Models
{
public class SynologyResponse<T> : SynologyResponse
internal class SynologyResponse<T> : SynologyResponse
{
public T Data { get; set; }
}

public class SynologyResponse
internal class SynologyResponse
{
public bool Success { get; set; }
public SynologyError Error { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions SynoAI/Notifiers/Discord/Discord.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace SynoAI.Notifiers.Discord
{
public class Discord : NotifierBase
internal class Discord : NotifierBase
{
/// <summary>
/// Discord Webhook Url.
Expand All @@ -25,7 +25,7 @@ public override async Task SendAsync(Camera camera, Notification notification, I
HttpResponseMessage responseMessage = await Shared.HttpClient.PostAsync(Url, formData);
if (responseMessage.IsSuccessStatusCode)
{
logger.LogInformation($"{camera.Name}: Discord: Notification sent successfully");
logger.LogInformation("{CameraName}: Discord: Notification sent successfully", camera.Name);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Notifiers/Discord/DiscordFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.Notifiers.Discord
{
public class DiscordFactory : NotifierFactory
internal class DiscordFactory : NotifierFactory
{
public override INotifier Create(ILogger logger, IConfigurationSection section)
{
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Notifiers/Email/Email.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SynoAI.Notifiers.Email
/// <summary>
/// Calls a third party API.
/// </summary>
public class Email : NotifierBase
internal class Email : NotifierBase
{
/// <summary>
/// The email address to send the notification from.
Expand Down
4 changes: 2 additions & 2 deletions SynoAI/Notifiers/Email/EmailFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SynoAI.Notifiers.Email
{
public class EmailFactory : NotifierFactory
internal class EmailFactory : NotifierFactory
{
public override INotifier Create(ILogger logger, IConfigurationSection section)
{
Expand Down Expand Up @@ -31,7 +31,7 @@ public override INotifier Create(ILogger logger, IConfigurationSection section)
}
}

private SecureSocketOptions GetSecureSocketOptions(ILogger logger, IConfigurationSection section)
private static SecureSocketOptions GetSecureSocketOptions(ILogger logger, IConfigurationSection section)
{
string options = section.GetValue<string>("Encryption", "None").ToUpper();

Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Notifiers/INotifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SynoAI.Notifiers
{
public interface INotifier
internal interface INotifier
{
/// <summary>
/// The list of camera names that the notifier is for.
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Notifiers/Mqtt/Mqtt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace SynoAI.Notifiers.Mqtt
/// <summary>
/// Sends a message over MQTT.
/// </summary>
public sealed class Mqtt : NotifierBase
internal sealed class Mqtt : NotifierBase
{
/// <summary>
/// The username when using Basic authentication.
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Notifiers/Mqtt/MqttFactory.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.Notifiers.Mqtt
{
public class MqttFactory : NotifierFactory
internal class MqttFactory : NotifierFactory
{
public override INotifier Create(ILogger logger, IConfigurationSection section)
{
Expand Down
12 changes: 6 additions & 6 deletions SynoAI/Notifiers/NotifierBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace SynoAI.Notifiers
{
public abstract class NotifierBase : INotifier
internal abstract class NotifierBase : INotifier
{
public IEnumerable<string> Cameras { get; set; }
public IEnumerable<string> Types { get; set; }
Expand All @@ -16,7 +16,7 @@ public abstract class NotifierBase : INotifier

public virtual Task CleanupAsync(ILogger logger) { return Task.CompletedTask; }

protected string GetMessage(Camera camera, IEnumerable<string> foundTypes, string errorMessage = null)
protected static string GetMessage(Camera camera, IEnumerable<string> foundTypes, string errorMessage = null)
{
string result ;
if (Config.AlternativeLabelling && Config.DrawMode == DrawMode.Matches)
Expand Down Expand Up @@ -53,7 +53,7 @@ protected string GetMessage(Camera camera, IEnumerable<string> foundTypes, strin
return result;
}

protected string GetImageUrl(Camera camera, Notification notification)
protected static string GetImageUrl(Camera camera, Notification notification)
{
if (Config.SynoAIUrL == null)
{
Expand All @@ -69,7 +69,7 @@ protected string GetImageUrl(Camera camera, Notification notification)
/// <summary>
/// Generates a JSON representation of the notification.
/// </summary>
protected string GenerateJSON(Camera camera, Notification notification, bool sendImage)
protected static string GenerateJSON(Camera camera, Notification notification, bool sendImage)
{
dynamic jsonObject = new ExpandoObject();

Expand All @@ -95,7 +95,7 @@ protected string GenerateJSON(Camera camera, Notification notification, bool sen
/// <summary>
/// Returns FileStream data as a base64-encoded string
/// </summary>
private string ToBase64String(FileStream fileStream)
private static string ToBase64String(FileStream fileStream)
{
byte[] buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, (int)fileStream.Length);
Expand All @@ -108,7 +108,7 @@ private string ToBase64String(FileStream fileStream)
/// </summary>
/// <param name="message">The message to parse.</param>
/// <returns>A usable object.</returns>
protected async Task<T> GetResponse<T>(HttpResponseMessage message)
protected static async Task<T> GetResponse<T>(HttpResponseMessage message)
{
string content = await message.Content.ReadAsStringAsync();
return JsonConvert.DeserializeObject<T>(content);
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Notifiers/NotifierFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace SynoAI.Notifiers
/// <summary>
/// Handles the construction of the notifiers.
/// </summary>
public abstract class NotifierFactory
internal abstract class NotifierFactory
{
public abstract INotifier Create(ILogger logger, IConfigurationSection section);

Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Notifiers/Pushbullet/Pushbullet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace SynoAI.Notifiers.Pushbullet
/// Configuration for sending a Pushbullet notification.
/// https://docs.pushbullet.com/
/// </summary>
public class Pushbullet : NotifierBase
internal class Pushbullet : NotifierBase
{
//private const int MAX_FILE_SIZE = 26214400;

Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Notifiers/Pushbullet/PushbulletError.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace SynoAI.Notifiers.Pushbullet
{
public class PushbulletError
internal class PushbulletError
{
public string Code { get; set; }
public string Type { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion SynoAI/Notifiers/Pushbullet/PushbulletErrorResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace SynoAI.Notifiers.Pushbullet
{
public class PushbulletErrorResponse
internal class PushbulletErrorResponse
{
public PushbulletError Error { get; set; }
[JsonProperty("error_code")]
Expand Down
Loading

0 comments on commit 68db37f

Please sign in to comment.