Created
April 21, 2011 18:04
-
-
Save jsmale/935122 to your computer and use it in GitHub Desktop.
TFS Copy Files Custom Activity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Activities; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
namespace BuildTasks.Activities | |
{ | |
public class CopyFiles : CodeActivity | |
{ | |
[RequiredArgument] | |
public InArgument<IEnumerable<string>> SourceFileMasks { get; set; } | |
[RequiredArgument] | |
public InArgument<string> SourceDirectory { get; set; } | |
[RequiredArgument] | |
public InArgument<string> DestinationDirectory { get; set; } | |
public InArgument<bool> OverwriteFiles { get; set; } | |
protected override void Execute(CodeActivityContext context) | |
{ | |
var sourceFileMasks = context.GetValue(SourceFileMasks); | |
if (sourceFileMasks == null || sourceFileMasks.Count() == 0) return; | |
var sourceDirectory = new DirectoryInfo(context.GetValue(SourceDirectory)); | |
if (!sourceDirectory.Exists) return; | |
var destinationDirectory = context.GetValue(DestinationDirectory); | |
if (!Directory.Exists(destinationDirectory)) return; | |
var overwrite = context.GetValue(OverwriteFiles); | |
foreach (var sourceFileMask in sourceFileMasks) | |
{ | |
var sourceFiles = sourceDirectory.GetFiles(sourceFileMask); | |
foreach (var sourceFile in sourceFiles) | |
{ | |
sourceFile.CopyTo(Path.Combine(destinationDirectory, sourceFile.Name), overwrite); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment