/// <inheritdoc /> public async Task <Possible <string, Failure> > ShutdownAsync() { Contract.Requires(!IsShutdown); m_isShutdown = true; try { try { GetStatsResult stats = await m_cache.GetStatsAsync(new Context(m_logger)); if (stats.Succeeded) { using (Stream fileStream = m_fileSystem.Open(m_statsFile, FileAccess.ReadWrite, FileMode.CreateNew, FileShare.None)) { using (StreamWriter sw = new StreamWriter(fileStream)) { foreach (KeyValuePair <string, long> stat in stats.CounterSet.ToDictionaryIntegral()) { await sw.WriteLineAsync($"{stat.Key}={stat.Value}"); } } } } else { m_logger.Debug($"Stats call failed {stats.ErrorMessage}"); } } #pragma warning disable ERP022 // Unobserved exception in generic exception handler catch { } #pragma warning restore ERP022 // Unobserved exception in generic exception handler BoolResult shutdownResult = await m_cache.ShutdownAsync(new Context(m_logger)); if (shutdownResult.Succeeded) { return(CacheId.ToString()); } return(new CacheFailure(shutdownResult.ErrorMessage)); } finally { Dispose(); } }
static string IdToString(CacheId id) => id.IsCategory ? id.ToString() : $"{id}.dat";