本文整理汇总了C#中RunMode.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# RunMode.HasFlag方法的具体用法?C# RunMode.HasFlag怎么用?C# RunMode.HasFlag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RunMode
的用法示例。
在下文中一共展示了RunMode.HasFlag方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RunAsync
/// <summary>
/// Runs the specified service using the command console as a user interface.
/// </summary>
/// <param name="service">The service.</param>
/// <param name="runMode">The run mode.</param>
/// <param name="defaultLogFormat">The default log format.</param>
/// <param name="defaultLoggingLevels">The default logging levels.</param>
/// <param name="token">The token.</param>
/// <returns>
/// An awaitable task.
/// </returns>
// ReSharper disable once CodeAnnotationAnalyzer
public static async Task RunAsync(
[NotNull] BaseService service,
RunMode runMode = RunMode.Default,
[CanBeNull] FormatBuilder defaultLogFormat = null,
LoggingLevels defaultLoggingLevels = LoggingLevels.All,
CancellationToken token = default(CancellationToken))
{
if (service == null) throw new ArgumentNullException("service");
if (!ConsoleHelper.IsConsole)
return;
Console.Clear();
Log.SetTrace(validLevels: LoggingLevels.None);
Log.SetConsole(defaultLogFormat ?? Log.ShortFormat, defaultLoggingLevels);
await Log.Flush(token).ConfigureAwait(false);
Impersonator impersonator = null;
try
{
if (runMode.HasFlag(RunMode.Prompt))
{
Debug.Assert(service.ServiceName != null);
// Whether we start will depend on the selected option in prompt.
runMode = runMode.Clear(RunMode.Start, true);
Console.Title = ServiceResources.ConsoleConnection_RunAsync_ConfigureTitle + service.ServiceName;
bool done = false;
do
{
if (token.IsCancellationRequested) return;
Dictionary<string, string> options = new Dictionary<string, string>
{
{ "I", ServiceResources.ConsoleConnection_RunAsync_OptionInstall },
{ "U", ServiceResources.ConsoleConnection_RunAsync_OptionUninstall },
{ "S", ServiceResources.ConsoleConnection_RunAsync_OptionStart },
{ "R", ServiceResources.ConsoleConnection_RunAsync_OptionRestart },
{ "T", ServiceResources.ConsoleConnection_RunAsync_OptionStop },
{ "P", ServiceResources.ConsoleConnection_RunAsync_OptionPause },
{ "C", ServiceResources.ConsoleConnection_RunAsync_OptionContinue },
{ "Y", ServiceResources.ConsoleConnection_RunAsync_OptionRunCmd },
{ "V", ServiceResources.ConsoleConnection_RunAsync_OptionStartCmd },
{ "W", ServiceResources.ConsoleConnection_RunAsync_OptionRunCmdNewCredentials },
{ "Z", ServiceResources.ConsoleConnection_RunAsync_OptionRunNoInteraction },
{ "X", ServiceResources.ConsoleConnection_RunAsync_OptionExit }
};
if (!runMode.HasFlag(RunMode.Interactive))
{
options.Remove("V");
options.Remove("Y");
options.Remove("W");
}
bool isAdmin;
string currentUser;
try
{
WindowsIdentity identity = WindowsIdentity.GetCurrent();
currentUser = identity.Name;
Debug.Assert(identity != null);
WindowsPrincipal principal = new WindowsPrincipal(identity);
isAdmin = principal.IsInRole(WindowsBuiltInRole.Administrator);
}
catch
{
isAdmin = false;
currentUser = null;
}
if (!string.IsNullOrEmpty(currentUser))
{
FormatBuilder fb = new FormatBuilder()
.AppendForegroundColor(ConsoleColor.Cyan)
.Append("Current User: ")
.AppendForegroundColor(ConsoleColor.White)
.Append(currentUser);
if (isAdmin)
fb
.AppendForegroundColor(ConsoleColor.Yellow)
.Append(" [Admin]");
fb.AppendLine().WriteToConsole();
}
if (!isAdmin)
{
//.........这里部分代码省略.........