예제 #1
0
        public async Task SaveAsync(DataFeed dataFeed)
        {
            var    text        = mapper.Map(dataFeed);
            string fileName    = $"{FilePrefix}{dataFeed.GetDataFeedDateTime():yyyyMMddHHmmss}";
            var    tmpFilePath = Path.Combine(configuration.StorageFolderPath, $"{fileName}{TempFileExtension}");

            if (!Directory.Exists(configuration.StorageFolderPath))
            {
                Directory.CreateDirectory(configuration.StorageFolderPath);
            }

            var filePath = Path.Combine(configuration.StorageFolderPath, $"{fileName}{FileExtension}");

            if (File.Exists(filePath))
            {
                return;
            }

            using (var writer = new StreamWriter(tmpFilePath))
            {
                await writer.WriteAsync(text);
            }

            File.Move(tmpFilePath, filePath);
        }