commit 8ef014f939a0a8cf1b40304c10d47b4e5ad1bb02 Author: rongguo.jia Date: Tue Dec 6 08:46:02 2022 +0800 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3e7f6ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,265 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ + +# Visual Studio 2015 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# DNX +project.lock.json +artifacts/ + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding add-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config +# NuGet v3's project.json files produces more ignoreable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +orleans.codegen.cs + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# JetBrains Rider +.idea/ +*.sln.iml + +# Auth +src/Win_in.Sfs.Auth.Web/Logs/* +src/Win_in.Sfs.Auth.Web.Host/Logs/* +src/Win_in.Sfs.Auth.IdentityServer/Logs/* +src/Win_in.Sfs.Auth.HttpApi.Host/Logs/* +src/Win_in.Sfs.Auth.HttpApi.HostWithIds/Logs/* +src/Win_in.Sfs.Auth.DbMigrator/Logs/* +src/Win_in.Sfs.Auth.Blazor.Server/Logs/* +src/Win_in.Sfs.Auth.Blazor.Server.Tiered/Logs/* +/WmsService/DataExchange/MesFiles/* +/WmsService/DataExchange/OutputToMes +/WmsService/DataExchange/Output To Mes diff --git a/SyBaseTestWebApp/AppDataConnection.cs b/SyBaseTestWebApp/AppDataConnection.cs new file mode 100644 index 0000000..f00d257 --- /dev/null +++ b/SyBaseTestWebApp/AppDataConnection.cs @@ -0,0 +1,18 @@ +using System; +using LinqToDB; +using LinqToDB.Configuration; +using LinqToDB.Data; +using SyBaseTestWebApp; + +public class AppDataConnection : DataConnection +{ + public AppDataConnection(LinqToDBConnectionOptions options) + : base(options) + { + } + + public ITable Users => this.GetTable(); + + public ITable Part => this.GetTable(); + +} \ No newline at end of file diff --git a/SyBaseTestWebApp/Controllers/Class1.cs b/SyBaseTestWebApp/Controllers/Class1.cs new file mode 100644 index 0000000..920a9de --- /dev/null +++ b/SyBaseTestWebApp/Controllers/Class1.cs @@ -0,0 +1,7 @@ +namespace SyBaseTestWebApp.Controllers +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/SyBaseTestWebApp/Controllers/WeatherForecastController.cs b/SyBaseTestWebApp/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..34c9d7c --- /dev/null +++ b/SyBaseTestWebApp/Controllers/WeatherForecastController.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using LinqToDB; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace SyBaseTestWebApp.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + + private readonly AppDataConnection _connection; + private readonly ILogger _logger; + + public WeatherForecastController( + AppDataConnection connection + ,ILogger logger) + { + _connection = connection; + _logger = logger; + } + + + + [HttpGet] + public Task ListUser() + { + return _connection.Part.ToArrayAsync(); + } + + [HttpGet("{id}")] + public async Task GetUser(int id) + { + + var parts =await _connection.Part.Where(p => p.Id == id).ToListAsync(); + + return parts[0]; + + // return _connection.Part.FirstOrDefaultAsync(person => person.Id == id); + } + + [HttpDelete("{id}")] + public Task DeleteUser(int id) + { + return _connection.Part.Where(person => person.Id == id).DeleteAsync(); + } + + [HttpPut] + public Task UpdateUser(Part person) + { + return _connection.UpdateAsync(person); + } + + [HttpPatch("{id}/new-name")] + public Task UpdateUserName(int id, string newName) + { + return _connection.Part.Where(person => person.Id == id) + .Set(person => person.Name, newName) + .UpdateAsync(); + } + + [HttpPost] + public Task InsertUser(Part person) + { + return _connection.InsertAsync(person); + } + + } +} diff --git a/SyBaseTestWebApp/Program.cs b/SyBaseTestWebApp/Program.cs new file mode 100644 index 0000000..e66c945 --- /dev/null +++ b/SyBaseTestWebApp/Program.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; + +namespace SyBaseTestWebApp +{ + 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(); + }); + } +} diff --git a/SyBaseTestWebApp/Properties/launchSettings.json b/SyBaseTestWebApp/Properties/launchSettings.json new file mode 100644 index 0000000..009049b --- /dev/null +++ b/SyBaseTestWebApp/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:14699", + "sslPort": 0 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "SyBaseTestWebApp": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/SyBaseTestWebApp/Startup.cs b/SyBaseTestWebApp/Startup.cs new file mode 100644 index 0000000..e23e87a --- /dev/null +++ b/SyBaseTestWebApp/Startup.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using LinqToDB.AspNet; +using LinqToDB.AspNet.Logging; +using LinqToDB.Configuration; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using WatchDog; + +namespace SyBaseTestWebApp +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + services.AddLinqToDBContext((provider, options) => { + options + //will configure the AppDataConnection to use + //sqite with the provided connection string + //there are methods for each supported database + .UseAse(Configuration.GetConnectionString("Default")) + //default logging will log everything using the ILoggerFactory configured in the provider + .UseDefaultLogging(provider); + }); + + services.AddWatchDogServices(); + + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "SyBaseTestWebApp", Version = "v1" }); + }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "SyBaseTestWebApp v1")); + } + app.UseWatchDog(opt => + { + opt.WatchPageUsername = "admin"; opt.WatchPagePassword = "Qwerty@123"; + }); + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/SyBaseTestWebApp/SyBaseTestWebApp.csproj b/SyBaseTestWebApp/SyBaseTestWebApp.csproj new file mode 100644 index 0000000..83c643e --- /dev/null +++ b/SyBaseTestWebApp/SyBaseTestWebApp.csproj @@ -0,0 +1,15 @@ + + + + net5.0 + + + + + + + + + + + diff --git a/SyBaseTestWebApp/Users.cs b/SyBaseTestWebApp/Users.cs new file mode 100644 index 0000000..3e81e8b --- /dev/null +++ b/SyBaseTestWebApp/Users.cs @@ -0,0 +1,36 @@ +using LinqToDB.Mapping; + +namespace SyBaseTestWebApp +{ + public class Users + { + [PrimaryKey] + public int Id { get; set; } + public string Name { get; set; } + public string Dept { get; set; } + + public override string ToString() + { + return $"{Id},{Name},{Dept}"; + } + } + + public class Part + { + [PrimaryKey] + [Identity] + public int Id { get; set; } + public string Code { get; set; } + public string Name { get; set; } + + public override string ToString() + { + return $"Id:{Id},Code:{Code},Name:{Name}"; + } + + public void SetId(int id) + { + Id = id; + } + } +} \ No newline at end of file diff --git a/SyBaseTestWebApp/WeatherForecast.cs b/SyBaseTestWebApp/WeatherForecast.cs new file mode 100644 index 0000000..dc5b858 --- /dev/null +++ b/SyBaseTestWebApp/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace SyBaseTestWebApp +{ + 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/SyBaseTestWebApp/appsettings.Development.json b/SyBaseTestWebApp/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/SyBaseTestWebApp/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/SyBaseTestWebApp/appsettings.json b/SyBaseTestWebApp/appsettings.json new file mode 100644 index 0000000..3598694 --- /dev/null +++ b/SyBaseTestWebApp/appsettings.json @@ -0,0 +1,13 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*", + "ConnectionStrings": { + "Default": "Data Source=dev.ccwin-in.com; Port=15000; Database=TYRP; Uid=sa; Pwd=Microsoft2008;Charset=iso_1;" + } +} diff --git a/SyBaseTestWebApp/watchlogs-log.db b/SyBaseTestWebApp/watchlogs-log.db new file mode 100644 index 0000000..647e722 Binary files /dev/null and b/SyBaseTestWebApp/watchlogs-log.db differ diff --git a/SyBaseTestWebApp/watchlogs.db b/SyBaseTestWebApp/watchlogs.db new file mode 100644 index 0000000..05d7527 Binary files /dev/null and b/SyBaseTestWebApp/watchlogs.db differ diff --git a/SybaseTest.sln b/SybaseTest.sln new file mode 100644 index 0000000..8a1ef43 --- /dev/null +++ b/SybaseTest.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.3.32922.545 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SybaseTest", "SybaseTest\SybaseTest.csproj", "{000896B3-2A75-4C73-9D53-00AFF85C250A}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SyBaseTestWebApp", "SyBaseTestWebApp\SyBaseTestWebApp.csproj", "{13CBB564-B3AC-4801-AE1D-EE87DEFDB4BA}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {000896B3-2A75-4C73-9D53-00AFF85C250A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {000896B3-2A75-4C73-9D53-00AFF85C250A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {000896B3-2A75-4C73-9D53-00AFF85C250A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {000896B3-2A75-4C73-9D53-00AFF85C250A}.Release|Any CPU.Build.0 = Release|Any CPU + {13CBB564-B3AC-4801-AE1D-EE87DEFDB4BA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {13CBB564-B3AC-4801-AE1D-EE87DEFDB4BA}.Debug|Any CPU.Build.0 = Debug|Any CPU + {13CBB564-B3AC-4801-AE1D-EE87DEFDB4BA}.Release|Any CPU.ActiveCfg = Release|Any CPU + {13CBB564-B3AC-4801-AE1D-EE87DEFDB4BA}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7895A86A-CF05-4A3C-85D6-2250E48A3E25} + EndGlobalSection +EndGlobal diff --git a/SybaseTest/Program.cs b/SybaseTest/Program.cs new file mode 100644 index 0000000..cb0d05a --- /dev/null +++ b/SybaseTest/Program.cs @@ -0,0 +1,130 @@ +using System; +using System.Data; +using System.Linq; +using AdoNetCore.AseClient; +using Dapper; + +namespace SybaseTest +{ + internal class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hello World!"); + + Delete(); + + Add(); + + Query(); + + Update(); + + Query(); + } + + private static void Delete() + { + using (IDbConnection conn = SybaseConn) + { + Users user = new Users + { + Id = 1 + }; + string sqlCommandText = @"DELETE FROM Users WHERE Id=@Id"; + int result = conn.Execute(sqlCommandText, user); + Console.WriteLine(result); + user = new Users + { + Id = 2 + }; + sqlCommandText = @"DELETE FROM Users WHERE Id=@Id"; + result = conn.Execute(sqlCommandText, user); + Console.WriteLine(result); + } + } + + private static void Update() + { + using (IDbConnection conn = SybaseConn) + { + Users user = new Users + { + Id = 1, + Name = "CNKI", + Dept = "HR" + }; + string sqlCommandText = @"UPDATE Users SET Dept=@Dept WHERE Id=@Id"; + int result = conn.Execute(sqlCommandText, user); + Console.WriteLine(result); + } + } + + private static void Query() + { + using (IDbConnection conn = SybaseConn) + { + string sqlCommandText = @"SELECT * FROM Users"; + var users = conn.Query(sqlCommandText).ToList(); + foreach (var user in users) + { + Console.WriteLine(user); + } + + } + } + + + private static void Add() + { + using (IDbConnection conn = SybaseConn) + { + Users user1 = new Users + { + Id = 1, + Name = "CNKI", + Dept = "Sale" + }; + string sqlCommandText = @"INSERT INTO Users(Id,Name,Dept)VALUES(@Id,@Name,@Dept)"; + int result = conn.Execute(sqlCommandText, user1); + Console.WriteLine(result); + Users user2 = new Users + { + Id = 2, + Name = "MSDN", + Dept = "Sale" + }; + sqlCommandText = @"INSERT INTO Users(Id,Name,Dept)VALUES(@Id,@Name,@Dept)"; + result = conn.Execute(sqlCommandText, user2); + Console.WriteLine(result); + } + } + + public static IDbConnection SybaseConn + { + get + { + try + { + return new AseConnection("Data Source=dev.ccwin-in.com; Port=15000; Database=TYRP; Uid=sa; Pwd=Microsoft2008;Charset=iso_1;"); + } + catch (Exception ex) + { + } + return null; + } + } + } + + internal class Users + { + public int Id { get; set; } + public string Name { get; set; } + public string Dept { get; set; } + + public override string ToString() + { + return $"{Id},{Name},{Dept}"; + } + } +} diff --git a/SybaseTest/SybaseTest.csproj b/SybaseTest/SybaseTest.csproj new file mode 100644 index 0000000..0e86272 --- /dev/null +++ b/SybaseTest/SybaseTest.csproj @@ -0,0 +1,13 @@ + + + + Exe + net5.0 + + + + + + + +