Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            System.Console.Write("Please enter the input file name: ");
            string inputFile = System.Console.ReadLine();

            //string inputFile = "aa1.txt";

            System.Console.Write("Please enter the output file name: ");
            string outputFile = System.Console.ReadLine();
            //string outputFile = "out.txt";

            FileStream inputStream = new FileStream(
                inputFile, FileMode.Open);  //non-writable

            FileStream      outputStream = new FileStream(outputFile, FileMode.Create);
            ConvertDocument convert      = new ConvertDocument();
            string          error        = convert.DoConvertDocument(inputStream, outputStream);

            if (error == "")  //success
            {
                System.Console.WriteLine("Conversion successful.");
            }
            else
            {
                System.Console.WriteLine(error);
            }
        }
Ejemplo n.º 2
0
        public ActionResult read(string id)
        {
            DocumentEntity       doc           = _repository.Single <DocumentEntity>(id);
            var                  fields        = typeof(ConvertComponentType).GetFields(BindingFlags.Static | BindingFlags.Public);
            var                  componentName = ConfigurationManager.AppSettings["Component"];
            ConvertComponentType selectenum    = (ConvertComponentType)Enum.Parse(typeof(ConvertComponentType), componentName, false);
            ConvertDocument      convertdoc    = new ConvertDocument(doc, selectenum);
            ///未考虑到的情况: 如果文档已经解析完毕,是否需要重新解析
            ///留下与后续数据存放的逻辑一同实现
            ///update 2014-12-11已完成 逻辑在ProcessDocument中实现
            JsonDocEntity parseEntity = convertdoc.ProcessDocument();

            //若解析文档不成功,则直接返回
            if (parseEntity != null)
            {
                //若文档已经存储过,则跳过存储逻辑
                if (!convertdoc._docEntity.isStore)
                {
                    convertdoc._docEntity.isStore = true;
                    _repository.Update <DocumentEntity>(convertdoc._docEntity);
                }
                return(Json(parseEntity, JsonRequestBehavior.AllowGet));
            }
            return(null);
        }
        //returns the contents of the document or error
        public string Convert(string content)
        {
            //assuming it comes in UTF8
            MemoryStream inputStream = new MemoryStream(
                Encoding.UTF8.GetBytes(content), false);    //non-writable

            bool b = inputStream.CanSeek;

            MemoryStream    outputStream = new MemoryStream();
            ConvertDocument convert      = new ConvertDocument();
            string          error        = convert.DoConvertDocument(inputStream, outputStream);

            if (error == "")  //success
            {
                return(Encoding.UTF8.GetString(outputStream.ToArray()));
            }
            return(error);
        }