Ejemplo n.º 1
0
        }//输出
        #endregion

        public void BatchProcess(PrimalArrivalData Pad, string path)
        {
            //判断文件路径是否存在,不存在则创建文件夹
            if (!System.IO.Directory.Exists(path))
            {
                System.IO.Directory.CreateDirectory(path);//不存在就创建目录
            }
            XmlTextWriter writer1 = new XmlTextWriter(path + "SellingRecord.xml", null);
            XmlTextWriter writer2 = new XmlTextWriter(path + "ControlRecord.xml", null);

            //写入根元素
            writer1.WriteStartElement("SellingRecordData");
            writer2.WriteStartElement("ControlRecordData");

            //TODO 限制任务数量
            while (Pad.ReadNextPAL())
            {
                PrimalArrivalList pal = Pad.GetCurPAL();
                Task ta = factory.StartNew(() =>
                {
                    SellingRecordList Srlist;
                    ControlRecordList Crlist;
                    Process(pal, out Srlist, out Crlist);
                    lock (writer1)
                    {
                        Srlist.WritetoXml(writer1);
                    }
                    lock (writer2)
                    {
                        Crlist.WritetoXml(writer2);
                    }
                    //SimData.CRD.Add(Crlist);
                    //SimData.SRD.Add(Srlist);
                }, cts.Token);
                tasks.Add(ta);
                if (tasks.Count >= 128)
                {
                    Task.WaitAll(tasks.ToArray());
                    tasks.Clear();
                }
            }
            Task.WaitAll(tasks.ToArray());
            tasks.Clear();

            writer1.WriteEndElement();
            writer2.WriteEndElement();
            //将XML写入文件并且关闭XmlTextWriter
            writer1.Close();
            writer2.Close();
        }
Ejemplo n.º 2
0
        public void BatchProcess(string inputDir, string outputDir)
        {
            DirectoryInfo folder = new DirectoryInfo(inputDir);

            int n     = 0;
            int total = folder.GetFiles("*.arr").Length;
            int step  = (int)Math.Ceiling((double)folder.GetFiles("*.arr").Length / 10000);

            Console.Write("进度 000.00%");
            foreach (FileInfo f in folder.GetFiles("*.arr"))
            {
                FileInfo          file = f;//防止在VS2010下报错
                PrimalArrivalList pal  = new PrimalArrivalList();
                pal.ReadFromArrFile(file.FullName);
                Task ta = factory.StartNew(() =>
                {
                    SellingRecordList Srlist;
                    ControlRecordList Crlist;
                    Process(pal, out Srlist, out Crlist);
                    //判断文件路径是否存在,不存在则创建文件夹
                    if (!System.IO.Directory.Exists(outputDir + @"\Sell"))
                    {
                        System.IO.Directory.CreateDirectory(outputDir + @"\Sell");//不存在就创建目录
                    }
                    Srlist.WriteToFile(outputDir + @"\Sell\" + pal.PAListID + ".sr");
                    if (!System.IO.Directory.Exists(outputDir + @"\Control"))
                    {
                        System.IO.Directory.CreateDirectory(outputDir + @"\Control");//不存在就创建目录
                    }
                    Crlist.WriteToFile(outputDir + @"\Control\" + pal.PAListID + ".cr");
                    if (n++ % step == 0)
                    {
                        lock (folder)
                        {
                            Console.SetCursorPosition(Console.CursorLeft - 7, Console.CursorTop);
                            Console.Write("{0}%", String.Format("{0:000.00}", Math.Round(((double)n / (double)total), 4) * 100));
                        }
                    }
                }, cts.Token);
                tasks.Add(ta);
            }
            Task.WaitAll(tasks.ToArray());
            tasks.Clear();
            Console.SetCursorPosition(Console.CursorLeft - 7, Console.CursorTop);
            Console.WriteLine("100.00 %  完成!");
        }