Exemple #1
0
        // public void ExecuteQueue(object sender, ElapsedEventArgs e)
        public void ExecuteQueue()
        {
            lock (padlock)
            {
                string   docDir     = queueDir + "\\document";
                string   requestDir = queueDir + "\\request";
                string   tempDir    = queueDir + "\\temp";
                string[] files      = Directory.GetFiles(requestDir);

                if (files.Length <= 0)
                {
                    return;
                }
                foreach (string f in files)
                {
                    Console.WriteLine("正在归档:" + f);
                    DocumentBuilder builder   = null;
                    int             tempIndex = f.LastIndexOf("\\") + 1;
                    string          tag       = f.Substring(tempIndex, f.LastIndexOf(".") - tempIndex);
                    try
                    {
                        ZipHelper.UnZip(f, tempDir + "\\" + tag);
                        FileFilter(tempDir + "\\" + tag);
                        string      docPath = docDir + "\\" + tag + ".doc";
                        string      xmlPath = tempDir + "\\" + tag + "\\request.xml";
                        RequestList list    = SerializableHelper.DeserilizeXml(xmlPath);
                        File.Delete(xmlPath);
                        builder = InvokeFrontCover(list, docPath);
                        // builder = new DocumentBuilder(docPath);

                        foreach (RequestData data in list.RequestData)
                        {
                            InvokeMethod(data, builder);
                        }
                        builder.Save();
                        builder.Quit();
                        Directory.Delete(tempDir + "\\" + tag, true);
                        SendConvertLog(tag, true, "");

                        File.Delete(f);

                        Console.WriteLine(f + " 归档成功");
                    }
                    catch (Exception ex)
                    {
                        SendConvertLog(tag, false, ex.Message);
                        File.Delete(f);
                        log.ErrorFormat("执行队列出错,异常信息: {0}", ex.Message);
                        Console.WriteLine(f + " 归档失败");
                        Console.WriteLine("执行队列出错,异常信息: {0}", ex.Message);
                        if (builder != null)
                        {
                            builder.Quit();
                            builder.KillWordProcess();
                        }
                    }
                }
            }
        }