Exemplo n.º 1
0
        public static List <string> OutputCsvByXml(List <Cabinet> list, string orderNo = null)
        {
            List <string> files = ConvertCore.Output(list, orderNo);

            GZip(files);
            return(files);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 合并订单行解析xml,不打压缩包
        /// </summary>
        /// <param name="xmlString"></param>
        /// <param name="orderNo"></param>
        /// <returns></returns>
        public static List <string> OutputCsvByXml1(string xmlString, string orderNo = null)
        {
            List <Cabinet> list     = T3VProduct.LoadFromXML(xmlString);
            List <string>  files    = ConvertCore.Output(list, orderNo);
            var            newFiles = files.Where(p => !p.Contains(".jpg")).ToList();

            return(files);
        }
Exemplo n.º 3
0
        /*
         * 将文件转换为文本
         */
        private void FileConvert(object thread_payload)
        {
            //获取参数
            string[]      param        = (string[])thread_payload;
            int           taskNo       = int.Parse(param[0].ToString());
            DirectoryInfo sourceFolder = new DirectoryInfo(param[1]);
            DirectoryInfo textFolder   = new DirectoryInfo(param[2]);

            //判断源文件夹和目标文件夹是否存在
            if (!sourceFolder.Exists || !textFolder.Exists)
            {
                runningEnv.UIContext.BeginInvoke(new Action(() =>
                {
                    MessageBox.Show(runningEnv.UIContext, "数据损坏,任务失败!", "错误");
                }));
                return;
            }

            //获取源文件夹中的待转换文件
            FileInfo[] fileInfo = sourceFolder.GetFiles();

            //按本线程所分配的任务进行转换
            int addNumo = int.Parse(runningEnv.SettingData.ConvertThreadCnt.ToString());

            for (int FileInfoNo = taskNo; FileInfoNo < fileInfo.Length; FileInfoNo += addNumo)
            {
                FileInfo NextFile = fileInfo[FileInfoNo];

                string path      = sourceFolder.FullName + "\\" + NextFile.Name;
                string dist_path = textFolder.FullName + "\\" + NextFile.Name + ".txt";

                //文件已经被转换则忽略该文件
                if (File.Exists(dist_path))
                {
                    continue;
                }

                ConverterFactory converterFactory = new ConverterFactory();

                try
                {
                    //获取文件后缀
                    string file_type = path.ToLower().Split('.')[Math.Max(path.ToLower().Split('.').Length - 1, 0)];
                    //获取转换器
                    ConvertCore file_converter = converterFactory.GetConverter(file_type, runningEnv);
                    string      text           = "";
                    if (file_converter != null)//如果可以获得到转换器
                    {
                        //获取文本
                        text = file_converter.ConvertToString(path);
                        if (text.Length > RunningEnv.ProgramParam.MaxWords)
                        {
                            //舍弃过长的部分
                            text = text.Substring(0, RunningEnv.ProgramParam.MaxWords);
                        }
                        //写入目标路径
                        File.WriteAllText(dist_path, text, Encoding.GetEncoding("GBK"));
                    }
                    else
                    {
                        //没有获取到转换器则忽略
                        continue;
                    }

                    //如果转换后的文件不符合所设阈值则删除
                    if (new FileInfo(dist_path).Length <= runningEnv.CheckData.MinBytes || text.Length <= runningEnv.CheckData.MinWords)
                    {
                        if (File.Exists(dist_path))
                        {
                            File.Delete(dist_path);
                        }
                        throw new Exception();//并爆出一个异常
                    }
                }
                catch (Exception e)
                {
                    runningEnv.CheckingData.ErrorPaperList.AddLast(NextFile.Name);
                }
            }
        }
Exemplo n.º 4
0
        /*
         * 将文件转换为文本
         */
        private void FileConvert(object thread_payload)
        {
            //获取参数
            string[]      param        = (string[])thread_payload;
            int           taskNo       = int.Parse(param[0].ToString());
            DirectoryInfo sourceFolder = new DirectoryInfo(param[1]);
            DirectoryInfo textFolder   = new DirectoryInfo(param[2]);

            //判断源文件夹和目标文件夹是否存在
            if (!sourceFolder.Exists || !textFolder.Exists)
            {
                runningEnv.UIContext.BeginInvoke(new Action(() =>
                {
                    MessageBox.Show(runningEnv.UIContext, "数据损坏,任务失败!", "错误");
                }));
                return;
            }

            //获取源文件夹中的待转换文件
            FileInfo[] fileInfo = Utils.GetFileInfoRecursion(sourceFolder).ToArray();

            //按本线程所分配的任务进行转换
            int addNumo = int.Parse(runningEnv.SettingData.ConvertThreadCnt.ToString());

            for (int FileInfoNo = taskNo; FileInfoNo < fileInfo.Length; FileInfoNo += addNumo)
            {
                FileInfo NextFile = fileInfo[FileInfoNo];

                string path = NextFile.FullName;
                string real_dis_file_name = Regex.Replace(NextFile.Name, @"[^\u4e00-\u9fa5\u0022\《\》\(\)\—\;\,\。\“\”\!\#\\_\-\.\,\:\(\)\'\[\]\【\】\+\·\:\<\>\w]", string.Empty);
                foreach (char rInvalidChar in Path.GetInvalidFileNameChars())
                {
                    real_dis_file_name = real_dis_file_name.Replace(rInvalidChar.ToString(), string.Empty);
                }
                string dist_path = textFolder.FullName + Path.DirectorySeparatorChar + real_dis_file_name + ".txt";

                //文件已经被转换则忽略该文件
                if (File.Exists(dist_path))
                {
                    continue;
                }

                ConverterFactory converterFactory = new ConverterFactory();

                try
                {
                    //获取文件后缀
                    string file_type = path.ToLower().Split('.')[Math.Max(path.ToLower().Split('.').Length - 1, 0)];
                    //获取转换器
                    ConvertCore file_converter = converterFactory.GetConverter(file_type, runningEnv);
                    string      text           = "";
                    if (file_converter != null)//如果可以获得到转换器
                    {
                        //获取文本
                        text = file_converter.ConvertToString(path, runningEnv.CheckData.Blocklist);
                        if (text != null && text.Length > 0)
                        {
                            if (text.Length > RunningEnv.ProgramParam.MaxWords)
                            {
                                //舍弃过长的部分
                                text = text.Substring(0, RunningEnv.ProgramParam.MaxWords);
                            }
                            //写入目标路径
                            File.WriteAllText(dist_path, text, Encoding.GetEncoding("GBK"));
                        }
                    }
                    else
                    {
                        //没有获取到转换器则忽略
                        continue;
                    }

                    //如果转换后的文件不符合所设阈值则删除
                    if (new FileInfo(dist_path).Length <= runningEnv.CheckData.MinBytes || text.Length <= runningEnv.CheckData.MinWords)
                    {
                        if (File.Exists(dist_path))
                        {
                            File.Delete(dist_path);
                        }
                        //并抛出一个异常
                        throw new Exception();
                    }
                }
                catch (Exception e)
                {
                    runningEnv.CheckingData.ErrorPaperList.AddLast(NextFile.Name);
                }
            }
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Need the input file.");
                Console.Read();
                return;
            }

            var inFile   = args[0];
            var outFile  = inFile + ".json";
            var outFile2 = inFile + ".txt";

            if (!File.Exists(inFile))
            {
                Console.WriteLine("File not found.");
                Console.Read();
                return;
            }

            var isDone = false;

            try
            {
                // OBS:
                // It's better to convert using same class model
                // as the one used in AikaEmu.GameServer.

                var fileName = Path.GetFileNameWithoutExtension(inFile);
                if (fileName == null)
                {
                    return;
                }

                BaseConvert convert = null;
                switch (fileName)
                {
                case "ItemList":
                    convert = new ItemList();
                    break;

                case "npcpos":
                    convert = new NpcPos();
                    break;

                case "MobPos":
                    convert = new MobPos();
                    break;

                case "ExpList":
                    convert = new ExpList();
                    break;

                case "PranExpList":
                    convert = new PranExpList();
                    break;

                case "MN":
                    convert = new Mn();
                    break;

                case "GearCore":
                    convert = new GearCore();
                    break;

                case "ConvertCore":
                    convert = new ConvertCore();
                    break;

                case "Title":
                    convert = new Title();
                    break;

                case "Recipe":
                    convert = new Recipe();
                    break;

                case "RecipeRate":
                    convert = new RecipeRate();
                    break;

                case "ItemEffect":
                    convert = new ItemEffect();
                    break;

                case "ReinforceA":
                case "ReinforceW":
                    convert = new ReinforceA();
                    ((ReinforceA)convert).IsReinforceW = fileName == "ReinforceW";
                    break;

                case "Reinforce2":
                case "Reinforce3":
                    convert = new Reinforce2();
                    break;

                case "MakeItems":
                    convert = new MakeItems();
                    break;

                case "SetItem":
                    convert = new SetItem();
                    break;

                case "SkillData":
                    convert = new SkillData();
                    break;

                case "Quest":
                    convert = new Quest();
                    break;

                case "Map":
                    convert = new Map();
                    break;

                case "ObjPos":
                    convert = new ObjPos();
                    break;

                case "SPosition":
                    convert = new SPosition();
                    break;

                case "Dialog":
                    convert = new Dialog();
                    break;

                case "StatusPoint":
                    convert = new StatusPoint();
                    break;
                }

                if (convert != null)
                {
                    convert.SetupFile(inFile, outFile, outFile2);
                    convert.Convert();
                    convert.Save();
                    isDone = true;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.Read();
                throw;
            }
            finally
            {
                if (isDone)
                {
                    Console.WriteLine("Input: " + Path.GetFileName(inFile));
                    Console.WriteLine("Output: " + Path.GetFileName(outFile));
                    Console.WriteLine("OutputSql: " + Path.GetFileName(outFile2));
                    Console.WriteLine("Converted with success.");
                }
                else
                {
                    Console.WriteLine("Error in conversion.");
                }
            }

            Console.Read();
        }