Compare commits
1 Commits
3b197f0b85
...
feature/da
| Author | SHA1 | Date | |
|---|---|---|---|
| 37dc8bed35 |
30
SmartHouse.Services/.dockerignore
Normal file
30
SmartHouse.Services/.dockerignore
Normal file
@@ -0,0 +1,30 @@
|
||||
**/.classpath
|
||||
**/.dockerignore
|
||||
**/.env
|
||||
**/.git
|
||||
**/.gitignore
|
||||
**/.project
|
||||
**/.settings
|
||||
**/.toolstarget
|
||||
**/.vs
|
||||
**/.vscode
|
||||
**/*.*proj.user
|
||||
**/*.dbmdl
|
||||
**/*.jfm
|
||||
**/azds.yaml
|
||||
**/bin
|
||||
**/charts
|
||||
**/docker-compose*
|
||||
**/Dockerfile*
|
||||
**/node_modules
|
||||
**/npm-debug.log
|
||||
**/obj
|
||||
**/secrets.dev.yaml
|
||||
**/values.dev.yaml
|
||||
LICENSE
|
||||
README.md
|
||||
!**/.gitignore
|
||||
!.git/HEAD
|
||||
!.git/config
|
||||
!.git/packed-refs
|
||||
!.git/refs/heads/**
|
||||
16
SmartHouse.Services/Program.cs
Normal file
16
SmartHouse.Services/Program.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SmartHouse.Services.Database.Models;
|
||||
|
||||
var host = Host.CreateDefaultBuilder(args)
|
||||
.ConfigureServices((context, services) =>
|
||||
{
|
||||
services.AddDbContext<SmartHouseContext>(options =>
|
||||
options.UseSqlServer(context.Configuration.GetConnectionString("SmartHouse")));
|
||||
|
||||
// services.AddHostedService<YourBackgroundService>();
|
||||
})
|
||||
.Build();
|
||||
|
||||
await host.RunAsync();
|
||||
@@ -0,0 +1,29 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SmartHouse.Services.Database.Models;
|
||||
|
||||
namespace SmartHouse.Services.Database.Data;
|
||||
|
||||
public partial class SmartHouseDbContext : DbContext
|
||||
{
|
||||
public SmartHouseDbContext()
|
||||
{
|
||||
}
|
||||
|
||||
public SmartHouseDbContext(DbContextOptions<SmartHouseDbContext> options)
|
||||
: base(options)
|
||||
{
|
||||
}
|
||||
|
||||
public virtual DbSet<DailyReading> DailyReadings { get; set; }
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
}
|
||||
|
||||
partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace SmartHouse.Services.Database.Entities
|
||||
{
|
||||
public class Device
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string Name { get; set; } = null!;
|
||||
public string? Location { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// <auto-generated> This file has been auto generated by EF Core Power Tools. </auto-generated>
|
||||
#nullable disable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace SmartHouse.Services.Database.Models;
|
||||
|
||||
[Table("DailyReading", Schema = "SunCast")]
|
||||
public partial class DailyReading
|
||||
{
|
||||
[Key]
|
||||
public int Id { get; set; }
|
||||
|
||||
public DateTime Date { get; set; }
|
||||
|
||||
public double SuncastValue { get; set; }
|
||||
|
||||
public double GrowattValue { get; set; }
|
||||
|
||||
public double DiffValue { get; set; }
|
||||
|
||||
public double DiffProcent { get; set; }
|
||||
}
|
||||
@@ -10,4 +10,8 @@
|
||||
<ProjectReference Include="..\SmartHouse.Services.ServiceDefaults\SmartHouse.Services.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.22" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"CodeGenerationMode": 4,
|
||||
"ContextClassName": "SmartHouseDbContext",
|
||||
"ContextNamespace": "",
|
||||
"FilterSchemas": false,
|
||||
"IncludeConnectionString": true,
|
||||
"IrregularWords": null,
|
||||
"MinimumProductVersion": "2.6.1301",
|
||||
"ModelNamespace": null,
|
||||
"OutputContextPath": "Data",
|
||||
"OutputPath": "Models",
|
||||
"PluralRules": null,
|
||||
"PreserveCasingWithRegex": true,
|
||||
"ProjectRootNamespace": "SmartHouse.Services.Database",
|
||||
"Schemas": null,
|
||||
"SelectedHandlebarsLanguage": 2,
|
||||
"SelectedToBeGenerated": 0,
|
||||
"SingularRules": null,
|
||||
"T4TemplatePath": null,
|
||||
"Tables": [
|
||||
{
|
||||
"Name": "[SunCast].[DailyReading]",
|
||||
"ObjectType": 0
|
||||
}
|
||||
],
|
||||
"UiHint": null,
|
||||
"UncountableWords": null,
|
||||
"UseAsyncStoredProcedureCalls": true,
|
||||
"UseBoolPropertiesWithoutDefaultSql": false,
|
||||
"UseDatabaseNames": true,
|
||||
"UseDatabaseNamesForRoutines": true,
|
||||
"UseDateOnlyTimeOnly": true,
|
||||
"UseDbContextSplitting": false,
|
||||
"UseDecimalDataAnnotationForSprocResult": true,
|
||||
"UseFluentApiOnly": false,
|
||||
"UseHandleBars": false,
|
||||
"UseHierarchyId": false,
|
||||
"UseInflector": true,
|
||||
"UseInternalAccessModifiersForSprocsAndFunctions": false,
|
||||
"UseLegacyPluralizer": false,
|
||||
"UseManyToManyEntity": true,
|
||||
"UseNoDefaultConstructor": false,
|
||||
"UseNoNavigations": false,
|
||||
"UseNoObjectFilter": false,
|
||||
"UseNodaTime": false,
|
||||
"UseNullableReferences": false,
|
||||
"UsePrefixNavigationNaming": false,
|
||||
"UseSchemaFolders": false,
|
||||
"UseSchemaNamespaces": false,
|
||||
"UseSpatial": false,
|
||||
"UseT4": false,
|
||||
"UseT4Split": false
|
||||
}
|
||||
28
SmartHouse.Services/SmartHouse.Services.DbUP/Dockerfile
Normal file
28
SmartHouse.Services/SmartHouse.Services.DbUP/Dockerfile
Normal file
@@ -0,0 +1,28 @@
|
||||
# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
|
||||
|
||||
# This stage is used when running from VS in fast mode (Default for Debug configuration)
|
||||
FROM mcr.microsoft.com/dotnet/runtime:10.0 AS base
|
||||
USER $APP_UID
|
||||
WORKDIR /app
|
||||
|
||||
|
||||
# This stage is used to build the service project
|
||||
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
WORKDIR /src
|
||||
COPY ["SmartHouse.Services.DbUP/SmartHouse.Services.DbUP.csproj", "SmartHouse.Services.DbUP/"]
|
||||
RUN dotnet restore "./SmartHouse.Services.DbUP/SmartHouse.Services.DbUP.csproj"
|
||||
COPY . .
|
||||
WORKDIR "/src/SmartHouse.Services.DbUP"
|
||||
RUN dotnet build "./SmartHouse.Services.DbUP.csproj" -c $BUILD_CONFIGURATION -o /app/build
|
||||
|
||||
# This stage is used to publish the service project to be copied to the final stage
|
||||
FROM build AS publish
|
||||
ARG BUILD_CONFIGURATION=Release
|
||||
RUN dotnet publish "./SmartHouse.Services.DbUP.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
|
||||
|
||||
# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
|
||||
FROM base AS final
|
||||
WORKDIR /app
|
||||
COPY --from=publish /app/publish .
|
||||
ENTRYPOINT ["dotnet", "SmartHouse.Services.DbUP.dll"]
|
||||
29
SmartHouse.Services/SmartHouse.Services.DbUP/Program.cs
Normal file
29
SmartHouse.Services/SmartHouse.Services.DbUP/Program.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using DbUp;
|
||||
using System.Reflection;
|
||||
|
||||
var connectionString = "Server=vps.maximuss.dk;Database=SmartHouse;Trusted_Connection=True;MultipleActiveResultSets=true";
|
||||
EnsureDatabase.For.SqlDatabase(connectionString);
|
||||
var upgrader =
|
||||
DeployChanges.To
|
||||
.SqlDatabase(connectionString)
|
||||
.WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
|
||||
.LogToConsole()
|
||||
.Build();
|
||||
|
||||
var result = upgrader.PerformUpgrade();
|
||||
|
||||
if (!result.Successful)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine(result.Error);
|
||||
Console.ResetColor();
|
||||
#if DEBUG
|
||||
Console.ReadLine();
|
||||
#endif
|
||||
return -1;
|
||||
}
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Console.WriteLine("Success!");
|
||||
Console.ResetColor();
|
||||
return 0;
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"profiles": {
|
||||
"SmartHouse.Services.DbUP": {
|
||||
"commandName": "Project"
|
||||
},
|
||||
"Container (Dockerfile)": {
|
||||
"commandName": "Docker"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
create schema SunCast
|
||||
@@ -0,0 +1,12 @@
|
||||
CREATE TABLE SunCast.DailyReading
|
||||
(
|
||||
Id int NOT NULL IDENTITY (1, 1),
|
||||
Date datetime2(7) NOT NULL,
|
||||
SuncastValue float(53) NOT NULL,
|
||||
GrowattValue float(53) NOT NULL,
|
||||
DiffValue float(53) NOT NULL,
|
||||
DiffProcent float(53) NOT NULL
|
||||
) ON [PRIMARY]
|
||||
GO
|
||||
ALTER TABLE SunCast.Dailyreading SET (LOCK_ESCALATION = TABLE)
|
||||
GO
|
||||
@@ -0,0 +1,5 @@
|
||||
ALTER TABLE SunCast.DailyReading ADD CONSTRAINT
|
||||
PK_DailyReading PRIMARY KEY CLUSTERED
|
||||
(
|
||||
Id
|
||||
) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
|
||||
@@ -0,0 +1,16 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="dbup" Version="5.0.41" />
|
||||
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.23.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,9 +1,13 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SmartHouse.Services.Database;
|
||||
using SmartHouse.Services.EVCharging;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.AddServiceDefaults();
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
//builder.Services.AddDbContext<SmartHouseDbContext>(options =>
|
||||
// options.UseSqlServer(builder.Configuration.GetConnectionString("SmartHouseDatabase")));
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
@@ -8,10 +8,14 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="dbup-sqlserver" Version="6.0.16" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SmartHouse.Services.Database\SmartHouse.Services.Database.csproj" />
|
||||
<ProjectReference Include="..\SmartHouse.Services.ServiceDefaults\SmartHouse.Services.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -1,10 +1,6 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SmartHouse.Services.Helper;
|
||||
|
||||
public interface IPerfLog
|
||||
{
|
||||
void Info(string message, params object[] args);
|
||||
void Warn(string message, params object[] args);
|
||||
}
|
||||
|
||||
public sealed class PerfLog : IPerfLog
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using NLog;
|
||||
using NLog.Extensions.Logging;
|
||||
using SmartHouse.Services.Helper;
|
||||
using SmartHouse.Services.Siemens;
|
||||
|
||||
// NLog internal bootstrap logger (til hvis noget går galt før hosten er oppe)
|
||||
|
||||
@@ -1,9 +1,14 @@
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SmartHouse.Services.Database;
|
||||
using SmartHouse.Services.Database.Data;
|
||||
using SmartHouse.Services.SunCast;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
|
||||
builder.AddServiceDefaults();
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
builder.Services.AddDbContext<SmartHouseDbContext>(options =>
|
||||
options.UseSqlServer(builder.Configuration.GetConnectionString("SmartHouseDatabase")));
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
@@ -8,10 +8,17 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="10.0.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\SmartHouse.Services.Database\SmartHouse.Services.Database.csproj" />
|
||||
<ProjectReference Include="..\SmartHouse.Services.ServiceDefaults\SmartHouse.Services.ServiceDefaults.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -4,5 +4,8 @@
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
},
|
||||
"ConnectionStrings": {
|
||||
"SmartHouse": "Data Source=localhost;Initial Catalog=SmartHouse;Integrated Security=True"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 18
|
||||
VisualStudioVersion = 18.1.11312.151 d18.0
|
||||
VisualStudioVersion = 18.1.11312.151
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.HomeAssistent", "SmartHouse.Services.HomeAssistent\SmartHouse.Services.HomeAssistent.csproj", "{5EE8D007-801D-4E7A-8F40-D89C7A61B5FD}"
|
||||
EndProject
|
||||
@@ -19,6 +19,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.Service
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.Helper", "SmartHouse.Services.Helper\SmartHouse.Services.Helper.csproj", "{119F70AB-85D8-4715-A41D-AD8509CEC551}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SmartHouse.Services.DbUP", "SmartHouse.Services.DbUP\SmartHouse.Services.DbUP.csproj", "{888E76E7-9AB3-4F05-99E5-ACDE1078A4C0}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -57,6 +59,10 @@ Global
|
||||
{119F70AB-85D8-4715-A41D-AD8509CEC551}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{119F70AB-85D8-4715-A41D-AD8509CEC551}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{119F70AB-85D8-4715-A41D-AD8509CEC551}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{888E76E7-9AB3-4F05-99E5-ACDE1078A4C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{888E76E7-9AB3-4F05-99E5-ACDE1078A4C0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{888E76E7-9AB3-4F05-99E5-ACDE1078A4C0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{888E76E7-9AB3-4F05-99E5-ACDE1078A4C0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
5
SmartHouse.Services/appsettings.json
Normal file
5
SmartHouse.Services/appsettings.json
Normal file
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"ConnectionStrings": {
|
||||
"SmartHouse": "Data Source=localhost;Initial Catalog=SmartHouse;Integrated Security=True"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user