示例#1
0
        /// <inheritdoc />
        protected override async Task <BoolResult> StartupCoreAsync(OperationContext context)
        {
            (var contentStoreResult, var memoizationStoreResult) = await CreateAndStartStoresAsync(context);

            Contract.Assert(ContentStore != null, "Content store must be initialized");
            Contract.Assert(MemoizationStore != null, "Memoization store must be initialized");
            Contract.Assert(!ReferenceEquals(ContentStore, MemoizationStore));

            BoolResult result;

            if (!contentStoreResult.Succeeded || !memoizationStoreResult.Succeeded)
            {
                var sb = new StringBuilder();

                if (contentStoreResult.Succeeded)
                {
                    var r = await ContentStore.ShutdownAsync(context).ConfigureAwait(false);

                    if (!r.Succeeded)
                    {
                        sb.Append($"Content store shutdown failed, error=[{r}]");
                    }
                }
                else
                {
                    sb.Append($"Content store startup failed, error=[{contentStoreResult}]");
                }

                if (memoizationStoreResult.Succeeded)
                {
                    var r = await MemoizationStore.ShutdownAsync(context).ConfigureAwait(false);

                    if (!r.Succeeded)
                    {
                        sb.Append(sb.Length > 0 ? ", " : string.Empty);
                        sb.Append($"Memoization store shutdown failed, error=[{memoizationStoreResult}]");
                    }
                }
                else
                {
                    sb.Append(sb.Length > 0 ? ", " : string.Empty);
                    sb.Append($"Memoization store startup failed, error=[{memoizationStoreResult}]");
                }

                result = new BoolResult(sb.ToString());
            }
            else
            {
                result = BoolResult.Success;
            }

            return(result);
        }
示例#2
0
        /// <inheritdoc />
        protected override async Task <BoolResult> ShutdownCoreAsync(OperationContext context)
        {
            var statsResult = await StatsAsync(context).ConfigureAwait(false);

            var contentStoreTask       = Task.Run(() => ContentStore.ShutdownAsync(context));
            var memoizationStoreResult = await MemoizationStore.ShutdownAsync(context).ConfigureAwait(false);

            var contentStoreResult = await contentStoreTask.ConfigureAwait(false);

            BoolResult result;

            if (contentStoreResult.Succeeded && memoizationStoreResult.Succeeded)
            {
                result = BoolResult.Success;
            }
            else
            {
                var sb = new StringBuilder();
                if (!contentStoreResult.Succeeded)
                {
                    sb.Append($"Content store shutdown failed, error=[{contentStoreResult}]");
                }

                if (!memoizationStoreResult.Succeeded)
                {
                    sb.Append(sb.Length > 0 ? ", " : string.Empty);
                    sb.Append($"Memoization store shutdown failed, error=[{memoizationStoreResult}]");
                }

                result = new BoolResult(sb.ToString());
            }

            if (statsResult.Succeeded)
            {
#if NET_FRAMEWORK
                LocalCacheStatsEventSource.Instance.Stats(statsResult.CounterSet);
#endif
                statsResult.CounterSet.LogOrderedNameValuePairs(s => Tracer.Debug(context, s));
            }

            return(result);
        }
示例#3
0
        protected override async Task <BoolResult> StartupCoreAsync(OperationContext context)
        {
            var(contentStoreResult, memoizationStoreResult) = await CreateAndStartStoresAsync(context);

            if (contentStoreResult.Succeeded && memoizationStoreResult.Succeeded)
            {
                // The properties must be initialized but only when the startup succeeded.
                Contract.Assert(ContentStore != null, "Content store must be initialized");
                Contract.Assert(MemoizationStore != null, "Memoization store must be initialized");
                Contract.Assert(!ReferenceEquals(ContentStore, MemoizationStore), "ContentStore and MemoizationStore should not be the same.");

                return(BoolResult.Success);
            }
            else
            {
                // One of the startup operations failed.
                var sb = new StringBuilder();

                AppendIfError(sb, "Content store startup", contentStoreResult);

                if (contentStoreResult)
                {
                    Contract.Assert(ContentStore != null, "Content store must be initialized");
                    var r = await ContentStore.ShutdownAsync(context).ConfigureAwait(false);

                    AppendIfError(sb, "Content store shutdown", r);
                }

                AppendIfError(sb, "Memoization store startup", memoizationStoreResult);
                if (memoizationStoreResult)
                {
                    Contract.Assert(MemoizationStore != null, "Memoization store must be initialized");
                    var r = await MemoizationStore.ShutdownAsync(context).ConfigureAwait(false);

                    AppendIfError(sb, "Memoization store shutdown", r);
                }

                return(new BoolResult(sb.ToString()));
            }
        }