コード例 #1
0
        public override async Task <T> GetData <T>(string dataId = "")
        {
            T data = default;

            string url = SharedSettings.GetDataPath <T>(dataId, true);

            try
            {
                using (var httpResponse = await Client.GetAsync(url, HttpCompletionOption.ResponseHeadersRead))
                {
                    if (httpResponse.IsSuccessStatusCode)
                    {
                        var contentHeaders = httpResponse.Content.Headers;

                        using (var responseStream = await httpResponse.Content.ReadAsStreamAsync())
                        {
                            data = Deserialize <T>(responseStream);
                        }
                    }
                }
            }
            catch (HttpRequestException e)
            {
                Console.WriteLine(e);
            }

            return(data);
        }
コード例 #2
0
        public override async Task SaveData <T>(T data)
        {
            await StreamSemaphore.WaitAsync();

            var dataPath = ToZipPath(Archive, SharedSettings.GetDataPath <T>(data.DatabaseIndex));
            var zipEntry = Archive.GetEntry(dataPath) ?? Archive.CreateEntry(dataPath);

            using (var entryStream = zipEntry.Open())
                using (var writer = new StreamWriter(entryStream))
                {
                    Serialize(data, writer);
                    entryStream.SetLength(entryStream.Position);
                }

            zipEntry.LastWriteTime = DateTime.Now;
            StreamSemaphore.Release();
        }
コード例 #3
0
        public override async Task <T> GetData <T>(string dataId = "")
        {
            await Task.CompletedTask;

            string path = SharedSettings.GetDataPath <T>(dataId);

            T data = default;

            if (File.Exists(path))
            {
                using (var stream = File.Open(path, FileMode.Open))
                {
                    data = Deserialize <T>(stream);
                }
            }

            return(data);
        }
コード例 #4
0
        public override async Task <T> GetData <T>(string dataId = "")
        {
            await StreamSemaphore.WaitAsync();

            T   data     = default;
            var dataPath = ToZipPath(Archive, SharedSettings.GetDataPath <T>(dataId));

            var zipEntry = Archive.GetEntry(dataPath);

            if (zipEntry != null)
            {
                using var stream = zipEntry.Open();
                data             = Deserialize <T>(stream);
            }

            StreamSemaphore.Release();

            return(data);
        }
コード例 #5
0
        public override async Task SaveData <T>(T data)
        {
            await Task.CompletedTask;

            try
            {
                Directory.CreateDirectory(SharedSettings.GetPath <T>(data.DatabaseIndex));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            string path = SharedSettings.GetDataPath <T>(data.DatabaseIndex);

            using (var stream = File.CreateText(path))
            {
                Serialize(data, stream);
            }
        }