-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
98f3878
commit 3543a3b
Showing
69 changed files
with
1,550 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
Web/storage | ||
Web/bin | ||
Web/obj | ||
Monitor/storage | ||
Monitor/bin | ||
Monitor/obj |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.EntityFrameworkCore.ChangeTracking; | ||
using Monitor.Context.Entities; | ||
|
||
namespace Monitor.Context; | ||
|
||
public class DataContext : DbContext | ||
{ | ||
public required DbSet<Weather> Weathers { get; set; } | ||
|
||
public required DbSet<Mppt> Mppts { get; set; } | ||
|
||
public required DbSet<Entities.System> Systems { get; set; } | ||
|
||
public DataContext(DbContextOptions<DataContext> options) : base(options) {} | ||
|
||
public override int SaveChanges() | ||
{ | ||
ComputeEntitiesBeforeSaveChanges(); | ||
|
||
return base.SaveChanges(); | ||
} | ||
|
||
private void ComputeEntitiesBeforeSaveChanges() | ||
{ | ||
foreach (EntityEntry entityEntry in ChangeTracker.Entries()) | ||
{ | ||
if (entityEntry.Entity is IEntity entity) | ||
{ | ||
switch (entityEntry.State) | ||
{ | ||
case EntityState.Added: | ||
entity.CreatedAt = DateTime.UtcNow; | ||
break; | ||
|
||
} | ||
} | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
Monitor/Web/Context/Entities/IEntity.cs → Monitor/Monitor/Context/Entities/IEntity.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Web.Context.Entities; | ||
namespace Monitor.Context.Entities; | ||
|
||
public interface IEntity | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
Monitor/Web/Context/Entities/Mppt.cs → Monitor/Monitor/Context/Entities/Mppt.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace Monitor.Context.Entities; | ||
|
||
public class System : IEntity | ||
{ | ||
public long Id { get; set; } | ||
public DateTime CreatedAt { get; set; } | ||
|
||
public bool Npr { get; set; } | ||
|
||
public bool Wifi { get; set; } | ||
|
||
public bool BoxOpened { get; set; } | ||
|
||
public long Uptime { get; set; } | ||
|
||
public long McuUptime { get; set; } | ||
} |
2 changes: 1 addition & 1 deletion
2
Monitor/Web/Context/Entities/Weather.cs → Monitor/Monitor/Context/Entities/Weather.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Monitor.Controllers; | ||
|
||
public abstract class AController : Controller | ||
{ | ||
protected readonly ILogger<AController> Logger; | ||
|
||
protected AController(ILogger<AController> logger) | ||
{ | ||
Logger = logger; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Monitor.Services; | ||
|
||
namespace Monitor.Controllers; | ||
|
||
[Route("gpio")] | ||
public class GpioController : AController | ||
{ | ||
private readonly SerialMessageService _serialMessageService; | ||
|
||
public GpioController(ILogger<GpioController> logger, SerialMessageService serialMessageService) : base(logger) | ||
{ | ||
_serialMessageService = serialMessageService; | ||
} | ||
|
||
[Route("wifi/{enabled}")] | ||
public void Wifi(bool enabled) | ||
{ | ||
Logger.LogInformation("From web, set wifi to {enabled}", enabled); | ||
|
||
_serialMessageService.SetWifi(enabled); | ||
} | ||
|
||
[Route("npr/{enabled}")] | ||
public void Npr(bool enabled) | ||
{ | ||
Logger.LogInformation("From web, set npr to {enabled}", enabled); | ||
|
||
_serialMessageService.SetNpr(enabled); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using Microsoft.AspNetCore.Mvc; | ||
using Monitor.Models.Views; | ||
using Monitor.Services; | ||
|
||
namespace Monitor.Controllers; | ||
|
||
public class HomeController : AController | ||
{ | ||
private readonly CameraService _cameraService; | ||
|
||
public HomeController(ILogger<HomeController> logger, CameraService cameraService) : base(logger) | ||
{ | ||
_cameraService = cameraService; | ||
} | ||
|
||
public IActionResult Index() | ||
{ | ||
return View(new HomeModel | ||
{ | ||
State = MonitorService.State, | ||
LastPhoto = _cameraService.GetLast() | ||
}); | ||
} | ||
} |
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...or/Web/Exceptions/HttpRequestException.cs → ...onitor/Exceptions/HttpRequestException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Web.Exceptions; | ||
namespace Monitor.Exceptions; | ||
|
||
public class HttpRequestException : Exception | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
...r/Web/Exceptions/MessageParseException.cs → ...nitor/Exceptions/MessageParseException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
namespace Web.Exceptions; | ||
namespace Monitor.Exceptions; | ||
|
||
public class MessageParseException : Exception | ||
{ | ||
|
2 changes: 1 addition & 1 deletion
2
...ceptions/MissingConfigurationException.cs → ...ceptions/MissingConfigurationException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...Web/Extensions/ConfigurationExtensions.cs → ...tor/Extensions/ConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...ations/20230519165529_Initial.Designer.cs → ...ations/20230519165529_Initial.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
118 changes: 118 additions & 0 deletions
118
Monitor/Monitor/Migrations/20230525192341_AddSystem.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using Microsoft.EntityFrameworkCore.Migrations; | ||
|
||
#nullable disable | ||
|
||
namespace Monitor.Migrations | ||
{ | ||
/// <inheritdoc /> | ||
public partial class AddSystem : Migration | ||
{ | ||
/// <inheritdoc /> | ||
protected override void Up(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.CreateTable( | ||
name: "Systems", | ||
columns: table => new | ||
{ | ||
Id = table.Column<long>(type: "INTEGER", nullable: false) | ||
.Annotation("Sqlite:Autoincrement", true), | ||
CreatedAt = table.Column<DateTime>(type: "TEXT", nullable: false), | ||
Npr = table.Column<bool>(type: "INTEGER", nullable: false), | ||
Wifi = table.Column<bool>(type: "INTEGER", nullable: false), | ||
BoxOpened = table.Column<bool>(type: "INTEGER", nullable: false), | ||
Uptime = table.Column<TimeSpan>(type: "TEXT", nullable: false), | ||
McuUptime = table.Column<TimeSpan>(type: "TEXT", nullable: false) | ||
}, | ||
constraints: table => | ||
{ | ||
table.PrimaryKey("PK_Systems", x => x.Id); | ||
}); | ||
} | ||
|
||
/// <inheritdoc /> | ||
protected override void Down(MigrationBuilder migrationBuilder) | ||
{ | ||
migrationBuilder.DropTable( | ||
name: "Systems"); | ||
} | ||
} | ||
} |
Oops, something went wrong.