Skip to content

Commit

Permalink
Merge pull request #278 from pkuehnel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
pkuehnel authored Sep 21, 2022
2 parents 21f5b9b + bc109dd commit 4555337
Show file tree
Hide file tree
Showing 79 changed files with 1,932 additions and 209 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@

public interface IDbConnectionStringHelper
{
string GetConnectionString();
string GetTeslaMateConnectionString();
string GetTeslaSolarChargerDbPath();
}
17 changes: 17 additions & 0 deletions TeslaSolarCharger.Model/Contracts/ITeslaSolarChargerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Infrastructure;
using TeslaSolarCharger.Model.Entities.TeslaSolarCharger;

namespace TeslaSolarCharger.Model.Contracts;

public interface ITeslaSolarChargerContext
{
DbSet<ChargePrice> ChargePrices { get; set; }
DbSet<HandledCharge> HandledCharges { get; set; }
DbSet<PowerDistribution> PowerDistributions { get; set; }
ChangeTracker ChangeTracker { get; }
Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken());
DatabaseFacade Database { get; }
void RejectChanges();
}
6 changes: 4 additions & 2 deletions TeslaSolarCharger.Model/Contracts/ITeslamateContext.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using Microsoft.EntityFrameworkCore;
using TeslaSolarCharger.Model.Entities;
using TeslaSolarCharger.Model.Entities.TeslaMate;

namespace TeslaSolarCharger.Model.Contracts;

Expand All @@ -18,4 +18,6 @@ public interface ITeslamateContext
DbSet<State> States { get; set; }
DbSet<Token> Tokens { get; set; }
DbSet<Update> Updates { get; set; }
}

Task<int> SaveChangesAsync(CancellationToken cancellationToken = new CancellationToken());
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class Address
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class Car
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class CarSetting
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class Charge
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class ChargingProcess
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class Drive
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class Geofence
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class Position
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class SchemaMigration
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class Setting
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class State
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class Token
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace TeslaSolarCharger.Model.Entities
namespace TeslaSolarCharger.Model.Entities.TeslaMate
{
public class Update
{
Expand Down
11 changes: 11 additions & 0 deletions TeslaSolarCharger.Model/Entities/TeslaSolarCharger/ChargePrice.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TeslaSolarCharger.Model.Entities.TeslaSolarCharger;

public class ChargePrice
{
public int Id { get; set; }
public DateTime ValidSince { get; set; }
public decimal SolarPrice { get; set; }
public decimal GridPrice { get; set; }

public List<HandledCharge> HandledCharges { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace TeslaSolarCharger.Model.Entities.TeslaSolarCharger;

public class HandledCharge
{
public int Id { get; set; }
public int ChargingProcessId { get; set; }
public int CarId { get; set; }
public decimal? UsedGridEnergy { get; set; }
public decimal? UsedSolarEnergy { get; set; }
public decimal? CalculatedPrice { get; set; }
public List<PowerDistribution> PowerDistributions { get; set; } = new();


public int ChargePriceId { get; set; }
public ChargePrice ChargePrice { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace TeslaSolarCharger.Model.Entities.TeslaSolarCharger;

public class PowerDistribution
{
public int Id { get; set; }
public DateTime TimeStamp { get; set; }
public int ChargingPower { get; set; }
public int PowerFromGrid { get; set; }
public float GridProportion { get; set; }

public int HandledChargeId { get; set; }
public HandledCharge HandledCharge { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ public DbConnectionStringHelper(ILogger<DbConnectionStringHelper> logger, IConfi
_configurationWrapper = configurationWrapper;
}

public string GetConnectionString()
public string GetTeslaMateConnectionString()
{
_logger.LogTrace("{method}()", nameof(GetConnectionString));
_logger.LogTrace("{method}()", nameof(GetTeslaMateConnectionString));
var server = _configurationWrapper.TeslaMateDbServer();
var port = _configurationWrapper.TeslaMateDbPort();
var databaseName = _configurationWrapper.TeslaMateDbDatabaseName();
Expand All @@ -27,4 +27,11 @@ public string GetConnectionString()
_logger.LogTrace("ConnectionString: {connectionString}", connectionString);
return connectionString;
}
}

public string GetTeslaSolarChargerDbPath()
{
_logger.LogTrace("{method}()", nameof(GetTeslaSolarChargerDbPath));
var connectionString = $"Data Source={_configurationWrapper.SqliteFileFullName()}";
return connectionString;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.EntityFrameworkCore;
using TeslaSolarCharger.Model.Contracts;
using TeslaSolarCharger.Model.Entities.TeslaSolarCharger;

namespace TeslaSolarCharger.Model.EntityFramework;

public class TeslaSolarChargerContext : DbContext, ITeslaSolarChargerContext
{
public DbSet<ChargePrice> ChargePrices { get; set; } = null!;
public DbSet<HandledCharge> HandledCharges { get; set; } = null!;
public DbSet<PowerDistribution> PowerDistributions { get; set; } = null!;

public string DbPath { get; }

public void RejectChanges()
{
foreach (var entry in ChangeTracker.Entries())
{
switch (entry.State)
{
case EntityState.Modified:
case EntityState.Deleted:
entry.State = EntityState.Modified; //Revert changes made to deleted entity.
entry.State = EntityState.Unchanged;
break;
case EntityState.Added:
entry.State = EntityState.Detached;
break;
}
}
}


public TeslaSolarChargerContext()
{
}

public TeslaSolarChargerContext(DbContextOptions<TeslaSolarChargerContext> options)
: base(options)
{
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Microsoft.EntityFrameworkCore;
using TeslaSolarCharger.Model.Contracts;
using TeslaSolarCharger.Model.Entities;
using TeslaSolarCharger.Model.Entities.TeslaMate;

namespace TeslaSolarCharger.Model.EntityFramework
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4555337

Please sign in to comment.