/// Determines the document type for Rpt style file protected void ParseXML(string filePath) { using (XmlTextReader xr = new XmlTextReader(filePath)) { xr.WhitespaceHandling = WhitespaceHandling.None; xr.Read(); // Read the XML declaration node, advance to next tag xr.Read(); // Read the root tag switch (xr.Name.ToLower()) { case "linkdoc": DocumentType = EDocumentType.Link; break; case "griddef": DocumentType = EDocumentType.DataGrid; break; case "workspace": DocumentType = EDocumentType.TaskList; break; default: throw new DocumentException("Cannot determine document type for file {0}", filePath); } Name = xr.GetAttribute("doc_name"); Description = xr.GetAttribute("doc_description"); DocumentFileType = EDocumentFileType.XML; // TODO: Fix this... SecurityClass = xr.GetAttribute("doc_secclass"); } }
public void SaveDocument( [Parameter("The path to the folder in which to save the document")] string path, [Parameter("The name to give the document")] string name, [Parameter("The description to give the document")] string desc, [Parameter("The document type to save the document as")] EDocumentType documentType, [Parameter("The document file type to save the document as")] EDocumentFileType documentFileType, [Parameter("The content for the new document")] string content, [Parameter("The security class to assign the document", DefaultValue = "[Default]")] string securityClass, [Parameter("If true, the document is saved as a private document; otherwise, it is public", DefaultValue = false)] bool isPrivate, [Parameter("True to overwrite any existing document with the same name in the folder", DefaultValue = true)] bool overwrite) { HFM.Try("Saving document {0} to {1}", name, path, () => _documents.SaveDocument2(path, name, desc, (int)documentType, (int)documentFileType, securityClass, content, isPrivate, (int)EDocumentType.All, overwrite)); // Update cache LoadCache(path, false); }
/// Determines the document type for Rpt style file protected void ParseRpt(string filePath) { var re = new Regex(@"^(ReportType|ReportLabel|ReportDescription|ReportSecurityClass)=(.*)", RegexOptions.IgnoreCase); using (StreamReader r = new StreamReader(filePath)) { while (r.Peek() >= 0) { var line = r.ReadLine(); var match = re.Match(line); if (match.Success) { switch (match.Groups[1].Value.ToUpper()) { case "REPORTDESCRIPTION": Description = match.Groups[2].Value; break; case "REPORTLABEL": Name = match.Groups[2].Value; break; case "REPORTSECURITYCLASS": // TODO: Fix this... SecurityClass = match.Groups[2].Value; break; case "REPORTTYPE": switch (match.Groups[2].Value.ToUpper()) { case "INTERCOMPANY": DocumentType = EDocumentType.IntercompanyReport; DocumentFileType = EDocumentFileType.ReportDefRPT; break; case "JOURNAL": DocumentType = EDocumentType.JournalReport; DocumentFileType = EDocumentFileType.ReportDefRPT; break; case "WEBFORM": DocumentType = EDocumentType.WebForm; DocumentFileType = EDocumentFileType.WebFormDef; break; case "DATAEXPLORER": DocumentType = EDocumentType.DataExplorerReport; DocumentFileType = EDocumentFileType.XML; break; } break; } } } } if (DocumentType == EDocumentType.Invalid) { DocumentType = EDocumentType.Custom; } _log.TraceFormat("File {0} has document type {1}", filePath, DocumentType); }
public void ExtractDocuments( [Parameter("The source folder from which document extraction is to take place")] string path, [Parameter("A document name pattern identifying the documents to extract", DefaultValue = '*')] string name, [Parameter("The file system path where extracted documents are to be placed")] string targetDir, [Parameter("A flag indicating whether documents in sub-folders should be included", DefaultValue = false)] bool includeSubFolders, [Parameter("The document type(s) to be extracted", DefaultValue = EDocumentType.All)] EDocumentType documentType, [Parameter("The document file type(s) to be extracted", DefaultValue = EDocumentFileType.All)] EDocumentFileType documentFileTypes, [Parameter("The type of documents to extract (public, private, or both)", DefaultValue = EPublicPrivate.Both)] EPublicPrivate visibility, [Parameter("Flag indicating whether existing files should be overwritten", DefaultValue = true)] bool overwrite, IOutput output) { string tgtPath, filePath; int extracted = 0; var docs = EnumDocuments(path, name, includeSubFolders, documentType, visibility, null); if (!Directory.Exists(targetDir)) { Directory.CreateDirectory(targetDir); } output.InitProgress("Extracting documents", docs.Count); foreach (var doc in docs) { tgtPath = Path.Combine(targetDir, FileUtilities.PathDifference(path, doc.Folder)); filePath = Path.Combine(tgtPath, doc.DefaultFileName); if (doc.IsFolder) { if (!Directory.Exists(filePath)) { _log.FineFormat("Creating directory {0}", filePath); Directory.CreateDirectory(filePath); } } else if (overwrite || !File.Exists(filePath)) { _log.FineFormat("Extracting document {0} to {1}", doc.Name, filePath); var content = GetDocument(doc.Folder, doc.Name, doc.DocumentType); using (FileStream fs = File.Open(filePath, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)) { fs.Write(content, 0, content.Length); } // Update last modified time to match document timestamp File.SetLastWriteTime(filePath, doc.Timestamp); extracted++; } if (output.IterationComplete()) { break; } } output.EndProgress(); _log.InfoFormat("Successfully extracted {0} documents to {1}", extracted, targetDir); }