From 1049ec9a97a29a82a67a1f53cdc52c490c37be0b Mon Sep 17 00:00:00 2001 From: wangyu Date: Fri, 25 Aug 2023 14:10:51 +0800 Subject: [PATCH] init --- .gitignore | 5 +++ Program.cs | 45 +++++++++++++++++++ .../PublishProfiles/FolderProfile.pubxml | 24 ++++++++++ Properties/launchSettings.json | 29 ++++++++++++ Sinet.CacheService.csproj | 13 ++++++ Sinet.CacheService.sln | 25 +++++++++++ appsettings.Development.json | 8 ++++ appsettings.json | 11 +++++ 8 files changed, 160 insertions(+) create mode 100644 .gitignore create mode 100644 Program.cs create mode 100644 Properties/PublishProfiles/FolderProfile.pubxml create mode 100644 Properties/launchSettings.json create mode 100644 Sinet.CacheService.csproj create mode 100644 Sinet.CacheService.sln create mode 100644 appsettings.Development.json create mode 100644 appsettings.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..632a996 --- /dev/null +++ b/.gitignore @@ -0,0 +1,5 @@ +.vs +bin +obj +/.config +*.user diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..7d51927 --- /dev/null +++ b/Program.cs @@ -0,0 +1,45 @@ +using Microsoft.Extensions.Caching.Distributed; + +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddStackExchangeRedisCache(options => +{ + options.Configuration = builder.Configuration["Redis"]; + options.InstanceName = "CacheData_"; +}); + +var app = builder.Build(); + +var CacheDictionary = new Dictionary(); + +// Configure the HTTP request pipeline. + +app.MapPost("/CacheData/Set", async (HttpRequest request, IDistributedCache cache, string key) => +{ + string body = ""; + using (StreamReader stream = new StreamReader(request.Body)) + { + body = await stream.ReadToEndAsync(); + } + cache.SetString(key, body); + return "success"; +}); + +app.MapGet("/CacheData/Get", (HttpContext httpContext, IDistributedCache cache, string key) => +{ + var cacheString = cache.GetString(key); + if (!string.IsNullOrWhiteSpace(cacheString)) + { + httpContext.Response.ContentType = "application/json"; + return cacheString; + } + else + { + httpContext.Response.StatusCode = 404; + return string.Empty; + } +}); + +app.Run(); \ No newline at end of file diff --git a/Properties/PublishProfiles/FolderProfile.pubxml b/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000..21ee1dd --- /dev/null +++ b/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,24 @@ + + + + + true + false + true + Release + Any CPU + FileSystem + bin\Release\net7.0\publish\ + FileSystem + <_TargetId>Folder + + net7.0 + win-x64 + true + 295af217-802a-4cc5-a87c-ce1d68ed553f + false + false + + \ No newline at end of file diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..809d294 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,29 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:59800", + "sslPort": 0 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5120", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Sinet.CacheService.csproj b/Sinet.CacheService.csproj new file mode 100644 index 0000000..3a2d712 --- /dev/null +++ b/Sinet.CacheService.csproj @@ -0,0 +1,13 @@ + + + + net7.0 + enable + enable + + + + + + + diff --git a/Sinet.CacheService.sln b/Sinet.CacheService.sln new file mode 100644 index 0000000..f90386d --- /dev/null +++ b/Sinet.CacheService.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.8.34004.107 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sinet.CacheService", "Sinet.CacheService.csproj", "{295AF217-802A-4CC5-A87C-CE1D68ED553F}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {295AF217-802A-4CC5-A87C-CE1D68ED553F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {295AF217-802A-4CC5-A87C-CE1D68ED553F}.Debug|Any CPU.Build.0 = Debug|Any CPU + {295AF217-802A-4CC5-A87C-CE1D68ED553F}.Release|Any CPU.ActiveCfg = Release|Any CPU + {295AF217-802A-4CC5-A87C-CE1D68ED553F}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {7D0D0CC9-4D7E-46A8-A5C2-7B949335348B} + EndGlobalSection +EndGlobal diff --git a/appsettings.Development.json b/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..a231f76 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,11 @@ +{ + "Urls": "http://*:5120", + "Redis": "localhost:6379,user=redis,password=password", + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}