Esempio n. 1
0
        public FormToPDFTask GetTask(string Id = "")
        {
            var sql = "";

            if (string.IsNullOrWhiteSpace(Id))
            {
                sql = @"select top 1 * from S_D_FormToPDFTask Where State = 'New'";
            }
            else
            {
                sql = string.Format("select * from S_D_FormToPDFTask where ID = '{0}'", Id);
            }

            FormToPDFTask task   = null;
            var           db     = SqlHelper.Create("Base");
            var           reader = db.ExecuteReader(sql);

            if (reader.Read())
            {
                task                    = new FormToPDFTask();
                task.ID                 = reader.Get("ID", "");
                task.TempCode           = reader.Get("TempCode", "");
                task.FormID             = reader.Get("FormID", "");
                task.PDFFileID          = reader.Get("PDFFileID", "");
                task.FormLastModifyDate = reader.Get <DateTime>("FormLastModifyDate");
                task.BeginTime          = reader.Get <DateTime>("BeginTime");
                task.EndTime            = reader.Get <DateTime>("EndTime");
                task.DoneLog            = reader.Get("DoneLog", "");
                task.State              = reader.Get("State", "");
            }
            reader.Close();
            return(task);
        }
Esempio n. 2
0
        public void Execute(IJobExecutionContext context)
        {
            FormToPDFTaskRepository repo = new FormToPDFTaskRepository();

            repo.AddTask();

            var taskId        = "";
            var jobDataTaskId = context.Trigger.JobDataMap["taskId"];

            if (jobDataTaskId != null)
            {
                taskId = jobDataTaskId.ToString();
            }

            FormToPDFTask task = repo.GetTask(taskId);

            try
            {
                while (task != null)
                {
                    repo.BeginTask(task.ID);
                    var    uri        = FormToWordApiUrl + string.Format("FormToWordAPI/{0}?TmplCode={1}", task.FormID, task.TempCode);
                    byte[] wordBuffer = WebApiClientHelper.DoFileRequest(uri);
                    byte[] pdfBuffer  = FileConverter.Word2JPG(wordBuffer);
                    var    length     = "0KB";
                    if (pdfBuffer.Length < 1000)
                    {
                        length = pdfBuffer.Length + "B";
                    }
                    else if (pdfBuffer.Length >= 1000 && pdfBuffer.Length < 1000000)
                    {
                        length = pdfBuffer.Length / 1000 + "KB";
                    }
                    else
                    {
                        length = pdfBuffer.Length / 1000000 + "M";
                    }

                    string pdfFileID = FileStoreHelper.SaveFile(pdfBuffer, task.FormID + ".jpg");
                    repo.EndTask(task.ID, pdfFileID + "_" + length);

                    task = repo.GetTask();
                }
            }
            catch (Exception ex)
            {
                repo.Log(task.ID, ex.Message);
            }
        }
Esempio n. 3
0
        public void Execute(IJobExecutionContext context)
        {
            try
            {
                FormToPDFTaskRepository repo = new FormToPDFTaskRepository();
                repo.AddTask();

                var taskId        = "";
                var jobDataTaskId = context.Trigger.JobDataMap["taskId"];
                if (jobDataTaskId != null)
                {
                    taskId = jobDataTaskId.ToString();
                }

                FormToPDFTask task = repo.GetTask(taskId);

                while (task != null)
                {
                    try
                    {
                        repo.BeginTask(task.ID);
                        var    uri        = FormToWordApiUrl + string.Format("FormToWordAPI/{0}?TmplCode={1}", task.FormID, task.TempCode);
                        byte[] wordBuffer = WebApiClientHelper.DoFileRequest(uri);

                        StringBuilder fileNames = new StringBuilder();

                        //1. 转pdf
                        byte[] pdfFile = FileConverter.Word2PDF(wordBuffer);
                        int    j       = 0;
                        var    length  = "0KB";
                        if (pdfFile.Length < 1000)
                        {
                            length = pdfFile.Length + "B";
                        }
                        else if (pdfFile.Length >= 1000 && pdfFile.Length < 1000000)
                        {
                            length = pdfFile.Length / 1000 + "KB";
                        }
                        else
                        {
                            length = pdfFile.Length / 1000000 + "M";
                        }

                        var src = string.IsNullOrEmpty(ConfigurationManager.AppSettings["Src"]) ? "" : ConfigurationManager.AppSettings["Src"];

                        string pdfFileID = FileStoreHelper.SaveFile(pdfFile, task.FormID + ".pdf", src, true);

                        //2.转jpg
                        List <byte[]> results = FileConverter.Word2JPG(wordBuffer);
                        foreach (var item in results)
                        {
                            int p = 0;
                            length = "0KB";
                            if (item.Length < 1000)
                            {
                                length = item.Length + "B";
                            }
                            else if (item.Length >= 1000 && item.Length < 1000000)
                            {
                                length = item.Length / 1000 + "KB";
                            }
                            else
                            {
                                length = item.Length / 1000000 + "M";
                            }

                            string fileID = FileStoreHelper.SaveFile(item, task.FormID + "_" + (p++).ToString() + ".jpg", src, true);

                            fileNames.Append(fileID);
                            fileNames.Append("_");
                            fileNames.Append(length);
                            fileNames.Append(",");
                        }
                        repo.EndTask(task.ID, pdfFileID, fileNames.ToString().TrimEnd(','));

                        task = repo.GetTask();
                    }
                    catch (Exception ex)
                    {
                        repo.Log(task.ID, ex.Message);
                        LogWriter.Error("[出错记录]:" + task.ID + " [错误信息]:" + ex.Message);
                        continue;
                    }
                }
            }
            catch (Exception e)
            {
                LogWriter.Error(e.Message);
            }
            finally
            {
                //防止和浏览转图程序关闭进程冲突,不能在转图浏览服务器上同时部署
                CloseExit();
                System.Environment.Exit(0);
            }
        }