/// <summary> /// Find all subdocuments. /// The Errors array is filled if errors are found /// </summary> /// <param name="tempInputPath">Path to the copy of the word document.</param> /// <param name="originalInputPath">Path to the original word document.</param> /// <returns>Collection of the subdocuments.</returns> public static SubdocumentsList FindSubdocuments(string tempInputPath, string originalInputPath) { PackageRelationship relationship = null; SubdocumentsList result = new SubdocumentsList(); Package packDoc = Package.Open(tempInputPath, FileMode.Open, FileAccess.ReadWrite); foreach (PackageRelationship searchRelation in packDoc.GetRelationshipsByType(WordRelationshipType)) { relationship = searchRelation; break; } Uri partUri = PackUriHelper.ResolvePartUri(relationship.SourceUri, relationship.TargetUri); PackagePart mainPartxml = packDoc.GetPart(partUri); foreach (PackageRelationship searchRelation in mainPartxml.GetRelationships()) { relationship = searchRelation; if (IsExternalSubdocumentRelationship(relationship)) { bool subDocumentFound = IsMsWordSubdocumentRelationship(relationship); result.SubdocumentsCount += subDocumentFound ? 1 : 0; String filePath = GetRealFilePath(relationship.TargetUri.ToString(), originalInputPath); if (!string.IsNullOrEmpty(filePath)) { if (subDocumentFound) { result.Subdocuments.Add(new SubdocumentInfo(filePath, relationship.Id)); } else { result.NotTranslatedSubdocuments.Add(new SubdocumentInfo(filePath, relationship.Id)); } } else { result.Errors.Add( "The subdocument " + originalInputPath + "\\" + relationship.TargetUri.ToString() + " was not found on your system." ); } } } packDoc.Close(); return(result); }
/// <summary> /// Function to translate all Sub documents /// </summary> /// <param name="tempInputFile">Duplicate for the Input File</param> /// <param name="temp_InputFile">Duplicate for the Input File</param> /// <param name="inputFile">Input file to be Translated</param> /// <param name="outputfilepath">Path of the Output file</param> /// <param name="HTable">Document properties</param> public void OoxToDaisyOwn(String tempInputFile, String temp_InputFile, String inputFile, String outputfilepath, Hashtable HTable, string control, Hashtable listMathMl, string output_Pipeline) { try { SubdocumentsList subdocuments = SubdocumentsManager.FindSubdocuments(temp_InputFile, inputFile); ArrayList notTranslatedDoc = subdocuments.GetNotTraslatedSubdocumentsNames(); ArrayList subList = new ArrayList(); subList.Add(tempInputFile + "|Master"); subList.AddRange(subdocuments.GetSubdocumentsNameWithRelationship()); int subCount = subdocuments.SubdocumentsCount + 1; //Checking whether any original or Subdocumets is already Open or not string resultOpenSub = CheckFileOPen(subList); if (resultOpenSub != "notopen") { OnUnknownError(resourceManager.GetString("OpenSubOwn")); return; } //Checking whether Sub documents are Simple documents or a Master document string resultSub = SubdocumentsManager.CheckingSubDocs(subdocuments.GetSubdocumentsNameWithRelationship()); if (resultSub != "simple") { OnUnknownError(resourceManager.GetString("AddSimpleMasterSub")); return; } if (subCount != subList.Count) { OnUnknownError(this.resourceManager.GetString("ProblemMasterSub")); return; } OoxToDaisySub(outputfilepath, subList, HTable, tempInputFile, control, listMathMl, output_Pipeline, notTranslatedDoc); } catch (Exception e) { AddinLogger.Error(e); OnUnknownError(resourceManager.GetString("TranslationFailed") + "\n" + this.resourceManager.GetString("WellDaisyFormat") + "\n" + " \"" + Path.GetFileName(tempInputFile) + "\"\n" + validationErrorMsg + "\n" + "Problem is:" + "\n" + e.Message + "\n"); } }