简体   繁体   English

InvokeProcess的TFS活动(无需等待)

[英]TFS Activity for InvokeProcess (without wait)

I see lots of posts for waiting on the return value of various activities, but in this case, I'd like to kick off an activity and then not wait. 我看到很多帖子都在等待各种活动的返回值,但是在这种情况下,我想开始一项活动然后不等待。 I just want to copy a directory over a (very) slow network, so I'd prefer not to create another activity or use a batch script for this. 我只想通过(非常慢的)网络复制目录,所以我不希望为此创建另一个活动或使用批处理脚本。 Anyone done this? 有人这样做吗? Is there a clean way? 有没有干净的方法? I could cobble something together, but I'm trying to keep this as vanilla as possible. 我可以将一些东西拼凑在一起,但我正在尝试尽可能地保持这种效果。

Here is simple custom activity that will create new process: 这是将创建新流程的简单自定义活动:

[BuildActivity (HostEnvironmentOption.All)]
public sealed class InvokeProcessAsync : CodeActivity
{
    [RequiredArgument]
    public InArgument<string> FileName { get; set; }

    public InArgument<string> Arguments { get; set; }

    public InArgument<string> WorkingDirectory { get; set; }

    public InArgument<IDictionary<string, string>> EnvironmentVariables { get; set; }



    protected override void Execute (CodeActivityContext context)
    {
        context.DublicateOperationsLogsToBuildOutput ();

        var psi = new ProcessStartInfo
        {
            FileName = context.GetValue (this.FileName),
            Arguments = context.GetValue (this.Arguments),
            WorkingDirectory = context.GetValue (this.WorkingDirectory)
        };

        var env_vars = context.GetValue (this.EnvironmentVariables);
        if (env_vars != null)
        {
            foreach (var v in env_vars)
                psi.EnvironmentVariables.Add (v.Key, v.Value);
        }

        Process.Start (psi);
    }
}

I don't think that something out of the box is available for you to use. 我认为没有可用的开箱即用的东西。

One way to proceed is to organize an "Invoke Process" that invokes another service that does the actual copying. 一种进行方式是组织“调用过程”,该过程调用另一个执行实际复制的服务。 So from within Build you advance and let the invoked entity (that is out of scope in terms of TFS build) do the actual activity. 因此,您可以从Build内部进行扩展,并让被调用的实体(就TFS构建而言不在范围内)进行实际的活动。 This does come with certain deficiencies, the more important being that you won't ever know in your build-logs if this succeeded or failed. 这确实存在某些缺陷,更重要的是,如果成功或失败,您将永远不会在构建日志中知道。

Another option is to use the Parallel activity (it's in the Toolbox under "Control Flow" - System.Activities.Statements.Parallel ). 另一个选择是使用Parallel活动(在“控制流”下的“工具箱”中System.Activities.Statements.Parallel )。 This is not quite like what you need (kick & forget), still it could allow you to do other stuff while your copy happens. 这与您所需要的不完全相同(踢完即忘),它仍然可以让您在复制发生时做其他事情。

您需要Build.Workflow程序集中的CopyDirectory活动。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM