Beispiel #1
0
        public async Task <TextFile> AddFile(string text)
        {
            var textFile = new Text.Service.Repositories.Text {
                TextValue = text
            };

            textFile = await _textRepository.Create(textFile);

            textFile.TextValue = null;

            return(_mapper.Map <TextFile>(textFile));
        }
Beispiel #2
0
        public async Task <TextFile> AddFileByUrl(string textFileUrl, CancellationToken cancellationToken)
        {
            using var httpClient = new HttpClient();
            var stream = await httpClient.GetStreamAsync(textFileUrl, cancellationToken);

            using var sr = new StreamReader(stream);
            var fileData = sr.ReadToEnd();
            var textFile = new Text.Service.Repositories.Text {
                TextValue = fileData
            };

            textFile = await _textRepository.Create(textFile);

            textFile.TextValue = null;

            return(_mapper.Map <TextFile>(textFile));
        }
Beispiel #3
0
        private async Task <TextFile> AddFileUpload(string fileName)
        {
            byte[] result;
            await using (FileStream sourceStream = File.Open(fileName, FileMode.Open))
            {
                result = new byte[sourceStream.Length];
                await sourceStream.ReadAsync(result, 0, (int)sourceStream.Length);
            }

            var fileData = System.Text.Encoding.UTF8.GetString(result);
            var textFile = new Text.Service.Repositories.Text {
                TextValue = fileData
            };

            textFile = await _textRepository.Create(textFile);

            textFile.TextValue = null;
            return(_mapper.Map <TextFile>(textFile));
        }