[ https://issues.apache.org/jira/browse/GEODE-9359?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17390749#comment-17390749 ]
ASF GitHub Bot commented on GEODE-9359: --------------------------------------- pivotal-jbarrett commented on a change in pull request #834: URL: https://github.com/apache/geode-native/pull/834#discussion_r680154554 ########## File path: netcore/NetCore.Session/NetCoreSessionState.cs ########## @@ -0,0 +1,299 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using Apache.Geode.Client; +using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Apache.Geode.Session { + public class GeodeSessionStateValue { + public GeodeSessionStateValue() {} + public GeodeSessionStateValue(byte[] value) { + FromByteArray(value); + } + + public byte[] Value { get; set; } + public DateTime LastAccessTimeUtc { get; set; } + public DateTime ExpirationTimeUtc { get; set; } = DateTime.MinValue; + public TimeSpan SpanUntilStale { get; set; } = TimeSpan.Zero; + + public byte[] ToByteArray() { + int neededBytes = 3 * sizeof(long) + Value.Length; + byte[] byteArray = new byte[neededBytes]; + int byteIndex = 0; + + Array.Copy(BitConverter.GetBytes(LastAccessTimeUtc.Ticks), 0, byteArray, byteIndex, + sizeof(long)); + byteIndex += sizeof(long); + + Array.Copy(BitConverter.GetBytes(ExpirationTimeUtc.Ticks), 0, byteArray, byteIndex, + sizeof(long)); + byteIndex += sizeof(long); + + Array.Copy(BitConverter.GetBytes(SpanUntilStale.Ticks), 0, byteArray, byteIndex, + sizeof(long)); + byteIndex += sizeof(long); + + Array.Copy(Value, 0, byteArray, byteIndex, Value.Length); + return byteArray; + } + + public void FromByteArray(byte[] data) { + int byteIndex = 0; + + LastAccessTimeUtc = DateTime.FromBinary(BitConverter.ToInt64(data, byteIndex)); + byteIndex += sizeof(long); + + ExpirationTimeUtc = DateTime.FromBinary(BitConverter.ToInt64(data, byteIndex)); + byteIndex += sizeof(long); + + SpanUntilStale = TimeSpan.FromTicks(BitConverter.ToInt64(data, byteIndex)); + byteIndex += sizeof(long); + + Value = new byte[data.Length - byteIndex]; + Array.Copy(data, byteIndex, Value, 0, data.Length - byteIndex); + } + } + + public class GeodeSessionStateCache : GeodeNativeObject, IDistributedCache { + private readonly IGeodeCache _cache; + private ILogger<GeodeSessionStateCache> _logger; + private static Region _region; + private string _logLevel; + private string _logFile; + private string _regionName; + private readonly SemaphoreSlim _connectLock = new SemaphoreSlim(initialCount: 1, maxCount: 1); + + public GeodeSessionStateCache(IOptions<GeodeSessionStateCacheOptions> optionsAccessor) { + var host = optionsAccessor.Value.Host; + var port = optionsAccessor.Value.Port; + _regionName = optionsAccessor.Value.RegionName; + _logLevel = optionsAccessor.Value.LogLevel; + _logFile = optionsAccessor.Value.LogFile; + + _cache = CacheFactory.Create() + .SetProperty("log-level", _logLevel) + .SetProperty("log-file", _logFile) + .CreateCache(); + + _cache.PoolManager.CreatePoolFactory().AddLocator(host, port).CreatePool("pool"); + + var regionFactory = _cache.CreateRegionFactory(RegionShortcut.Proxy); + _region = regionFactory.CreateRegion(_regionName); + } + + // Returns the SessionStateValue for key, or null if key doesn't exist + public GeodeSessionStateValue GetValueForKey(string key) { + var cacheValue = _region.GetByteArray(key); + + if (cacheValue != null) { + return new GeodeSessionStateValue(cacheValue); + } else + return null; + } + + public byte[] Get(string key) { + if (key == null) { + throw new ArgumentNullException(nameof(key)); + } + + Connect(); + + // Check for nonexistent key + GeodeSessionStateValue ssValue = GetValueForKey(key); Review comment: `var` ########## File path: netcore/NetCore.Session/NetCoreSessionState.cs ########## @@ -0,0 +1,299 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +using Apache.Geode.Client; +using Microsoft.Extensions.Caching.Distributed; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Options; +using System; +using System.Threading; +using System.Threading.Tasks; + +namespace Apache.Geode.Session { + public class GeodeSessionStateValue { + public GeodeSessionStateValue() {} + public GeodeSessionStateValue(byte[] value) { + FromByteArray(value); + } + + public byte[] Value { get; set; } + public DateTime LastAccessTimeUtc { get; set; } + public DateTime ExpirationTimeUtc { get; set; } = DateTime.MinValue; + public TimeSpan SpanUntilStale { get; set; } = TimeSpan.Zero; + + public byte[] ToByteArray() { + int neededBytes = 3 * sizeof(long) + Value.Length; + byte[] byteArray = new byte[neededBytes]; + int byteIndex = 0; + + Array.Copy(BitConverter.GetBytes(LastAccessTimeUtc.Ticks), 0, byteArray, byteIndex, + sizeof(long)); + byteIndex += sizeof(long); + + Array.Copy(BitConverter.GetBytes(ExpirationTimeUtc.Ticks), 0, byteArray, byteIndex, + sizeof(long)); + byteIndex += sizeof(long); + + Array.Copy(BitConverter.GetBytes(SpanUntilStale.Ticks), 0, byteArray, byteIndex, + sizeof(long)); + byteIndex += sizeof(long); + + Array.Copy(Value, 0, byteArray, byteIndex, Value.Length); + return byteArray; + } + + public void FromByteArray(byte[] data) { + int byteIndex = 0; + + LastAccessTimeUtc = DateTime.FromBinary(BitConverter.ToInt64(data, byteIndex)); + byteIndex += sizeof(long); + + ExpirationTimeUtc = DateTime.FromBinary(BitConverter.ToInt64(data, byteIndex)); + byteIndex += sizeof(long); + + SpanUntilStale = TimeSpan.FromTicks(BitConverter.ToInt64(data, byteIndex)); + byteIndex += sizeof(long); + + Value = new byte[data.Length - byteIndex]; + Array.Copy(data, byteIndex, Value, 0, data.Length - byteIndex); + } + } + + public class GeodeSessionStateCache : GeodeNativeObject, IDistributedCache { + private readonly IGeodeCache _cache; + private ILogger<GeodeSessionStateCache> _logger; + private static Region _region; + private string _logLevel; + private string _logFile; + private string _regionName; + private readonly SemaphoreSlim _connectLock = new SemaphoreSlim(initialCount: 1, maxCount: 1); + + public GeodeSessionStateCache(IOptions<GeodeSessionStateCacheOptions> optionsAccessor) { + var host = optionsAccessor.Value.Host; + var port = optionsAccessor.Value.Port; + _regionName = optionsAccessor.Value.RegionName; + _logLevel = optionsAccessor.Value.LogLevel; + _logFile = optionsAccessor.Value.LogFile; + + _cache = CacheFactory.Create() + .SetProperty("log-level", _logLevel) + .SetProperty("log-file", _logFile) + .CreateCache(); + + _cache.PoolManager.CreatePoolFactory().AddLocator(host, port).CreatePool("pool"); + + var regionFactory = _cache.CreateRegionFactory(RegionShortcut.Proxy); + _region = regionFactory.CreateRegion(_regionName); + } + + // Returns the SessionStateValue for key, or null if key doesn't exist + public GeodeSessionStateValue GetValueForKey(string key) { + var cacheValue = _region.GetByteArray(key); + + if (cacheValue != null) { + return new GeodeSessionStateValue(cacheValue); + } else + return null; + } + + public byte[] Get(string key) { + if (key == null) { + throw new ArgumentNullException(nameof(key)); + } + + Connect(); + + // Check for nonexistent key + GeodeSessionStateValue ssValue = GetValueForKey(key); + if (ssValue == null) { + return null; + } + + // Check for expired key + DateTime nowUtc = DateTime.UtcNow; Review comment: Still a few more local variables that should be `var`. ########## File path: netcore/NetCore.Session.IntegrationTests/NetCore.Session.IntegrationTests.csproj ########## @@ -0,0 +1,23 @@ +<Project Sdk="Microsoft.NET.Sdk"> + + <PropertyGroup> + <TargetFramework>netcoreapp3.1</TargetFramework> + + <IsPackable>false</IsPackable> + + <Platforms>x64</Platforms> + </PropertyGroup> + + <ItemGroup> + <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" /> Review comment: Inconsistent indentations. ########## File path: netcore/geode-dotnet-core.sln ########## @@ -7,24 +7,56 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore", "NetCore\NetCore. EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore.Test", "NetCore.Test\NetCore.Test.csproj", "{501DEA7E-8985-42A8-8BC9-C073E1B6DFE0}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Session", "Session", "{520C96EC-F929-4365-8D78-CC5785419B62}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore.Session", "NetCore.Session\NetCore.Session.csproj", "{B88C58EB-B144-403B-85F7-7A5B45E643E3}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NetCore.Session.IntegrationTests", "NetCore.Session.IntegrationTests\NetCore.Session.IntegrationTests.csproj", "{94D2CD59-A5F3-4504-BF01-0A3B95CE12B5}" +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 + {09ABBCE7-B217-43F1-A51B-CC5BDCD8EE98}.Debug|Any CPU.ActiveCfg = Debug|x64 Review comment: You still need to remove the `Any CPU` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@geode.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org > add net-core-session to geode-native > ------------------------------------ > > Key: GEODE-9359 > URL: https://issues.apache.org/jira/browse/GEODE-9359 > Project: Geode > Issue Type: New Feature > Components: native client > Reporter: Ernest Burghardt > Priority: Major > Labels: pull-request-available > > net-core-session shall be added to the top level of geode-native repo and > will produce a separate binary that will be publishable to NuGet > https://docs.microsoft.com/en-us/nuget/create-packages/package-authoring-best-practices -- This message was sent by Atlassian Jira (v8.3.4#803005)