Пример #1
0
 public string Read(Stream inputStream)
 {
     try
     {
         var encoding = EncodingUtils.GetFileEncode(inputStream);
         inputStream.Position = 0;
         StreamReader reader = new StreamReader(inputStream, encoding, true);
         return(reader.ReadToEnd());
     }
     catch (Exception ex)
     {
         throw new ReadException(ErrorMessages.ReadTextFailed, ex);
     }
 }
Пример #2
0
        public string Read(string filePath)
        {
            _logger.Debug("读取文本格式的文件:" + filePath);

            try
            {
                var encoding = EncodingUtils.GetFileEncode(filePath);
                return(File.ReadAllText(filePath, encoding));
            }
            catch (Exception ex)
            {
                throw new ReadException(ErrorMessages.ReadTextFailed, ex);
            }
        }
Пример #3
0
        public int Convert(string from, string to)
        {
            _logger.DebugFormat("Text转换为HTML, {0},到:{1}", from, to);

            try
            {
                var    encoding = EncodingUtils.GetFileEncode(from);
                string result   = File.ReadAllText(from, encoding);
                File.WriteAllText(to, result, Encoding.UTF8);
                return(ErrorMessages.Success);
            }
            catch (Exception ex)
            {
                throw new ConverterException(ErrorMessages.TextToHtmlFailed, ex);
            }
        }