예제 #1
0
        public Json2Docx(string fullJsonTestFilePath,
                         string fullDocxTestFilePath,
                         IDocxFileService docxFileService,
                         IDocxJsonService jsonService,
                         IMergeService mergeService)
        {
            JsonConversionData jsonFileData = jsonService.BuildJsonConversionData(fullJsonTestFilePath);

            //Handle Errors
            if (jsonFileData.Messages[0] != "Success")
            {
                Response = jsonFileData.Messages[0];
                return;
            }

            DocxConversionData docxFileData = docxFileService.CreateCleanedCopy(fullDocxTestFilePath, false);

            //Handle Errors
            if (docxFileData.Messages[0] != "Success")
            {
                Response = docxFileData.Messages[0];
                return;
            }

            Response = mergeService.MergeJson2Docx(jsonFileData, docxFileData);

            if (Response == "Success")
            {
                //rename DocxFile
                string docxConversionDataFullPath = docxFileData.FullPath;
                string mergedFileName             = docxFileData.GetTranslatedFullPath(DateTime.Now);

                try
                {
                    File.Move(docxConversionDataFullPath, mergedFileName);

                    if (File.Exists(mergedFileName))
                    {
                        FilePath = mergedFileName;
                    }
                    else
                    {
                        Response = "Error saving merged Docx file: " + mergedFileName;
                    }
                }
                catch (Exception e)
                {
                    Response = e.Message;
                }
            }
        }
예제 #2
0
 public Docx2Json(IJsonIoService jsonIoService, IDocxJsonService docxJsonService, IDocxFileService docxFileService)
 {
     this.jsonIoService   = jsonIoService ?? throw new ArgumentNullException("The Json IO service cannot be null.");
     this.docxJSonService = docxJsonService ?? throw new ArgumentNullException("The docx json service cannot be null.");
     this.docxFileService = docxFileService ?? throw new ArgumentNullException("The docx file service cannot be null.");
 }