<commit_before>using System;
using System.Collections.Generic;

using Microsoft.AspNetCore.Http;

namespace Epos.Utilities.Web
{
    internal class ObjectSession : IObjectSession
    {
        private const string ObjectSessionKey = "ObjectSession";

        private readonly IHttpContextAccessor myHttpContextAccessor;
        private static readonly Dictionary<Guid, IDictionary<string, object>> mySession =
            new Dictionary<Guid, IDictionary<string, object>>();

        public ObjectSession(IHttpContextAccessor httpContextAccessor) {
            myHttpContextAccessor = httpContextAccessor;
        }

        public object this[string key] {
            get {
                var theGuidString = myHttpContextAccessor.HttpContext.Session.GetString(ObjectSessionKey);
                if (theGuidString == null) {
                    return null;
                }

                Guid theGuid = Guid.Parse(theGuidString);

                var theSession = mySession.Get(theGuid);
                if (theSession == null) {
                    theSession = new Dictionary<string, object>();
                    mySession[theGuid] = theSession;
                }

                return theSession.Get(key);
            }

            set {
                var theGuidString = myHttpContextAccessor.HttpContext.Session.GetString(ObjectSessionKey);
                if (theGuidString == null) {
                    theGuidString = Guid.NewGuid().ToString();
                    myHttpContextAccessor.HttpContext.Session.SetString(ObjectSessionKey, theGuidString);
                }

                Guid theGuid = Guid.Parse(theGuidString);

                var theSession = mySession.Get(theGuid);
                if (theSession == null) {
                    theSession = new Dictionary<string, object>();
                    mySession[theGuid] = theSession;
                }

                theSession[key] = value;
            }
        }
    }
}<commit_msg>Make ObjectSession thread-safe<commit_after>using System;
using System.Collections.Concurrent;
using System.Collections.Generic;

using Microsoft.AspNetCore.Http;

namespace Epos.Utilities.Web
{
    internal class ObjectSession : IObjectSession
    {
        private const string ObjectSessionKey = "ObjectSession";

        private readonly IHttpContextAccessor myHttpContextAccessor;
        private static readonly IDictionary<Guid, IDictionary<string, object>> mySession =
            new ConcurrentDictionary<Guid, IDictionary<string, object>>();

        public ObjectSession(IHttpContextAccessor httpContextAccessor) {
            myHttpContextAccessor = httpContextAccessor;
        }

        public object this[string key] {
            get {
                string theGuidString = myHttpContextAccessor.HttpContext.Session.GetString(ObjectSessionKey);
                if (theGuidString == null) {
                    return null;
                }

                var theGuid = Guid.Parse(theGuidString);

                IDictionary<string, object> theSession = mySession.Get(theGuid);
                if (theSession == null) {
                    theSession = new Dictionary<string, object>();
                    mySession[theGuid] = theSession;
                }

                return theSession.Get(key);
            }

            set {
                string theGuidString = myHttpContextAccessor.HttpContext.Session.GetString(ObjectSessionKey);
                if (theGuidString == null) {
                    theGuidString = Guid.NewGuid().ToString();
                    myHttpContextAccessor.HttpContext.Session.SetString(ObjectSessionKey, theGuidString);
                }

                var theGuid = Guid.Parse(theGuidString);

                IDictionary<string, object> theSession = mySession.Get(theGuid);
                if (theSession == null) {
                    theSession = new Dictionary<string, object>();
                    mySession[theGuid] = theSession;
                }

                theSession[key] = value;
            }
        }
    }
}
{'fraction_non_alphanumeric': 0.07917383820998279, 'fraction_numerical': 0.0, 'mean_word_length': 1.8688293370944993, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5522374', 'n_tokens_mistral': 980, 'n_tokens_neox': 914, 'n_words': 196}