Compare commits

...

4 Commits

Author SHA1 Message Date
7754a77746 Merge branch 'migrate_net8' 2024-09-20 10:56:51 +05:00
89e215aec3 Migrape API to NET8
Use entity schema from root, add controller, add CORS for proxy
2024-09-20 10:54:32 +05:00
b5688b9b94 Move entity schema
Move classes for work with DB in root dir. Fix problems with num cycles, after change to Enum
2024-09-20 10:51:24 +05:00
9dbd0f39fe Migrate to .NET8 GenCycleVDP
Migrate generator to .NET8
2024-09-19 13:26:06 +03:00
307 changed files with 600 additions and 20049 deletions

31
APICycleVDP.sln Normal file

@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.11.35303.130
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "APICycleVDP", "APICycleVDP\APICycleVDP.csproj", "{EE827F72-C902-4E67-B4E7-A1B869310349}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenCycleVDP", "GenCycleVDP\GenCycleVDP.csproj", "{CEFFBDBE-DDBA-421D-80FA-A730914A5BDD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{EE827F72-C902-4E67-B4E7-A1B869310349}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EE827F72-C902-4E67-B4E7-A1B869310349}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EE827F72-C902-4E67-B4E7-A1B869310349}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EE827F72-C902-4E67-B4E7-A1B869310349}.Release|Any CPU.Build.0 = Release|Any CPU
{CEFFBDBE-DDBA-421D-80FA-A730914A5BDD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{CEFFBDBE-DDBA-421D-80FA-A730914A5BDD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CEFFBDBE-DDBA-421D-80FA-A730914A5BDD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CEFFBDBE-DDBA-421D-80FA-A730914A5BDD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A058F6B2-4BE7-414E-BCA6-A32B16A3DDDF}
EndGlobalSection
EndGlobal

@ -0,0 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<Compile Include="..\DbCycleVDP\DbFurnace.cs" Link="Db/DbFurnace.cs" />
<Compile Include="..\DbCycleVDP\TableCycle.cs" Link="Db/TableCycle.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />
</ItemGroup>
</Project>

@ -0,0 +1,71 @@
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using DbCycleVDP;
namespace APICycleVDP.Controller
{
[EnableCors("All")]
public class CyclesController : ControllerBase
{
[HttpPost]
public ActionResult<string> CurrCycles()
{
var result = new JObject
{
["currTime"] = DateTime.Now
};
var tasks = new List<Task<TableCycle>>();
//var v = new DB.WorkDB();
for (var i = 1; i <= 48; i++)
tasks.Add(WorkDB.GetCycle(i));
var arr = new JArray();
for (var i = 0; i < tasks.Count; i++)
{
var tmp = tasks[i].GetAwaiter().GetResult();
if (tmp != null)
{
var t = new JObject();
t["vdp"] = tmp.NumVdp;
t["cycle"] = tmp.NumCycle;
t["factStart"] = tmp.FactStart;
t["factEnd"] = tmp.FactEnd;
t["thinkEnd"] = tmp.ThinkEnd;
arr.Add(t);
}
}
result["data"] = arr;
return Content(result.ToString(), "application/json");
}
}
public static class WorkDB
{
async public static Task<TableCycle> GetCycle(int vdp)
{
var result = new TableCycle();
await Task.Run(() =>
{
try
{
using var db = new DbFurnace();
var tmp = (from u in db.Cycles
where
u.NumVdp == vdp
orderby u.FactStart descending
select u).FirstOrDefault();
result = tmp;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
});
return result;
}
}
}

22
APICycleVDP/Program.cs Normal file

@ -0,0 +1,22 @@
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddCors(options =>
{
options.AddPolicy("AllowAllOrigins",
builder =>
{
builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader();
});
});
var app = builder.Build();
app.UseCors("AllowAllOrigins");
app.MapControllerRoute(name: "CurrCycles", pattern: "/currcycles",
defaults: new { controller = "Cycles", action = "CurrCycles" });
app.Run();

@ -1,24 +1,28 @@
{ {
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": { "iisSettings": {
"windowsAuthentication": false, "windowsAuthentication": false,
"anonymousAuthentication": true, "anonymousAuthentication": true,
"iisExpress": { "iisExpress": {
"applicationUrl": "http://localhost:9312", "applicationUrl": "http://localhost:37468",
"sslPort": 0 "sslPort": 0
} }
}, },
"profiles": { "profiles": {
"IIS Express": { "http": {
"commandName": "IISExpress", "commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true, "launchBrowser": true,
"launchUrl": "currcycles",
"applicationUrl": "http://localhost:65041",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }
}, },
"Diagram_API": { "IIS Express": {
"commandName": "Project", "commandName": "IISExpress",
"launchBrowser": true, "launchBrowser": true,
"applicationUrl": "http://localhost:5000", "launchUrl": "currcycles",
"environmentVariables": { "environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development" "ASPNETCORE_ENVIRONMENT": "Development"
} }

@ -0,0 +1,8 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
}
}

@ -0,0 +1,16 @@
{
"Kestrel": {
"Endpoints": {
"Http": {
"Url": "http://*:65041"
}
}
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}

24
DbCycleVDP/DbFurnace.cs Normal file

@ -0,0 +1,24 @@
using System;
using Microsoft.EntityFrameworkCore;
namespace DbCycleVDP
{
public class DbFurnace : DbContext
{
public DbSet<TableCycle> Cycles { get; set; }
public DbFurnace()
{
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
// optionsBuilder.UseMySql("server=127.0.0.1;user=diplom;password=diplom;database=VDPCycles;", new MySqlServerVersion(new Version(8, 0)));
optionsBuilder.UseMySql("server=37.79.216.218;user=mytest;password=mytest;database=VDPCycles;", new MySqlServerVersion(new Version(8, 0)));
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
}
}

23
DbCycleVDP/TableCycle.cs Normal file

@ -0,0 +1,23 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace DbCycleVDP
{
[Table("Cycles")]
public class TableCycle
{
[Column("idCycle"), Required, Key]
public int IdCycle { get; set; }
[Column("numVdp")]
public int NumVdp { get; set; }
[Column("numCycle")]
public int NumCycle { get; set; }
[Column("factStart")]
public DateTime FactStart { get; set; }
[Column("thinkEnd")]
public DateTime ThinkEnd { get; set; }
[Column("factEnd")]
public DateTime FactEnd { get; set; }
}
}

@ -1,31 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31105.61
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GenerateVDPCycle", "GenerateVDPCycle\GenerateVDPCycle.csproj", "{018AAFB3-4293-4F38-9E6C-C9A7F16C278D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Diagram-API", "Diagram-API\Diagram-API.csproj", "{7159386F-FF50-43BD-B93F-C0441D58C15E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{018AAFB3-4293-4F38-9E6C-C9A7F16C278D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{018AAFB3-4293-4F38-9E6C-C9A7F16C278D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{018AAFB3-4293-4F38-9E6C-C9A7F16C278D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{018AAFB3-4293-4F38-9E6C-C9A7F16C278D}.Release|Any CPU.Build.0 = Release|Any CPU
{7159386F-FF50-43BD-B93F-C0441D58C15E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7159386F-FF50-43BD-B93F-C0441D58C15E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7159386F-FF50-43BD-B93F-C0441D58C15E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7159386F-FF50-43BD-B93F-C0441D58C15E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0DFB9976-856A-40AB-8E91-1962DAE0EA2D}
EndGlobalSection
EndGlobal

@ -1,46 +0,0 @@
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Diagram_API.Controller
{
[EnableCors("All")]
public class CyclesController : ControllerBase
{
[HttpPost]
public ActionResult<string> CurrCycles()
{
var result = new JObject();
result["currTime"] = DateTime.Now;
var tasks = new List<Task<DB.Cycle>>();
//var v = new DB.WorkDB();
for (var i = 1; i <= 48; i++)
tasks.Add(DB.WorkDB.GetCycle(i));
var arr = new JArray();
for (var i = 0; i < tasks.Count; i++)
{
var tmp = tasks[i].GetAwaiter().GetResult();
if (tmp != null)
{
var t = new JObject();
t["vdp"] = tmp.NumVdp;
t["cycle"] = tmp.NumCycle;
t["factStart"] = tmp.FactStart;
t["factEnd"] = tmp.FactEnd;
t["thinkEnd"] = tmp.ThinkEnd;
arr.Add(t);
}
}
result["data"] = arr;
return Content(result.ToString(), "application/json");
}
}
}

@ -1,74 +0,0 @@
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Threading.Tasks;
namespace Diagram_API.DB
{
public class VdpDB : DbContext
{
public DbSet<DB.Cycle> Cycles { get; set; }
public VdpDB()
{
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySql("server=127.0.0.1;user=diplom;password=diplom;database=VDPCycles;");
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
}
}
[Table("Cycles")]
public class Cycle
{
[Column("idCycle"), Required, Key]
public int IdCycle { get; set; }
[Column("numVdp")]
public int NumVdp { get; set; }
[Column("numCycle")]
public int NumCycle { get; set; }
[Column("factStart")]
public DateTime FactStart { get; set; }
[Column("thinkEnd")]
public DateTime ThinkEnd { get; set; }
[Column("factEnd")]
public DateTime FactEnd { get; set; }
}
public static class WorkDB
{
async public static Task<Cycle> GetCycle(int vdp)
{
var result = new Cycle();
await Task.Run(() =>
{
try
{
using (var db = new DB.VdpDB())
{
var tmp = (from u in db.Cycles
where
u.NumVdp == vdp
orderby u.FactStart descending
select u).FirstOrDefault();
result = tmp;
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
});
return result;
}
}
}

@ -1,12 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<RootNamespace>Diagram_API</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.2.5" />
</ItemGroup>
</Project>

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Controller_SelectedScaffolderID>MvcControllerEmptyScaffolder</Controller_SelectedScaffolderID>
<Controller_SelectedScaffolderCategoryPath>root/Common/MVC/Controller</Controller_SelectedScaffolderCategoryPath>
<ActiveDebugProfile>Diagram_API</ActiveDebugProfile>
<NameOfLastUsedPublishProfile>G:\Diagram-API\Diagram-API\Properties\PublishProfiles\FolderProfile.pubxml</NameOfLastUsedPublishProfile>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebuggerFlavor>ProjectDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

@ -1,26 +0,0 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Diagram_API
{
public class Program
{
public static void Main(string[] args)
{
CreateHostBuilder(args).Build().Run();
}
public static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseStartup<Startup>().UseUrls("http://*:65041");
});
}
}

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<DeleteExistingFiles>False</DeleteExistingFiles>
<ExcludeApp_Data>False</ExcludeApp_Data>
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<PublishProvider>FileSystem</PublishProvider>
<PublishUrl>bin\Release\netcoreapp3.1\publish\</PublishUrl>
<WebPublishMethod>FileSystem</WebPublishMethod>
</PropertyGroup>
</Project>

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121.
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<_PublishTargetUrl>G:\Diagram-API\Diagram-API\bin\Release\netcoreapp3.1\publish\</_PublishTargetUrl>
<History>True|2021-05-15T17:10:59.1171936Z;True|2021-05-15T22:06:16.7802197+05:00;</History>
</PropertyGroup>
</Project>

@ -1,61 +0,0 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace Diagram_API
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy(
name: "All",
builder => {
builder
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
//.AllowCredentials()
.SetIsOriginAllowed((host) => true);
});
});
services.AddControllers();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseRouting();
app.UseCors(
options => options
.AllowAnyOrigin()
.AllowAnyHeader()
.AllowAnyMethod()
//.AllowCredentials()
.SetIsOriginAllowed((host) => true)
);
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(name: "CurrCycles", pattern: "/currcycles",
defaults: new { controller = "Cycles", action = "CurrCycles" });
endpoints.MapControllerRoute(name: "ListCurrencies", pattern: "/listcurrencies",
defaults: new { controller = "Rates", action = "GetListCurrencies" });
endpoints.MapControllerRoute(name: "CurrentRates", pattern: "/currentrates",
defaults: new { controller = "Rates", action = "GetCurrentRates" });
endpoints.MapControllerRoute(name: "RatesList", pattern: "/rateslist",
defaults: new { controller = "Rates", action = "GetRatesList" });
});
}
}
}

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

@ -1,10 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

File diff suppressed because it is too large Load Diff

@ -1,10 +0,0 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\Admin\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Admin\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
"C:\\Program Files (x86)\\Microsoft\\Xamarin\\NuGet"
]
}
}

@ -1,13 +0,0 @@
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.AspNetCore.App",
"version": "3.1.0"
},
"configProperties": {
"System.GC.Server": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

@ -1,10 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

File diff suppressed because it is too large Load Diff

@ -1,10 +0,0 @@
{
"runtimeOptions": {
"additionalProbingPaths": [
"C:\\Users\\Admin\\.dotnet\\store\\|arch|\\|tfm|",
"C:\\Users\\Admin\\.nuget\\packages",
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages",
"C:\\Program Files (x86)\\Microsoft\\Xamarin\\NuGet"
]
}
}

@ -1,13 +0,0 @@
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.AspNetCore.App",
"version": "3.1.0"
},
"configProperties": {
"System.GC.Server": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

@ -1,9 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
}
}

@ -1,10 +0,0 @@
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*"
}

@ -1,13 +0,0 @@
{
"runtimeOptions": {
"tfm": "netcoreapp3.1",
"framework": {
"name": "Microsoft.AspNetCore.App",
"version": "3.1.0"
},
"configProperties": {
"System.GC.Server": true,
"System.Runtime.Serialization.EnableUnsafeBinaryFormatterSerialization": false
}
}
}

Some files were not shown because too many files have changed in this diff Show More