Skip to content

Commit 332b96a

Browse files
committed
Few updates to some of the examples project.
1 parent 5a980e4 commit 332b96a

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
namespace VirtualClient
5+
{
6+
using System.Threading.Tasks;
7+
using System.Threading;
8+
using System;
9+
10+
internal class InstallCommand
11+
{
12+
/// <summary>
13+
/// Executes the default monitor execution command.
14+
/// </summary>
15+
/// <param name="args">The arguments provided to the application on the command line.</param>
16+
/// <param name="cancellationTokenSource">Provides a token that can be used to cancel the command operations.</param>
17+
/// <returns>The exit code for the command operations.</returns>
18+
public async Task<int> ExecuteAsync(string[] args, CancellationTokenSource cancellationTokenSource)
19+
{
20+
21+
int exitCode = 0;
22+
23+
try
24+
{
25+
CancellationToken cancellationToken = cancellationTokenSource.Token;
26+
Guid dependencyId = Guid.NewGuid();
27+
28+
Console.Out.WriteLine();
29+
Console.Out.WriteLine($"Setup/Install Dependency: {dependencyId}");
30+
Console.Out.WriteLine($"Version: 2.0.0");
31+
Console.Out.WriteLine($"-------------------------------------------------------");
32+
33+
try
34+
{
35+
Console.Out.Write($"Installing");
36+
DateTime randomEndTime = DateTime.UtcNow.AddSeconds(Random.Shared.Next(10, 20));
37+
38+
while (DateTime.UtcNow < randomEndTime)
39+
{
40+
if (cancellationToken.IsCancellationRequested)
41+
{
42+
break;
43+
}
44+
45+
Console.Out.Write(".");
46+
await Task.Delay(2000);
47+
}
48+
49+
if (!cancellationToken.IsCancellationRequested)
50+
{
51+
Console.Out.WriteLine();
52+
Console.Out.WriteLine("Installation Successful");
53+
}
54+
}
55+
finally
56+
{
57+
Console.Out.WriteLine();
58+
}
59+
}
60+
catch (Exception exc)
61+
{
62+
Console.Error.WriteLine();
63+
Console.Error.WriteLine("Installation FAILED");
64+
Console.Error.WriteLine();
65+
Console.Error.WriteLine(exc.Message);
66+
Console.Error.WriteLine(exc.StackTrace);
67+
Console.Error.WriteLine();
68+
exitCode = 1;
69+
}
70+
71+
return exitCode;
72+
}
73+
}
74+
}

src/VirtualClient/VirtualClient.ExampleWorkload/Program.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ private static CommandLineBuilder SetupCommandLine(string[] args, CancellationTo
107107
rootCommand.AddCommand(runMonitorCommand);
108108
rootCommand.AddCommand(runApiCommand);
109109

110+
return new CommandLineBuilder(rootCommand).WithDefaults();
111+
}
112+
113+
private static CommandLineBuilder SetupCommandLine2(string[] args, CancellationTokenSource cancellationTokenSource)
114+
{
115+
RootCommand rootCommand = new RootCommand("Installs a dependency on the system.")
116+
{
117+
Handler = CommandHandler.Create<InstallCommand>(cmd => cmd.ExecuteAsync(args, cancellationTokenSource))
118+
};
119+
120+
110121
return new CommandLineBuilder(rootCommand).WithDefaults();
111122
}
112123
}

src/VirtualClient/VirtualClient.ExampleWorkload/VirtualClient.ExampleWorkload.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<RunAnalyzers>false</RunAnalyzers>
1010
<IsPackable>true</IsPackable>
1111
<DelaySign>false</DelaySign>
12-
<NoWarn>CA1416,NU5100,NU5118,NU5128,SA1118</NoWarn>
12+
<NoWarn>CA1416,IL2026,IL2104,IL2072,IL3000,NU5100,NU5118,NU5128,SA1118</NoWarn>
1313
</PropertyGroup>
1414

1515
<ItemGroup>

0 commit comments

Comments
 (0)