Esempio n. 1
0
        public void LoadDocuments(
            [Parameter("The source path containing the documents to be loaded")]
            string sourceDir,
            [Parameter("A file name pattern identifying the documents to be loaded; " +
                       "wildcards may be used. Note that the name pattern does not " +
                       "apply to folder names when IncludeSubDirs is true.",
                       DefaultValue = "*")]
            string name,
            [Parameter("The folder in the HFM document repository where the documents should be placed")]
            string targetFolder,
            [Parameter("A flag indicating whether sub-directories below the source directory " +
                       "should also be loaded. If true, sub-folders will be created below the " +
                       "target folder with the same names as the sub-directories.",
                       DefaultValue = false)]
            bool includeSubDirs,
            [Parameter("The document type(s) to upload", DefaultValue = EDocumentType.All)]
            EDocumentType documentType,
            [Parameter("The security class to be assigned to the uploaded documents",
                       DefaultValue = "[Default]")]
            string securityClass,
            [Parameter("If true, the documents are created as private documents; otherwise they are public",
                       DefaultValue = false)]
            bool isPrivate,
            [Parameter("True to overwrite existing documents, false to leave existing documents unchanged",
                       DefaultValue = false)]
            bool overwrite,
            IOutput output)
        {
            var files  = FileUtilities.FindMatchingFiles(sourceDir, name, includeSubDirs);
            var loaded = 0;

            _log.InfoFormat("Loading documents from {0} to {1}", sourceDir, targetFolder);
            output.InitProgress("Loading documents", files.Count);

            foreach (var filePath in files)
            {
                var file      = Path.GetFileName(filePath);
                var tgtFolder = Path.Combine(targetFolder, FileUtilities.PathDifference(sourceDir, filePath));
                CreateFolder(tgtFolder, null, securityClass, isPrivate, EDocumentType.All, false);
                if (overwrite || !DoesDocumentExist(tgtFolder, file, EDocumentType.All))
                {
                    var doc = new DocumentInfo(filePath);
                    if (doc.IsDocumentType(documentType))
                    {
                        _log.FineFormat("Loading {0} to {1}", file, targetFolder);
                        SaveDocument(targetFolder, doc.Name, doc.Description,
                                     doc.DocumentType, doc.DocumentFileType,
                                     doc.Content, securityClass, isPrivate, overwrite);
                        loaded++;
                    }
                }
                if (output.IterationComplete())
                {
                    break;
                }
            }
            output.EndProgress();
            _log.InfoFormat("Successfully loaded {0} documents to {1}", loaded, targetFolder);
        }