Example #1
0
        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);
        }
Example #2
0
        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);
        }