static int Main(string[] args) { if (args.Count() < 1) { Console.WriteLine("USAGE: WordToPDF <source> [destination]"); return(-1); } try { string inputFile = (args.Count() > 0) ? args[0] : "c:/users/mterry/git/wordtopdf/src/hello.docx"; string outputFile = (args.Count() > 1) ? args[1] : null; ConvertService convertService = new ConvertService(); convertService.Initialize(); convertService.Convert(inputFile, ref outputFile); return(0); } catch (Exception e) { Console.WriteLine($"Failed to generate PDF - {e.Message}"); return(-1); } }
public void ProcessDocuments() { ConvertService convertService = null; if (_processLock) { Log.Debug("Re-entry into service process, still busy."); return; } _processLock = true; if (!String.IsNullOrEmpty(_heartbeatEndpoint)) { // synchronous use of async. reading repsonse string as async synchronizes the call using (var client = new HttpClient()) { var response = client.GetAsync(_heartbeatEndpoint).Result; if (response.IsSuccessStatusCode) { var responseContent = response.Content; responseContent.ReadAsStringAsync(); Log.Debug("UptimeRobot heartbeat link touched"); } } } try { Log.Debug("Processing pending documents."); foreach (IDocumentQueue documentQueue in _documentQueues) { while (documentQueue.Count() > 0) { if (convertService == null) { convertService = new ConvertService(); convertService.Initialize(); } DocumentTarget documentTarget = documentQueue.NextDocument(); Log.Information($"Generating PDF for {documentQueue.SourceName()}: {documentTarget.Id}: {documentTarget.InputFile}"); try { string outFile = documentTarget.OutputFile; documentTarget.ResultCode = convertService.Convert(documentTarget.InputFile, ref outFile); documentTarget.OutputFile = outFile; } catch (Exception e) { Log.Warning("Conversion exception {0}", e.Message); documentTarget.ResultCode = (int)ExitCode.InternalError; } Log.Information($"Generated PDF for {documentTarget.Id} as {documentTarget.OutputFile} with Result {documentTarget.ResultCode}"); documentQueue.CompleteDocument(documentTarget); } } } catch (Exception e) { Log.Error("Unhandled exception in ProcessDocuments {0}", e); } _processLock = false; }