From b4e971768581e78f8cc0237a4914430dad1c9c0d Mon Sep 17 00:00:00 2001 From: syneffort Date: Fri, 10 May 2024 15:21:12 +0900 Subject: [PATCH] by rest api (not recommanded) --- .../Controllers/DataTableController.cs | 49 +++++++++++++++++++ .../DataTableAPIHost/DataManager.cs | 26 ++++++++++ .../DataTableAPIHost/DataTableAPIHost.csproj | 14 ++++++ DataTableRemoting/DataTableAPIHost/Program.cs | 35 +++++++++++++ .../Properties/launchSettings.json | 31 ++++++++++++ .../DataTableAPIHost/WeatherForecast.cs | 13 +++++ .../appsettings.Development.json | 8 +++ .../DataTableAPIHost/appsettings.json | 9 ++++ DataTableRemoting/DataTableRemoting.sln | 9 ++++ 9 files changed, 194 insertions(+) create mode 100644 DataTableRemoting/DataTableAPIHost/Controllers/DataTableController.cs create mode 100644 DataTableRemoting/DataTableAPIHost/DataManager.cs create mode 100644 DataTableRemoting/DataTableAPIHost/DataTableAPIHost.csproj create mode 100644 DataTableRemoting/DataTableAPIHost/Program.cs create mode 100644 DataTableRemoting/DataTableAPIHost/Properties/launchSettings.json create mode 100644 DataTableRemoting/DataTableAPIHost/WeatherForecast.cs create mode 100644 DataTableRemoting/DataTableAPIHost/appsettings.Development.json create mode 100644 DataTableRemoting/DataTableAPIHost/appsettings.json diff --git a/DataTableRemoting/DataTableAPIHost/Controllers/DataTableController.cs b/DataTableRemoting/DataTableAPIHost/Controllers/DataTableController.cs new file mode 100644 index 0000000..81fb3a2 --- /dev/null +++ b/DataTableRemoting/DataTableAPIHost/Controllers/DataTableController.cs @@ -0,0 +1,49 @@ +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System.Data; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace DataTableAPIHost.Controllers +{ + [Route("api/[controller]")] + [ApiController] + public class DataTableController : ControllerBase + { + // GET: api/ + [HttpGet] + public string Get() + { + return JsonConvert.SerializeObject(DataManager.Instance.DataTable); + } + + // GET api//5 + [HttpGet("{id}")] + public string Get(int id) + { + DataRow[] rows = DataManager.Instance.DataTable.Select($"ID = {id}"); + return JsonConvert.SerializeObject(rows[0]); + } + + //// POST api/ + //[HttpPost] + //public string Post([FromBody] string value) + //{ + // return ""; + //} + + //// PUT api//5 + //[HttpPut("{id}")] + //public string Put(int id, [FromBody] string value) + //{ + // return ""; + + //} + + //// DELETE api//5 + //[HttpDelete("{id}")] + //public DataTable Delete(int id) + //{ + //} + } +} diff --git a/DataTableRemoting/DataTableAPIHost/DataManager.cs b/DataTableRemoting/DataTableAPIHost/DataManager.cs new file mode 100644 index 0000000..f019979 --- /dev/null +++ b/DataTableRemoting/DataTableAPIHost/DataManager.cs @@ -0,0 +1,26 @@ +using System.Data; + +namespace DataTableAPIHost +{ + public class DataManager + { + public static DataManager Instance = new DataManager(); + + public DataManager() + { + if (Instance == null) + { + _dataTable = new DataTable("SampleTable"); + _dataTable.Columns.Add("ID", typeof(int)); + _dataTable.Columns.Add("Name", typeof(string)); + + _dataTable.Rows.Add(1, "John"); + _dataTable.Rows.Add(2, "Ronaldo"); + _dataTable.Rows.Add(3, "Messi"); + } + } + + DataTable _dataTable; + public DataTable DataTable { get { return _dataTable; } } + } +} diff --git a/DataTableRemoting/DataTableAPIHost/DataTableAPIHost.csproj b/DataTableRemoting/DataTableAPIHost/DataTableAPIHost.csproj new file mode 100644 index 0000000..0c965c0 --- /dev/null +++ b/DataTableRemoting/DataTableAPIHost/DataTableAPIHost.csproj @@ -0,0 +1,14 @@ + + + + net6.0 + enable + enable + + + + + + + + diff --git a/DataTableRemoting/DataTableAPIHost/Program.cs b/DataTableRemoting/DataTableAPIHost/Program.cs new file mode 100644 index 0000000..009c5ba --- /dev/null +++ b/DataTableRemoting/DataTableAPIHost/Program.cs @@ -0,0 +1,35 @@ +namespace DataTableAPIHost +{ + public class Program + { + public static void Main(string[] args) + { + var builder = WebApplication.CreateBuilder(args); + + // Add services to the container. + + builder.Services.AddControllers(); + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + builder.Services.AddEndpointsApiExplorer(); + builder.Services.AddSwaggerGen(); + + var app = builder.Build(); + + // Configure the HTTP request pipeline. + if (app.Environment.IsDevelopment()) + { + app.UseSwagger(); + app.UseSwaggerUI(); + } + + app.UseHttpsRedirection(); + + app.UseAuthorization(); + + + app.MapControllers(); + + app.Run(); + } + } +} diff --git a/DataTableRemoting/DataTableAPIHost/Properties/launchSettings.json b/DataTableRemoting/DataTableAPIHost/Properties/launchSettings.json new file mode 100644 index 0000000..7a55fa6 --- /dev/null +++ b/DataTableRemoting/DataTableAPIHost/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:53804", + "sslPort": 44380 + } + }, + "profiles": { + "DataTableAPIHost": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7050;http://localhost:5259", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/DataTableRemoting/DataTableAPIHost/WeatherForecast.cs b/DataTableRemoting/DataTableAPIHost/WeatherForecast.cs new file mode 100644 index 0000000..66fd1f6 --- /dev/null +++ b/DataTableRemoting/DataTableAPIHost/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace DataTableAPIHost +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } + } +} diff --git a/DataTableRemoting/DataTableAPIHost/appsettings.Development.json b/DataTableRemoting/DataTableAPIHost/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/DataTableRemoting/DataTableAPIHost/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/DataTableRemoting/DataTableAPIHost/appsettings.json b/DataTableRemoting/DataTableAPIHost/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/DataTableRemoting/DataTableAPIHost/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/DataTableRemoting/DataTableRemoting.sln b/DataTableRemoting/DataTableRemoting.sln index 6473c36..922c059 100644 --- a/DataTableRemoting/DataTableRemoting.sln +++ b/DataTableRemoting/DataTableRemoting.sln @@ -11,6 +11,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataTableWCFClient", "DataT EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WCF", "WCF", "{35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "WebService", "WebService", "{4F8C407D-03AF-4010-A10D-3228D7810EF5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataTableAPIHost", "DataTableAPIHost\DataTableAPIHost.csproj", "{8598A97E-811F-405C-BCEE-3E9077D503F6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,6 +33,10 @@ Global {2BC29718-BCFE-4069-881A-595AC1688F8A}.Debug|Any CPU.Build.0 = Debug|Any CPU {2BC29718-BCFE-4069-881A-595AC1688F8A}.Release|Any CPU.ActiveCfg = Release|Any CPU {2BC29718-BCFE-4069-881A-595AC1688F8A}.Release|Any CPU.Build.0 = Release|Any CPU + {8598A97E-811F-405C-BCEE-3E9077D503F6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8598A97E-811F-405C-BCEE-3E9077D503F6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8598A97E-811F-405C-BCEE-3E9077D503F6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8598A97E-811F-405C-BCEE-3E9077D503F6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -37,6 +45,7 @@ Global {07A3D554-0C5E-4A63-A1B1-2D48165701A4} = {35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866} {6E02E64B-D7C0-4593-8CCF-75D680AEB188} = {35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866} {2BC29718-BCFE-4069-881A-595AC1688F8A} = {35D8B24C-91B6-47F4-AEBC-1FEF7FCF2866} + {8598A97E-811F-405C-BCEE-3E9077D503F6} = {4F8C407D-03AF-4010-A10D-3228D7810EF5} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {659C8570-938B-451A-8E1F-087AA1B1F50D}