提交 2caf789b 编写于 作者: L Larry Golding

ProcessWatchdog: Parse the timeout interval.

上级 9a32b8ea
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Globalization;
namespace ProcessWatchdog
{
internal static class ConsoleUtils
{
internal static void ReportError(string messageFormat, params string[] args)
{
string fullMessage = string.Format(
CultureInfo.InvariantCulture,
Resources.ErrorFormat,
string.Format(CultureInfo.InvariantCulture, messageFormat, args));
Console.Error.WriteLine(fullMessage);
}
}
}
\ No newline at end of file
......@@ -26,6 +26,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConsoleUtils.cs" />
<Compile Include="Options.cs" />
<Compile Include="Program.cs" />
<Compile Include="Resources.Designer.cs">
......
......@@ -13,6 +13,7 @@ namespace ProcessWatchdog
internal sealed class Program
{
private Options _options;
private TimeSpan _timeout;
public Program(Options options)
{
......@@ -21,6 +22,20 @@ public Program(Options options)
private int Run()
{
try
{
_timeout = TimeSpan.Parse(_options.Timeout);
}
catch (Exception ex)
{
ConsoleUtils.ReportError(Resources.ErrorInvalidTimeoutInterval, _options.Timeout, ex.Message);
return 1;
}
Console.WriteLine("Options:");
Console.WriteLine("Timeout: {0:c}", _timeout);
Console.WriteLine("Command: {0}", _options.CommandLine);
return 0;
}
......
......@@ -77,5 +77,23 @@ internal class Resources {
return ResourceManager.GetString("Banner", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Error: {0}.
/// </summary>
internal static string ErrorFormat {
get {
return ResourceManager.GetString("ErrorFormat", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The string &quot;{0}&quot; is not a valid TimeSpan. {1} Please specify the timeout interval with a string of the form hh:mm[:ss]..
/// </summary>
internal static string ErrorInvalidTimeoutInterval {
get {
return ResourceManager.GetString("ErrorInvalidTimeoutInterval", resourceCulture);
}
}
}
}
......@@ -123,4 +123,10 @@
<data name="Banner" xml:space="preserve">
<value>{0} version {1}</value>
</data>
<data name="ErrorFormat" xml:space="preserve">
<value>Error: {0}</value>
</data>
<data name="ErrorInvalidTimeoutInterval" xml:space="preserve">
<value>The string "{0}" is not a valid TimeSpan. {1} Please specify the timeout interval with a string of the form hh:mm[:ss].</value>
</data>
</root>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册