public PathMapping(PathMapping parentMapping, ITaskItem model) { if (parentMapping != null) { if (parentMapping.DocumentType != Document.DocumentType.Folder) { throw new ArgumentException("Path should have 'Folder' Document Type", "folderPath"); } ParentMapping = parentMapping; } ResourceType = GetResourceType(model.RequireResourceId()); Title = model.RequireTitle(); switch (ResourceType) { case ResourceType.file: MappedFilename = SanitizeTitle(Path.GetFileNameWithoutExtension(Title)); MappedExtension = String.Concat(".", ResourceType.ToString(), "_", SanitizeTitle(Path.GetExtension(Title).TrimStart('.'))); break; case ResourceType.folder: MappedFilename = SanitizeTitle(Title); MappedExtension = null; break; default: MappedFilename = SanitizeTitle(Title); MappedExtension = string.Concat(".", ResourceType.ToString()); break; } }
public PathMapping(PathMapping parentMapping, ITaskItem model) { if (parentMapping != null) { if (parentMapping.DocumentType != Document.DocumentType.Folder) { throw new ArgumentException("Path should have 'Folder' Document Type", "folderPath"); } ParentMapping = parentMapping; } ResourceType = GetResourceType(model.RequireResourceId()); Title = model.RequireTitle(); switch (ResourceType) { case ResourceType.file: MappedFilename = SanitizeTitle(Path.GetFileNameWithoutExtension(Title)); MappedExtension = String.Concat(".", ResourceType.ToString(), "_", SanitizeTitle(Path.GetExtension(Title).TrimStart('.'))); break; case ResourceType.folder: MappedFilename = SanitizeTitle(Title); MappedExtension = null; break; default: MappedFilename = SanitizeTitle(Title); MappedExtension = string.Concat(".",ResourceType.ToString()); break; } }
private void DoDownload(Request documentsRequest, ITaskItem document, ITaskItem download) { string sourceFile = document.ItemSpec; string targetFile = download.ItemSpec; string targetDirectory = Path.GetDirectoryName(targetFile); Log.LogMessage(MessageImportance.High, "Downloading \"{0}\"", document.RequireTitle()); Log.LogMessage(MessageImportance.Normal, "To \"{0}\"", targetDirectory); download.RequireParentDirectory(Log); if (!File.Exists(sourceFile)) { throw new FileNotFoundException("Cannot find", sourceFile); } ResourceType resourceType = document.RequireResourceType(); switch (resourceType) { case ResourceType.file: DoFileDownload(documentsRequest, document, targetFile); break; case ResourceType.document: DoDocumentDownload(documentsRequest, document, targetFile); break; default: throw new NotImplementedException(string.Format("Resource Type '{0}' is unsupported", resourceType)); } DateTime updated = document.GetTimestamp(); File.SetLastWriteTime(download.ItemSpec, updated); document.CopyMetadataTo(download); }
private void DoDownload(Request documentsRequest, ITaskItem document, ITaskItem download) { string sourceFile = document.ItemSpec; string targetFile = download.ItemSpec; string targetDirectory = Path.GetDirectoryName(targetFile); Log.LogMessage(MessageImportance.High,"Downloading \"{0}\"", document.RequireTitle()); Log.LogMessage(MessageImportance.Normal, "To \"{0}\"", targetDirectory); download.RequireParentDirectory(Log); if (!File.Exists(sourceFile)) { throw new FileNotFoundException("Cannot find", sourceFile); } ResourceType resourceType = document.RequireResourceType(); switch (resourceType) { case ResourceType.file: DoFileDownload(documentsRequest, document, targetFile); break; case ResourceType.document: DoDocumentDownload(documentsRequest, document, targetFile); break; default: throw new NotImplementedException(string.Format("Resource Type '{0}' is unsupported", resourceType)); } DateTime updated = document.GetTimestamp(); File.SetLastWriteTime(download.ItemSpec, updated); document.CopyMetadataTo(download); }