示例#1
0
        public ManualResetEvent Run(string type, string sourceDoc, string outDir, DocResponseHandler callback)
        {
            Preconditions.CheckArgument(type);
            Preconditions.CheckArgument(sourceDoc);
            Preconditions.CheckArgument(outDir);
            Preconditions.CheckArgument(callback);

            if (handlers.ContainsKey(type))
            {
                ProcessRequest request = new ProcessRequest();
                request.Handler   = handlers[type];
                request.SourceDoc = sourceDoc;
                request.OutDir    = outDir;
                request.Callback  = callback;
                request.Event     = new ManualResetEvent(false);

                ThreadPool.QueueUserWorkItem(new WaitCallback(Process), request);

                return(request.Event);
            }
            else
            {
                throw new Exception(String.Format("Document handler not found. [type={0}]", type));
            }
        }
示例#2
0
        private void Process(object request)
        {
            ProcessRequest pr = request as ProcessRequest;

            ProcessResponse response = new ProcessResponse();

            response.SourceDoc = pr.SourceDoc;

            try
            {
                string outfile = pr.Handler.ConvertToPDF(pr.SourceDoc, pr.OutDir, true);
                LogUtils.Debug(String.Format("Generate output file. [source={0}][filename={1}]", pr.SourceDoc, outfile));
                response.OutputFile = outfile;
            }
            catch (Exception ex)
            {
                LogUtils.Error(ex);
                response.Error = ex;
            }
            finally
            {
                pr.Callback(response);
                pr.Event.Set();
            }
        }