Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
TFS Copy Files Custom Activity
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