Esempio n. 1
0
        public List <DocumentInfo> EnumDocuments(
            [Parameter("The document repository folder that contains the documents to return " +
                       @"(note: the root folder is '\')",
                       DefaultValue = @"\")]
            string path,
            [Parameter("An optional pattern that document names should match; may include wildcards ? and *",
                       DefaultValue = "*")]
            string name,
            [Parameter("If true, recurses into each sub-folder encountered, and returns its content as well",
                       DefaultValue = false)]
            bool includeSubFolders,
            [Parameter("The document type(s) to return",
                       DefaultValue = EDocumentType.All)]
            EDocumentType documentType,
            [Parameter("A visibility setting used to determine whether public, private or both " +
                       "types of documents should be returned",
                       DefaultValue = EPublicPrivate.Public)]
            EPublicPrivate visibility,
            IOutput output)
        {
            var nameRE = FileUtilities.ConvertWildcardPatternToRE(name);
            List <DocumentInfo> docs = new List <DocumentInfo>();

            if (_documentCache.ContainsKey(path))
            {
                _log.TraceFormat("Locating matching documents at {0}", path);
                docs.AddRange(_documentCache[path].Where(doc => nameRE.IsMatch(doc.Name) &&
                                                         doc.IsDocumentType(documentType) && doc.IsVisible(visibility)));

                if (includeSubFolders)
                {
                    // Recurse into sub-directory
                    foreach (var folder in GetFolders(path, visibility))
                    {
                        docs.AddRange(EnumDocuments(AddFolderToPath(path, folder.Name), name,
                                                    includeSubFolders, documentType, visibility, null));
                    }
                }
            }
            else
            {
                _log.WarnFormat("The path '{0}' does not exist", path);
            }

            if (output != null)
            {
                // TODO: Add support for outputting any field of DocumentInfo
                output.SetHeader("Name", 30, "Document Type", "Timestamp", "Description");
                foreach (var doc in docs)
                {
                    output.WriteRecord(doc.Name, doc.DocumentType,
                                       doc.Timestamp, doc.Description);
                }
                output.End();
            }

            return(docs);
        }
Esempio n. 2
0
        /// <summary>
        /// Returns a DocumentInfo object for the requested document if it
        /// exists, or null if the document is not found.
        /// </summary>
        public DocumentInfo FindDocument(string path, string name, EDocumentType docType)
        {
            _log.TraceFormat("Searching for {0} at {1}", name, path);
            DocumentInfo docInfo = null;

            if (_documentCache.ContainsKey(path))
            {
                var nameRE = FileUtilities.ConvertWildcardPatternToRE(name);
                docInfo = _documentCache[path].FirstOrDefault(doc =>
                                                              nameRE.IsMatch(doc.Name) && doc.IsDocumentType(docType));
            }
            return(docInfo);
        }