forked from dotnet/machinelearning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChainCommand.cs
More file actions
80 lines (65 loc) · 2.85 KB
/
Copy pathChainCommand.cs
File metadata and controls
80 lines (65 loc) · 2.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Globalization;
using Microsoft.ML;
using Microsoft.ML.Command;
using Microsoft.ML.CommandLine;
using Microsoft.ML.Tools;
[assembly: LoadableClass(ChainCommand.Summary, typeof(ChainCommand), typeof(ChainCommand.Arguments), typeof(SignatureCommand),
"Chain Command", "Chain")]
namespace Microsoft.ML.Tools
{
using Stopwatch = System.Diagnostics.Stopwatch;
[BestFriend]
internal sealed class ChainCommand : ICommand
{
public sealed class Arguments
{
#pragma warning disable 649 // never assigned
[Argument(ArgumentType.Multiple, HelpText = "Command", ShortName = "cmd", SignatureType = typeof(SignatureCommand))]
public IComponentFactory<ICommand>[] Command;
#pragma warning restore 649 // never assigned
}
internal const string Summary = "A command that chains multiple other commands.";
private readonly IHost _host;
private readonly Arguments _args;
public ChainCommand(IHostEnvironment env, Arguments args)
{
Contracts.CheckValue(env, nameof(env));
env.CheckValue(args, nameof(args));
_args = args;
_host = env.Register("Chain");
}
public void Run()
{
using (var ch = _host.Start("Run"))
{
var sw = new Stopwatch();
int count = 0;
sw.Start();
if (_args.Command != null)
{
for (int i = 0; i < _args.Command.Length; i++)
{
using (var chCmd = _host.Start(string.Format(CultureInfo.InvariantCulture, "Command[{0}]", i)))
{
var sub = _args.Command[i];
chCmd.Info("=====================================================================================");
chCmd.Info("Executing: {0}", sub);
chCmd.Info("=====================================================================================");
var cmd = sub.CreateComponent(_host);
cmd.Run();
count++;
chCmd.Info(" ");
}
}
}
sw.Stop();
ch.Info("=====================================================================================");
ch.Info("Executed {0} commands in {1}", count, sw.Elapsed);
ch.Info("=====================================================================================");
}
}
}
}