This is an automated email from the ASF dual-hosted git repository. mmartell pushed a commit to branch GEODE-9356-create-ci in repository https://gitbox.apache.org/repos/asf/geode-dotnet-core-client.git
The following commit(s) were added to refs/heads/GEODE-9356-create-ci by this push: new f9cbf66 Mostly support for non-Steeltoe sample f9cbf66 is described below commit f9cbf66109cc2a7a0924e1ed97df8e8ab012138b Author: Mike Martell <mmart...@pivotal.io> AuthorDate: Mon Jul 19 13:54:36 2021 -0700 Mostly support for non-Steeltoe sample --- NetCore.Session/NetCore.Session.csproj | 3 +- .../NetCoreCacheServiceCollectionExtensions.cs | 39 ++++++++++ NetCore.Session/NetCoreSessionStateOptions.cs | 31 ++++++++ NetCore.Test/NetCore.Test.csproj | 2 +- NetCore/Constants.cs | 2 +- SessionSample/Startup.cs | 5 +- .../Extensions/SessionExtensions.cs | 44 +++++++++++ .../Middleware/HttpContextItemsMiddleware.cs | 36 +++++++++ .../Models/BasicAuthInitialize.cs | 31 ++++++++ SessionSampleNoSteeltoe/Models/ErrorViewModel.cs | 11 +++ SessionSampleNoSteeltoe/Pages/Error.cshtml | 26 +++++++ SessionSampleNoSteeltoe/Pages/Error.cshtml.cs | 23 ++++++ SessionSampleNoSteeltoe/Pages/Index.cshtml | 72 +++++++++++++++++ SessionSampleNoSteeltoe/Pages/Index.cshtml.cs | 77 ++++++++++++++++++ .../Pages/Shared/_Layout.cshtml | 14 ++++ SessionSampleNoSteeltoe/Pages/_ViewImports.cshtml | 3 + SessionSampleNoSteeltoe/Pages/_ViewStart.cshtml | 3 + SessionSampleNoSteeltoe/Program.cs | 20 +++++ .../Properties/launchSettings.json | 28 +++++++ .../SessionSampleNoSteeltoe.csproj | 13 ++++ .../SessionSampleNoSteeltoe.csproj.user | 6 ++ .../SessionSampleNoSteeltoe.sln | 31 ++++++++ SessionSampleNoSteeltoe/Startup.cs | 91 ++++++++++++++++++++++ .../appsettings.Development.json | 9 +++ .../appsettings.Production.json | 9 +++ SessionSampleNoSteeltoe/appsettings.json | 8 ++ ci/pipeline.yml | 1 + geode-dotnet-core.sln | 37 +++++++++ 28 files changed, 669 insertions(+), 6 deletions(-) diff --git a/NetCore.Session/NetCore.Session.csproj b/NetCore.Session/NetCore.Session.csproj index e7585bb..a21c47f 100644 --- a/NetCore.Session/NetCore.Session.csproj +++ b/NetCore.Session/NetCore.Session.csproj @@ -1,12 +1,13 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <TargetFramework>net5.0</TargetFramework> + <TargetFramework>netcoreapp3.1</TargetFramework> <Platforms>AnyCPU;x64</Platforms> </PropertyGroup> <ItemGroup> <PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="3.1.3" /> + <PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="3.1.17" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="3.1.3" /> </ItemGroup> diff --git a/NetCore.Session/NetCoreCacheServiceCollectionExtensions.cs b/NetCore.Session/NetCoreCacheServiceCollectionExtensions.cs new file mode 100644 index 0000000..e20873f --- /dev/null +++ b/NetCore.Session/NetCoreCacheServiceCollectionExtensions.cs @@ -0,0 +1,39 @@ +using System; +using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; + +namespace Apache.Geode.Session +{ + /// <summary> + /// Extension methods for setting up NetCore distributed cache related services in an <see cref="IServiceCollection" />. + /// </summary> + public static class SessionStateCacheServiceCollectionExtensions + { + /// <summary> + /// Adds Geode distributed caching services to the specified <see cref="IServiceCollection" />. + /// </summary> + /// <param name="services">The <see cref="IServiceCollection" /> to add services to.</param> + /// <param name="setupAction">An <see cref="Action{SessionStateCacheOptions}"/> to configure the provided + /// <see cref="SessionStateCacheOptions"/>.</param> + /// <returns>The <see cref="IServiceCollection"/> so that additional calls can be chained.</returns> + public static IServiceCollection AddsSessionStateCache(this IServiceCollection services, Action<SessionStateCacheOptions> setupAction) + { + if (services == null) + { + throw new ArgumentNullException(nameof(services)); + } + + if (setupAction == null) + { + throw new ArgumentNullException(nameof(setupAction)); + } + + services.AddOptions(); + services.Configure(setupAction); + //services.Add(ServiceDescriptor.Singleton<IDistributedCache, SessionStateCache>()); + + return services; + } + } +} diff --git a/NetCore.Session/NetCoreSessionStateOptions.cs b/NetCore.Session/NetCoreSessionStateOptions.cs new file mode 100644 index 0000000..00998d2 --- /dev/null +++ b/NetCore.Session/NetCoreSessionStateOptions.cs @@ -0,0 +1,31 @@ +using Microsoft.Extensions.Options; + +namespace Apache.Geode.Session +{ + /// <summary> + /// Configuration options for <see cref="SessionStateCache"/>. + /// </summary> + public class SessionStateCacheOptions : IOptions<SessionStateCacheOptions> + { + /// <summary> + /// The configuration used to connect to SessionStateCache. + /// </summary> + public string Configuration { get; set; } + + /// <summary> + /// The configuration used to connect to SessionStateCache. + /// This is preferred over Configuration. + /// </summary> + //public ConfigurationOptions ConfigurationOptions { get; set; } + + /// <summary> + /// The Redis instance name. + /// </summary> + public string InstanceName { get; set; } + + SessionStateCacheOptions IOptions<SessionStateCacheOptions>.Value + { + get { return this; } + } + } +} \ No newline at end of file diff --git a/NetCore.Test/NetCore.Test.csproj b/NetCore.Test/NetCore.Test.csproj index 0e1af0c..9b701e7 100644 --- a/NetCore.Test/NetCore.Test.csproj +++ b/NetCore.Test/NetCore.Test.csproj @@ -1,7 +1,7 @@ <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> - <TargetFramework>net5.0</TargetFramework> + <TargetFramework>netcoreapp3.1</TargetFramework> <IsPackable>false</IsPackable> diff --git a/NetCore/Constants.cs b/NetCore/Constants.cs index a733440..dcdb003 100644 --- a/NetCore/Constants.cs +++ b/NetCore/Constants.cs @@ -9,7 +9,7 @@ namespace Apache { public const string libPath = //"/Users/matthewreddington/workspace/apache/geode-native/cppcache/shared/libapache-geode.dylib"; - "C:/geode-native-c_bindings/build/c_bindings/Debug/apache-geode-c.dll"; + "C:/geode-native/build/c_bindings/Debug/apache-geode-c.dll"; } } } diff --git a/SessionSample/Startup.cs b/SessionSample/Startup.cs index 7cf7c36..f5333af 100644 --- a/SessionSample/Startup.cs +++ b/SessionSample/Startup.cs @@ -1,6 +1,5 @@ using GemFireSessionState.Models; using Apache.Geode.Session; -using Steeltoe.Connector.GemFire; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; @@ -27,10 +26,10 @@ namespace SessionSample public void ConfigureServices(IServiceCollection services) { - services.AddGemFireConnection(Configuration, typeof(BasicAuthInitialize), loggerFactory: LoggerFactory); + //services.AddGemFireConnection(Configuration, typeof(BasicAuthInitialize), loggerFactory: LoggerFactory); // TODO: Don't hardcode region name here - services.AddSingleton<IDistributedCache>((isp) => new SessionStateCache(isp.GetRequiredService<Cache>(), "SteeltoeDemo", isp.GetService<ILogger<SessionStateCache>>())); + services.AddSingleton<IDistributedCache>((isp) => new SessionStateCache(isp.GetRequiredService<Cache>(), "NetCoreSession", isp.GetService<ILogger<SessionStateCache>>())); services.AddSession(options => { diff --git a/SessionSampleNoSteeltoe/Extensions/SessionExtensions.cs b/SessionSampleNoSteeltoe/Extensions/SessionExtensions.cs new file mode 100644 index 0000000..8b5035e --- /dev/null +++ b/SessionSampleNoSteeltoe/Extensions/SessionExtensions.cs @@ -0,0 +1,44 @@ +using System.Text.Json; +using Microsoft.AspNetCore.Http; + +namespace Web.Extensions +{ + #region snippet1 + public static class SessionExtensions + { + public static void Set<T>(this ISession session, string key, T value) + { + session.SetString(key, JsonSerializer.Serialize(value)); + } + + public static T Get<T>(this ISession session, string key) + { + var value = session.GetString(key); + return value == null ? default : JsonSerializer.Deserialize<T>(value); + } + } + #endregion +} + +namespace Web.Extensions2 +{ + // Alternate approach + + public static class SessionExtensions + { + public static void Set<T>(this ISession session, string key, T value) + { + session.SetString(key, JsonSerializer.Serialize(value)); + } + + public static bool TryGet<T>(this ISession session, string key, out T value) + { + var state = session.GetString(key); + value = default; + if (state == null) + return false; + value = JsonSerializer.Deserialize<T>(state); + return true; + } + } +} \ No newline at end of file diff --git a/SessionSampleNoSteeltoe/Middleware/HttpContextItemsMiddleware.cs b/SessionSampleNoSteeltoe/Middleware/HttpContextItemsMiddleware.cs new file mode 100644 index 0000000..6a8597c --- /dev/null +++ b/SessionSampleNoSteeltoe/Middleware/HttpContextItemsMiddleware.cs @@ -0,0 +1,36 @@ +using System; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Http; + +namespace SessionSample.Middleware +{ + #region snippet1 + public class HttpContextItemsMiddleware + { + private readonly RequestDelegate _next; + public static readonly object HttpContextItemsMiddlewareKey = new Object(); + + public HttpContextItemsMiddleware(RequestDelegate next) + { + _next = next; + } + + public async Task Invoke(HttpContext httpContext) + { + httpContext.Items[HttpContextItemsMiddlewareKey] = "K-9"; + + await _next(httpContext); + } + } + + public static class HttpContextItemsMiddlewareExtensions + { + public static IApplicationBuilder + UseHttpContextItemsMiddleware(this IApplicationBuilder app) + { + return app.UseMiddleware<HttpContextItemsMiddleware>(); + } + } + #endregion +} diff --git a/SessionSampleNoSteeltoe/Models/BasicAuthInitialize.cs b/SessionSampleNoSteeltoe/Models/BasicAuthInitialize.cs new file mode 100644 index 0000000..c1b2a71 --- /dev/null +++ b/SessionSampleNoSteeltoe/Models/BasicAuthInitialize.cs @@ -0,0 +1,31 @@ +using Apache.Geode.NetCore; +using System; +using System.Collections.Generic; + +namespace GemFireSessionState.Models +{ + public class BasicAuthInitialize : IAuthInitialize + { + private string _username; + private string _password; + + public BasicAuthInitialize(string username, string password) + { + _username = username; + _password = password; + } + + public void Close() + { + } + + public Dictionary<string, string> GetCredentials() + { + Console.WriteLine("SimpleAuthInitialize::GetCredentials called"); + var credentials = new Dictionary<string, string>(); + credentials.Add("security-username", "root"); + credentials.Add("security-password", "root-password"); + return credentials; + } + } +} \ No newline at end of file diff --git a/SessionSampleNoSteeltoe/Models/ErrorViewModel.cs b/SessionSampleNoSteeltoe/Models/ErrorViewModel.cs new file mode 100644 index 0000000..e67efeb --- /dev/null +++ b/SessionSampleNoSteeltoe/Models/ErrorViewModel.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace SessionSample.Models +{ + public class ErrorViewModel + { + } +} diff --git a/SessionSampleNoSteeltoe/Pages/Error.cshtml b/SessionSampleNoSteeltoe/Pages/Error.cshtml new file mode 100644 index 0000000..6f92b95 --- /dev/null +++ b/SessionSampleNoSteeltoe/Pages/Error.cshtml @@ -0,0 +1,26 @@ +@page +@model ErrorModel +@{ + ViewData["Title"] = "Error"; +} + +<h1 class="text-danger">Error.</h1> +<h2 class="text-danger">An error occurred while processing your request.</h2> + +@if (Model.ShowRequestId) +{ + <p> + <strong>Request ID:</strong> <code>@Model.RequestId</code> + </p> +} + +<h3>Development Mode</h3> +<p> + Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred. +</p> +<p> + <strong>The Development environment shouldn't be enabled for deployed applications.</strong> + It can result in displaying sensitive information from exceptions to end users. + For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong> + and restarting the app. +</p> diff --git a/SessionSampleNoSteeltoe/Pages/Error.cshtml.cs b/SessionSampleNoSteeltoe/Pages/Error.cshtml.cs new file mode 100644 index 0000000..3951f71 --- /dev/null +++ b/SessionSampleNoSteeltoe/Pages/Error.cshtml.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; + +namespace SessionSample.Pages +{ + [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] + public class ErrorModel : PageModel + { + public string RequestId { get; set; } + + public bool ShowRequestId => !string.IsNullOrEmpty(RequestId); + + public void OnGet() + { + RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier; + } + } +} diff --git a/SessionSampleNoSteeltoe/Pages/Index.cshtml b/SessionSampleNoSteeltoe/Pages/Index.cshtml new file mode 100644 index 0000000..3e2c92f --- /dev/null +++ b/SessionSampleNoSteeltoe/Pages/Index.cshtml @@ -0,0 +1,72 @@ +@page +@using Microsoft.AspNetCore.Http +@model IndexModel +@{ + ViewData["Title"] = "Session Sample"; +} + +<h1>@ViewData["Title"]</h1> + +<h2>State management</h2> + +<div class="row"> + <div class="col-md-8"> + <form method="post"> + <div class="panel panel-default"> + <div class="panel-heading"> + <button type="submit" asp-page-handler="ChangeAge" class="pull-right btn btn-danger">Change Age</button> + <h3 class="panel-title" style="line-height:2.1">Name and Age</h3> + </div> + <div class="panel-body"> + <p>The name and age are stored in session. Select the <span style="font-weight:bold">Change Age</span> + button to update the session to a new random age value.</p> + <p>Session values by the model with + <code>@@Model.<PropertyName></code>:</p> + <p><b>Name:</b> @Model.SessionInfo_Name <b>Age:</b> @Model.SessionInfo_Age</p> + <hr> + <p>Session values direct </p> + <p><b>Name:</b> @HttpContext.Session.GetString(IndexModel.SessionKeyName) + <b>Age:</b> + @HttpContext.Session.GetInt32(IndexModel.SessionKeyAge).ToString()</p> + </div> + </div> + </form> + </div> +</div> + +<div class="row"> + <div class="col-md-8"> + <div class="panel panel-default"> + <div class="panel-heading"> + <h3 class="panel-title">HttpContext.Items Middleware Value</h3> + </div> + <div class="panel-body"> + <p>The middleware value is set into the <code>HttpContext.Items</code> collection by + the <code>HttpContextItemsMiddleware</code> before Razor Pages processes the request. + The value is retreived by the page and displayed.</p> + <p>Value: @Model.SessionInfo_MiddlewareValue</p> + </div> + </div> + </div> +</div> + +<div class="row"> + <div class="col-md-8"> + <form method="post"> + <div class="panel panel-default"> + <div class="panel-heading clearfix"> + <button type="submit" asp-page-handler="UpdateSessionDate" class="pull-right btn btn-danger">Update Session Time</button> + <a href="/" class="pull-right btn btn-danger" style="margin-right:5px">Reload Page (No Update)</a> + <h3 class="panel-title" style="line-height:2.1">Session Time</h3> + </div> + <div class="panel-body"> + <p>The session time is stored in session. Select the <span style="font-weight:bold"> + Reload Page (No Update)</span> button to display the current time and the time stored in session. + Select the <span style="font-weight:bold">Update Session Time</span> button to store the current time in session.</p> + <p>Current Time: @Model.SessionInfo_CurrentTime</p> + <p>Session Time: @Model.SessionInfo_SessionTime</p> + </div> + </div> + </form> + </div> +</div> diff --git a/SessionSampleNoSteeltoe/Pages/Index.cshtml.cs b/SessionSampleNoSteeltoe/Pages/Index.cshtml.cs new file mode 100644 index 0000000..59bf24a --- /dev/null +++ b/SessionSampleNoSteeltoe/Pages/Index.cshtml.cs @@ -0,0 +1,77 @@ +using System; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.AspNetCore.Mvc.RazorPages; +using SessionSample.Middleware; +using Web.Extensions; + +namespace SessionSample.Pages +{ + #region snippet1 + public class IndexModel : PageModel + { + public const string SessionKeyName = "_Name"; + public const string SessionKeyAge = "_Age"; + const string SessionKeyTime = "_Time"; + + public string SessionInfo_Name { get; private set; } + public string SessionInfo_Age { get; private set; } + public string SessionInfo_CurrentTime { get; private set; } + public string SessionInfo_SessionTime { get; private set; } + public string SessionInfo_MiddlewareValue { get; private set; } + + public void OnGet() + { + // Requires: using Microsoft.AspNetCore.Http; + if (string.IsNullOrEmpty(HttpContext.Session.GetString(SessionKeyName))) + { + HttpContext.Session.SetString(SessionKeyName, "The Doctor"); + HttpContext.Session.SetInt32(SessionKeyAge, 773); + } + + var name = HttpContext.Session.GetString(SessionKeyName); + var age = HttpContext.Session.GetInt32(SessionKeyAge); + #endregion + SessionInfo_Name = name; + SessionInfo_Age = age.ToString(); + + var currentTime = DateTime.Now; + + #region snippet2 + // Requires SessionExtensions from sample download. + if (HttpContext.Session.Get<DateTime>(SessionKeyTime) == default) + { + HttpContext.Session.Set<DateTime>(SessionKeyTime, currentTime); + } + #endregion + + SessionInfo_CurrentTime = currentTime.ToString("H:mm:ss tt"); + SessionInfo_SessionTime = HttpContext.Session.Get<DateTime>(SessionKeyTime) + .ToString("H:mm:ss tt"); + + #region snippet3 + HttpContext.Items + .TryGetValue(HttpContextItemsMiddleware.HttpContextItemsMiddlewareKey, + out var middlewareSetValue); + SessionInfo_MiddlewareValue = + middlewareSetValue?.ToString() ?? "Middleware value not set!"; + #endregion + } + + public IActionResult OnPostUpdateSessionDate() + { + HttpContext.Session.Set<DateTime>(SessionKeyTime, DateTime.Now); + + return RedirectToPage(); + } + + public IActionResult OnPostChangeAge() + { + var r = new Random(); + + HttpContext.Session.SetInt32(SessionKeyAge, r.Next(500, 1000)); + + return RedirectToPage(); + } + } +} diff --git a/SessionSampleNoSteeltoe/Pages/Shared/_Layout.cshtml b/SessionSampleNoSteeltoe/Pages/Shared/_Layout.cshtml new file mode 100644 index 0000000..b761491 --- /dev/null +++ b/SessionSampleNoSteeltoe/Pages/Shared/_Layout.cshtml @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <title>@ViewData["Title"]</title> + <style>body{margin:0;padding-bottom:20px;font-family:"Helvetica Neue", Helvetica, Arial, sans-serif;font-size:14px;line-height:1.42857143;color:#333;background-color:#fff;}h1{font-size:24px;margin:.67em 0;}pre{overflow:auto;}code,pre{font-family:monospace, monospace;font-size:1em;}button,input{margin:0;font:inherit;color:inherit;}button{overflow:visible;}button{text-transform:none;}input{line-height:normal;}{box-sizing:border-box;}:before,*:after{box-sizing:border-box;}input,button{f [...] +</head> +<body> + <div class="container body-content"> + @RenderBody() + </div> +</body> +</html> diff --git a/SessionSampleNoSteeltoe/Pages/_ViewImports.cshtml b/SessionSampleNoSteeltoe/Pages/_ViewImports.cshtml new file mode 100644 index 0000000..f22da06 --- /dev/null +++ b/SessionSampleNoSteeltoe/Pages/_ViewImports.cshtml @@ -0,0 +1,3 @@ +@using SessionSample +@namespace SessionSample.Pages +@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers diff --git a/SessionSampleNoSteeltoe/Pages/_ViewStart.cshtml b/SessionSampleNoSteeltoe/Pages/_ViewStart.cshtml new file mode 100644 index 0000000..a5f1004 --- /dev/null +++ b/SessionSampleNoSteeltoe/Pages/_ViewStart.cshtml @@ -0,0 +1,3 @@ +@{ + Layout = "_Layout"; +} diff --git a/SessionSampleNoSteeltoe/Program.cs b/SessionSampleNoSteeltoe/Program.cs new file mode 100644 index 0000000..d048ddb --- /dev/null +++ b/SessionSampleNoSteeltoe/Program.cs @@ -0,0 +1,20 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace SessionSample +{ + 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>(); + }); + } +} diff --git a/SessionSampleNoSteeltoe/Properties/launchSettings.json b/SessionSampleNoSteeltoe/Properties/launchSettings.json new file mode 100644 index 0000000..4ebabb5 --- /dev/null +++ b/SessionSampleNoSteeltoe/Properties/launchSettings.json @@ -0,0 +1,28 @@ +{ + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:50795/", + "sslPort": 44315 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "nativeDebugging": true + }, + "SessionSample": { + "commandName": "Project", + "launchBrowser": true, + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + }, + "applicationUrl": "https://localhost:5001;http://localhost:5000" + } + } +} \ No newline at end of file diff --git a/SessionSampleNoSteeltoe/SessionSampleNoSteeltoe.csproj b/SessionSampleNoSteeltoe/SessionSampleNoSteeltoe.csproj new file mode 100644 index 0000000..fb587cb --- /dev/null +++ b/SessionSampleNoSteeltoe/SessionSampleNoSteeltoe.csproj @@ -0,0 +1,13 @@ +<Project Sdk="Microsoft.NET.Sdk.Web"> + + <PropertyGroup> + <TargetFramework>netcoreapp3.1</TargetFramework> + <Platforms>x64</Platforms> + </PropertyGroup> + + <ItemGroup> + <ProjectReference Include="..\NetCore.Session\NetCore.Session.csproj" /> + </ItemGroup> + + +</Project> diff --git a/SessionSampleNoSteeltoe/SessionSampleNoSteeltoe.csproj.user b/SessionSampleNoSteeltoe/SessionSampleNoSteeltoe.csproj.user new file mode 100644 index 0000000..cff74a9 --- /dev/null +++ b/SessionSampleNoSteeltoe/SessionSampleNoSteeltoe.csproj.user @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <PropertyGroup> + <ActiveDebugProfile>IIS Express</ActiveDebugProfile> + </PropertyGroup> +</Project> \ No newline at end of file diff --git a/SessionSampleNoSteeltoe/SessionSampleNoSteeltoe.sln b/SessionSampleNoSteeltoe/SessionSampleNoSteeltoe.sln new file mode 100644 index 0000000..4f6c0fb --- /dev/null +++ b/SessionSampleNoSteeltoe/SessionSampleNoSteeltoe.sln @@ -0,0 +1,31 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30028.174 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionSample", "SessionSample.csproj", "{0073CD89-8ED5-42DC-8C0F-88036A11AE91}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Debug|x64 = Debug|x64 + Release|Any CPU = Release|Any CPU + Release|x64 = Release|x64 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Debug|Any CPU.ActiveCfg = Debug|x64 + {0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Debug|Any CPU.Build.0 = Debug|x64 + {0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Debug|x64.ActiveCfg = Debug|x64 + {0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Debug|x64.Build.0 = Debug|x64 + {0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Release|Any CPU.ActiveCfg = Release|Any CPU + {0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Release|Any CPU.Build.0 = Release|Any CPU + {0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Release|x64.ActiveCfg = Release|x64 + {0073CD89-8ED5-42DC-8C0F-88036A11AE91}.Release|x64.Build.0 = Release|x64 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {EA7D931C-E9EA-4F8A-B4EA-18C5322FC048} + EndGlobalSection +EndGlobal diff --git a/SessionSampleNoSteeltoe/Startup.cs b/SessionSampleNoSteeltoe/Startup.cs new file mode 100644 index 0000000..466ebff --- /dev/null +++ b/SessionSampleNoSteeltoe/Startup.cs @@ -0,0 +1,91 @@ +using GemFireSessionState.Models; +using Apache.Geode.Session; +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Hosting; +using SessionSample.Middleware; +using Microsoft.Extensions.Caching.Distributed; +using System; +using Apache.Geode.NetCore; + +namespace SessionSample +{ + #region snippet1 + public class Startup + { + private readonly IConfiguration _config; + private readonly IWebHostEnvironment _hostContext; + + public Startup(IConfiguration config, IWebHostEnvironment hostContext) + { + _config = config; + _hostContext = hostContext; + } + + public void ConfigureServices(IServiceCollection services) + { + //services.AddGemFireConnection(Configuration, typeof(BasicAuthInitialize), loggerFactory: LoggerFactory); + + // TODO: Don't hardcode region name here + //services.AddSingleton<IDistributedCache>((isp) => new SessionStateCache(isp.GetRequiredService<Cache>(), "NetCoreSession", isp.GetService<ILogger<SessionStateCache>>())); + //services.AddScoped<IDistributedCache, SessionStateCache>(); + + services.AddsSessionStateCache(options => + { + //options.IdleTimeout = TimeSpan.FromSeconds(5); + //options.Cookie.HttpOnly = true; + //options.Cookie.IsEssential = true; + using var cacheFactory = CacheFactory.Create() + .SetProperty("log-level", "none"); + + using var cache = (Cache)cacheFactory.CreateCache(); + + using var poolFactory = cache.PoolFactory.AddLocator("localhost", 10334); + using var pool = poolFactory.CreatePool("myPool"); + + using var ssCache = new SessionStateCache(cache, "exampleRegion"); + }); + //services.AddSingleton<IDistributedCache>((isp) => new SessionStateCache(isp.GetRequiredService<Cache>(), "exampleRegion", isp.GetService<ILogger<SessionStateCache>>())); + + + services.AddControllersWithViews(); + services.AddRazorPages(); + } + + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + } + else + { + app.UseExceptionHandler("/Home/Error"); + app.UseHsts(); + } + app.UseHttpsRedirection(); + app.UseStaticFiles(); + app.UseCookiePolicy(); + + + app.UseHttpContextItemsMiddleware(); + + app.UseRouting(); + + //app.UseAuthentication(); + //app.UseAuthorization(); + + app.UseSession(); + + app.UseEndpoints(endpoints => + { + endpoints.MapDefaultControllerRoute(); + endpoints.MapRazorPages(); + }); + } + } + #endregion +} diff --git a/SessionSampleNoSteeltoe/appsettings.Development.json b/SessionSampleNoSteeltoe/appsettings.Development.json new file mode 100644 index 0000000..0623a3f --- /dev/null +++ b/SessionSampleNoSteeltoe/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Debug", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/SessionSampleNoSteeltoe/appsettings.Production.json b/SessionSampleNoSteeltoe/appsettings.Production.json new file mode 100644 index 0000000..8af1e1f --- /dev/null +++ b/SessionSampleNoSteeltoe/appsettings.Production.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Error", + "System": "Information", + "Microsoft": "Information" + } + } +} diff --git a/SessionSampleNoSteeltoe/appsettings.json b/SessionSampleNoSteeltoe/appsettings.json new file mode 100644 index 0000000..b7c4ed9 --- /dev/null +++ b/SessionSampleNoSteeltoe/appsettings.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/ci/pipeline.yml b/ci/pipeline.yml index 04c3f86..488d8b4 100644 --- a/ci/pipeline.yml +++ b/ci/pipeline.yml @@ -56,6 +56,7 @@ jobs: cd package-ubuntu-20.0.4-debug-archive tar xvf apache-geode-native-1.15.0-build.46-Linux-64bit.tar.gz # geode-native install now in apache-geode-native + docker pull kitware/cmake cd .. cd ./netcore-source dotnet restore diff --git a/geode-dotnet-core.sln b/geode-dotnet-core.sln index 2f1a398..2099b5b 100644 --- a/geode-dotnet-core.sln +++ b/geode-dotnet-core.sln @@ -17,62 +17,98 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore.Session.Integration EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionSample", "SessionSample\SessionSample.csproj", "{6D0D1D93-917E-48EE-977C-16F65DB982BE}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SessionSampleNoSteeltoe", "SessionSampleNoSteeltoe\SessionSampleNoSteeltoe.csproj", "{A8BF122B-D8E8-4CEF-B60D-32A7560C1D02}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Debug|Any CPU.Build.0 = Debug|Any CPU {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Debug|x64.ActiveCfg = Debug|x64 {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Debug|x64.Build.0 = Debug|x64 + {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Debug|x86.ActiveCfg = Debug|Any CPU + {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Debug|x86.Build.0 = Debug|Any CPU {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Release|Any CPU.ActiveCfg = Release|Any CPU {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Release|Any CPU.Build.0 = Release|Any CPU {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Release|x64.ActiveCfg = Release|Any CPU {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Release|x64.Build.0 = Release|Any CPU + {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Release|x86.ActiveCfg = Release|Any CPU + {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Release|x86.Build.0 = Release|Any CPU {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Debug|Any CPU.Build.0 = Debug|Any CPU {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Debug|x64.ActiveCfg = Debug|x64 {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Debug|x64.Build.0 = Debug|x64 + {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Debug|x86.ActiveCfg = Debug|Any CPU + {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Debug|x86.Build.0 = Debug|Any CPU {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Release|Any CPU.ActiveCfg = Release|Any CPU {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Release|Any CPU.Build.0 = Release|Any CPU {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Release|x64.ActiveCfg = Release|Any CPU {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Release|x64.Build.0 = Release|Any CPU + {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Release|x86.ActiveCfg = Release|Any CPU + {501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}.Release|x86.Build.0 = Release|Any CPU {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Debug|Any CPU.Build.0 = Debug|Any CPU {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Debug|x64.ActiveCfg = Debug|x64 {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Debug|x64.Build.0 = Debug|x64 + {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Debug|x86.ActiveCfg = Debug|Any CPU + {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Debug|x86.Build.0 = Debug|Any CPU {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Release|Any CPU.ActiveCfg = Release|Any CPU {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Release|Any CPU.Build.0 = Release|Any CPU {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Release|x64.ActiveCfg = Release|Any CPU {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Release|x64.Build.0 = Release|Any CPU + {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Release|x86.ActiveCfg = Release|Any CPU + {CC1FEC64-9AD6-4A69-ADF2-038CF67A8590}.Release|x86.Build.0 = Release|Any CPU {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Debug|Any CPU.Build.0 = Debug|Any CPU {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Debug|x64.ActiveCfg = Debug|x64 {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Debug|x64.Build.0 = Debug|x64 + {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Debug|x86.ActiveCfg = Debug|Any CPU + {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Debug|x86.Build.0 = Debug|Any CPU {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Release|Any CPU.ActiveCfg = Release|Any CPU {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Release|Any CPU.Build.0 = Release|Any CPU {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Release|x64.ActiveCfg = Release|Any CPU {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Release|x64.Build.0 = Release|Any CPU + {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Release|x86.ActiveCfg = Release|Any CPU + {C107D019-3B4F-403D-9040-ECB6E86C44E9}.Release|x86.Build.0 = Release|Any CPU {742B4109-544E-492E-86AC-DC1E0FCCA596}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {742B4109-544E-492E-86AC-DC1E0FCCA596}.Debug|Any CPU.Build.0 = Debug|Any CPU {742B4109-544E-492E-86AC-DC1E0FCCA596}.Debug|x64.ActiveCfg = Debug|x64 {742B4109-544E-492E-86AC-DC1E0FCCA596}.Debug|x64.Build.0 = Debug|x64 + {742B4109-544E-492E-86AC-DC1E0FCCA596}.Debug|x86.ActiveCfg = Debug|Any CPU + {742B4109-544E-492E-86AC-DC1E0FCCA596}.Debug|x86.Build.0 = Debug|Any CPU {742B4109-544E-492E-86AC-DC1E0FCCA596}.Release|Any CPU.ActiveCfg = Release|Any CPU {742B4109-544E-492E-86AC-DC1E0FCCA596}.Release|Any CPU.Build.0 = Release|Any CPU {742B4109-544E-492E-86AC-DC1E0FCCA596}.Release|x64.ActiveCfg = Release|Any CPU {742B4109-544E-492E-86AC-DC1E0FCCA596}.Release|x64.Build.0 = Release|Any CPU + {742B4109-544E-492E-86AC-DC1E0FCCA596}.Release|x86.ActiveCfg = Release|Any CPU + {742B4109-544E-492E-86AC-DC1E0FCCA596}.Release|x86.Build.0 = Release|Any CPU {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Debug|Any CPU.Build.0 = Debug|Any CPU {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Debug|x64.ActiveCfg = Debug|x64 {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Debug|x64.Build.0 = Debug|x64 + {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Debug|x86.ActiveCfg = Debug|x86 + {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Debug|x86.Build.0 = Debug|x86 {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Release|Any CPU.ActiveCfg = Release|Any CPU {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Release|Any CPU.Build.0 = Release|Any CPU {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Release|x64.ActiveCfg = Release|x64 {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Release|x64.Build.0 = Release|x64 + {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Release|x86.ActiveCfg = Release|x86 + {6D0D1D93-917E-48EE-977C-16F65DB982BE}.Release|x86.Build.0 = Release|x86 + {A8BF122B-D8E8-4CEF-B60D-32A7560C1D02}.Debug|Any CPU.ActiveCfg = Debug|x64 + {A8BF122B-D8E8-4CEF-B60D-32A7560C1D02}.Debug|x64.ActiveCfg = Debug|x64 + {A8BF122B-D8E8-4CEF-B60D-32A7560C1D02}.Debug|x64.Build.0 = Debug|x64 + {A8BF122B-D8E8-4CEF-B60D-32A7560C1D02}.Debug|x86.ActiveCfg = Debug|x64 + {A8BF122B-D8E8-4CEF-B60D-32A7560C1D02}.Release|Any CPU.ActiveCfg = Release|x64 + {A8BF122B-D8E8-4CEF-B60D-32A7560C1D02}.Release|x64.ActiveCfg = Release|x64 + {A8BF122B-D8E8-4CEF-B60D-32A7560C1D02}.Release|x64.Build.0 = Release|x64 + {A8BF122B-D8E8-4CEF-B60D-32A7560C1D02}.Release|x86.ActiveCfg = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -82,6 +118,7 @@ Global {C107D019-3B4F-403D-9040-ECB6E86C44E9} = {38D87C7D-D5FE-43B8-80CC-1CE70167FB69} {742B4109-544E-492E-86AC-DC1E0FCCA596} = {38D87C7D-D5FE-43B8-80CC-1CE70167FB69} {6D0D1D93-917E-48EE-977C-16F65DB982BE} = {38D87C7D-D5FE-43B8-80CC-1CE70167FB69} + {A8BF122B-D8E8-4CEF-B60D-32A7560C1D02} = {38D87C7D-D5FE-43B8-80CC-1CE70167FB69} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {B30A49F0-1C96-4D6C-A222-0088B1D7FBBE}