コード例 #1
0
        private Task <Result <TSession> > CreateSessionAsync(
            OperationContext context,
            TSessionData sessionData,
            string cacheName,
            int id,
            long sessionExpirationUtcTicks)
        {
            return(context.PerformOperationAsync(
                       Tracer,
                       async() =>
            {
                TrySetBuildId(sessionData.Name);
                if (!StoresByName.TryGetValue(cacheName, out var store))
                {
                    return Result.FromErrorMessage <TSession>($"Cache by name=[{cacheName}] is not available");
                }

                var result = CreateSession(store, context, sessionData).ThrowIfFailure();

                var session = result.Session !;    // Still need to use '!' here because the compiler doesn't know the semantics of 'ThrowIfFailure'.
                await session.StartupAsync(context).ThrowIfFailure();

                var handle = new SessionHandle <TSession, TSessionData>(
                    session,
                    sessionData,
                    cacheName,
                    sessionExpirationUtcTicks,
                    GetTimeoutForCapabilities(sessionData.Capabilities));

                bool added = _sessionHandles.TryAdd(id, handle);
                Contract.Check(added)?.Assert($"The session with id '{id}' is already created.");
                Tracer.Debug(context, $"{nameof(CreateSessionAsync)} created session {handle.ToString(id)}.");
                return Result.Success(session);
            }));
コード例 #2
0
        private Task <Result <TSession> > CreateSessionAsync(
            OperationContext context,
            string name,
            string cacheName,
            ImplicitPin implicitPin,
            int id,
            long sessionExpirationUtcTicks,
            Capabilities capabilities)
        {
            return(context.PerformOperationAsync(
                       Tracer,
                       async() =>
            {
                TrySetBuildId(name);
                if (!StoresByName.TryGetValue(cacheName, out var store))
                {
                    return Result.FromErrorMessage <TSession>($"Cache by name=[{cacheName}] is not available");
                }

                var result = CreateSession(store, context, name, implicitPin).ThrowIfFailure();

                var session = result.Session;
                await session.StartupAsync(context).ThrowIfFailure();

                var handle = new SessionHandle <TSession>(
                    session,
                    name,
                    cacheName,
                    implicitPin,
                    capabilities,
                    sessionExpirationUtcTicks,
                    GetTimeoutForCapabilities(capabilities));

                bool added = _sessionHandles.TryAdd(id, handle);
                if (!added)
                {
                    // CreateSession should not be called for an id that is already presented in the internal map.
                    // The class members fully control the creation process, and the fact that the session is created is indication of a bug.
                    Contract.Assert(false, $"The session with id '{id}' is already created.");
                }

                Tracer.Debug(context, $"{nameof(CreateSessionAsync)} created session {handle.ToString(id)}.");
                return Result.Success(session);
            }));
コード例 #3
0
        private Task <Result <TSession> > CreateSessionAsync(
            OperationContext context,
            string name,
            string cacheName,
            ImplicitPin implicitPin,
            int id,
            long sessionExpirationUtcTicks,
            Capabilities capabilities)
        {
            return(context.PerformOperationAsync(
                       Tracer,
                       async() =>
            {
                TrySetBuildId(name);
                if (!StoresByName.TryGetValue(cacheName, out var store))
                {
                    return Result.FromErrorMessage <TSession>($"Cache by name=[{cacheName}] is not available");
                }

                var result = CreateSession(store, context, name, implicitPin).ThrowIfFailure();

                var session = result.Session !;
                await session.StartupAsync(context).ThrowIfFailure();

                var handle = new SessionHandle <TSession>(
                    session,
                    name,
                    cacheName,
                    implicitPin,
                    capabilities,
                    sessionExpirationUtcTicks,
                    GetTimeoutForCapabilities(capabilities));

                bool added = _sessionHandles.TryAdd(id, handle);
                Contract.Check(added)?.Assert($"The session with id '{id}' is already created.");
                Tracer.Debug(context, $"{nameof(CreateSessionAsync)} created session {handle.ToString(id)}.");
                return Result.Success(session);
            }));