static async Task <int> RunStore(Context context, IMemoizationStore store) { try { try { StartupResult startupResult = await store.StartupAsync(context).ConfigureAwait(false); if (startupResult.HasError) { throw new CacheException($"Failed to start store, error=[{startupResult.ErrorMessage}]"); } var createSessionResult = store.CreateSession(context, "sample"); if (createSessionResult.HasError) { throw new CacheException($"Failed to create session, error=[{createSessionResult.ErrorMessage}]"); } using (var session = createSessionResult.Session) { try { var sessionStartupResult = session.StartupAsync(context).Result; if (sessionStartupResult.HasError) { throw new CacheException($"Failed to start session, error=[{createSessionResult.ErrorMessage}]"); } } finally { var sessionShutdownResult = session.ShutdownAsync(context).Result; if (sessionShutdownResult.HasError) { context.Error($"Failed to shutdown session, error=[{sessionShutdownResult.ErrorMessage}]"); } } } } finally { ShutdownResult shutdownResult = await store.ShutdownAsync(context).ConfigureAwait(false); if (shutdownResult.HasError) { context.Error($"Failed to shutdown store, error=[{shutdownResult.ErrorMessage}]"); } } return(0); } catch (Exception) { return(1); } }
/// <inheritdoc /> public Task <BoolResult> StartupAsync(Context context) { StartupStarted = true; return(StartupCall <CacheTracer> .RunAsync(_tracer, context, async() => { var preStartupResult = await PreStartupAsync(context).ConfigureAwait(false); if (!preStartupResult.Succeeded) { return preStartupResult; } var contentStoreTask = Task.Run(() => ContentStore.StartupAsync(context)); var memoizationStoreResult = await MemoizationStore.StartupAsync(context).ConfigureAwait(false); var contentStoreResult = await contentStoreTask.ConfigureAwait(false); 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.AppendFormat($"Content store shutdown failed, error=[{r}]"); } } else { sb.AppendFormat($"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.AppendFormat($"Memoization store shutdown failed, error=[{memoizationStoreResult}]"); } } else { sb.Append(sb.Length > 0 ? ", " : string.Empty); sb.AppendFormat($"Memoization store startup failed, error=[{memoizationStoreResult}]"); } result = new BoolResult(sb.ToString()); } else { result = BoolResult.Success; } StartupCompleted = true; return result; })); }