コード例 #1
0
        public async Task <TextFile> AddFile(string text)
        {
            var textFile = new TextServiceRepositories.Text();

            textFile.TextValue = text;

            textFile = await _textRepository.Create(textFile);

            textFile.TextValue = null;

            return(_mapper.Map <TextFile>(textFile));
        }
コード例 #2
0
        public async Task <TextFile> AddFileFromSteam(Stream streamTextFile)
        {
            var    textFile = new TextServiceRepositories.Text();
            string text     = "";

            using (var reader = new StreamReader(streamTextFile))
            {
                text = await reader.ReadToEndAsync();
            }
            textFile.TextValue = text;
            textFile           = await _textRepository.Create(textFile);

            textFile.TextValue = null;
            return(_mapper.Map <TextFile>(textFile));
        }
コード例 #3
0
        public async Task <TextFile> AddFileFromUrl(string textFileUrl)
        {
            var    textFile = new TextServiceRepositories.Text();
            string text;
            var    textFileUri = new Uri(textFileUrl);

            using (var wc = new WebClient())
            {
                text = wc.DownloadString(textFileUri);
            }
            textFile.TextValue = text;
            textFile           = await _textRepository.Create(textFile);

            textFile.TextValue = null;
            return(_mapper.Map <TextFile>(textFile));
        }
コード例 #4
0
        public async Task <TextFile> AddFileFromIFormFile(List <IFormFile> files)
        {
            string text     = "";
            var    textFile = new TextServiceRepositories.Text();

            foreach (var file in files)
            {
                if (file.Length > 0)
                {
                    using (var reader = new StreamReader(file.OpenReadStream()))
                    {
                        text = await reader.ReadToEndAsync();
                    }

                    textFile.TextValue = text;
                    textFile           = await _textRepository.Create(textFile);

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