This commit is contained in:
jwlee
2024-06-02 22:24:28 +09:00
15 changed files with 375 additions and 1 deletions

2
.gitignore vendored
View File

@@ -4,3 +4,5 @@
/BitgetApi/obj /BitgetApi/obj
/BitgetApi/bin /BitgetApi/bin
/BitgetApi/Properties/licenses.licx /BitgetApi/Properties/licenses.licx
/Bitget_Server/bin
/Bitget_Server/obj

View File

@@ -5,6 +5,8 @@ VisualStudioVersion = 17.9.34902.65
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitgetApi", "BitgetApi\BitgetApi.csproj", "{09813A63-9EF4-4D6D-BA41-5F610909BDEC}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BitgetApi", "BitgetApi\BitgetApi.csproj", "{09813A63-9EF4-4D6D-BA41-5F610909BDEC}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bitget_Server", "Bitget_Server\Bitget_Server.csproj", "{725DC784-0243-4FDF-921E-91CF09580A03}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@@ -15,6 +17,10 @@ Global
{09813A63-9EF4-4D6D-BA41-5F610909BDEC}.Debug|Any CPU.Build.0 = Debug|Any CPU {09813A63-9EF4-4D6D-BA41-5F610909BDEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{09813A63-9EF4-4D6D-BA41-5F610909BDEC}.Release|Any CPU.ActiveCfg = Release|Any CPU {09813A63-9EF4-4D6D-BA41-5F610909BDEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{09813A63-9EF4-4D6D-BA41-5F610909BDEC}.Release|Any CPU.Build.0 = Release|Any CPU {09813A63-9EF4-4D6D-BA41-5F610909BDEC}.Release|Any CPU.Build.0 = Release|Any CPU
{725DC784-0243-4FDF-921E-91CF09580A03}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{725DC784-0243-4FDF-921E-91CF09580A03}.Debug|Any CPU.Build.0 = Debug|Any CPU
{725DC784-0243-4FDF-921E-91CF09580A03}.Release|Any CPU.ActiveCfg = Release|Any CPU
{725DC784-0243-4FDF-921E-91CF09580A03}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -92,7 +92,6 @@
<EmbeddedResource Include="MainForm.resx"> <EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon> <DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource> </EmbeddedResource>
<EmbeddedResource Include="Properties\licenses.licx" />
<EmbeddedResource Include="Properties\Resources.resx"> <EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator> <Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.cs</LastGenOutput> <LastGenOutput>Resources.Designer.cs</LastGenOutput>

View File

@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,19 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitget_Server.Common
{
public static class CommonProperty
{
public static string DbIp { get; set; } = "localhost";
public static string DbName { get; set; } = "Bitget";
public static string DbId { get; set; } = "million";
public static string DbPw { get; set; } = "million!";
public static string EfCoreConnectionStr { get; set; } = $"Server={DbIp};database={DbName};uid={DbId};pwd={DbPw};TrustServerCertificate=true;";
}
}

View File

@@ -0,0 +1,44 @@
using Bitget_Server.EFCore.Models;
using Bitget_Server.EFCore;
using Microsoft.AspNetCore.Mvc;
namespace Bitget_Server.Controller
{
[ApiController, Route("api")]
public class PushAlarmController : ControllerBase
{
private readonly BitgetContext context;
public PushAlarmController(BitgetContext _context)
{
context = _context;
}
[HttpGet, Route("getalarm")]
public List<PushAlarm> GetAlarm(int index)
{
return context.PushAlarms.Where(x => x.Id > index).ToList();
}
[HttpGet, Route("setalarm")]
public bool SetAlarm(string title,string contents)
{
try
{
context.PushAlarms.Add(new PushAlarm {Title = title,Contents = contents,AlarmTime = DateTime.Now});
context.SaveChanges();
return true;
}
catch (Exception e)
{
return false;
}
}
}
}

View File

@@ -0,0 +1,33 @@
using Bitget_Server.Common;
using Bitget_Server.EFCore.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitget_Server.EFCore
{
public class BitgetContext : DbContext
{
public DbSet<PushAlarm> PushAlarms { get; set; }
public BitgetContext(DbContextOptions<BitgetContext> options)
: base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlServer(CommonProperty.EfCoreConnectionStr);
base.OnConfiguring(optionsBuilder);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
}
}
}

View File

@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bitget_Server.EFCore.Models
{
public class PushAlarm
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public DateTime AlarmTime { get; set; }
public string Title { get; set; } = string.Empty;
public string Contents { get; set; } = string.Empty;
}
}

View File

@@ -0,0 +1,54 @@
// <auto-generated />
using System;
using Bitget_Server.EFCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Bitget_Server.Migrations
{
[DbContext(typeof(BitgetContext))]
[Migration("20240602102008_init1")]
partial class init1
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("Bitget_Server.EFCore.Models.PushAlarm", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("AlarmTime")
.HasColumnType("datetime2");
b.Property<string>("Contents")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("PushAlarms");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,37 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Bitget_Server.Migrations
{
/// <inheritdoc />
public partial class init1 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "PushAlarms",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
AlarmTime = table.Column<DateTime>(type: "datetime2", nullable: false),
Title = table.Column<string>(type: "nvarchar(max)", nullable: false),
Contents = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PushAlarms", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PushAlarms");
}
}
}

View File

@@ -0,0 +1,51 @@
// <auto-generated />
using System;
using Bitget_Server.EFCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Bitget_Server.Migrations
{
[DbContext(typeof(BitgetContext))]
partial class BitgetContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.6")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("Bitget_Server.EFCore.Models.PushAlarm", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("AlarmTime")
.HasColumnType("datetime2");
b.Property<string>("Contents")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Title")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("PushAlarms");
});
#pragma warning restore 612, 618
}
}
}

36
Bitget_Server/Program.cs Normal file
View File

@@ -0,0 +1,36 @@
using Bitget_Server.EFCore;
using Microsoft.EntityFrameworkCore;
using System.Net;
namespace Bitget_Server
{
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddDbContext<BitgetContext>();
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddControllersWithViews();
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = services.GetRequiredService<BitgetContext>();
context.Database.Migrate();
}
app.UseSwagger();
app.UseSwaggerUI();
app.MapControllers();
app.MapGet("/", () => "Hello World!");
app.Run($"http://{IPAddress.Any}:{5045}");
}
}
}

View File

@@ -0,0 +1,29 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:46411",
"sslPort": 0
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5045",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}

View File

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

View File

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