using System; using System.Threading.Tasks; using Aitex.Core.Account; using Aitex.Core.RT.Event; using Aitex.Core.WCF; using MECF.Framework.UI.Core.Accounts; namespace UserLoginTester { internal class Program { private static Credential _loginCred; public static async Task Main(string[] args) { EventClient.Instance.OnEvent += Instance_OnEvent; EventClient.Instance.OnDisconnectedWithRT += Instance_OnDisconnectedWithRT; EventClient.Instance.Start(); var accounts = AccountClient.Instance.Service.GetAccounts(); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine(@"Accounts:"); foreach (var acc in accounts) { Console.WriteLine($@" {acc.LoginName}"); } Console.ResetColor(); while (true) { var cmd = WaitCommand(); if(string.IsNullOrEmpty(cmd)) continue; if (cmd == "exit") break; ParseCommand(cmd); } } private static string WaitCommand() { Console.Write(@"Input Command [login]\\[logout]\[exit]:"); return Console.ReadLine(); } private static void ParseCommand(string command) { switch (command) { case "login": LoginProcess(); break; case "logout": break; default: Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(@"Invalid Command"); Console.ResetColor(); break; } } private static void LoginProcess() { Console.Write(@"User Name:"); var userName = Console.ReadLine(); Console.Write(@"Password:"); var password = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine($@"Logging in as {userName} ..."); var t = AccountClient.Instance.Service.LoginEx(userName, password, "0", null); Task.WaitAll(t); if (t.Result.Result == LoginRequestResults.Confirmed) { Console.WriteLine($@"Login Succeed!"); _loginCred = t.Result.Credential; } else { Console.WriteLine($@"Login Failed, {t.Result.Result}!"); } } private static void LogoutProcess() { AccountClient.Instance.Service.LogoutEx(_loginCred); } private static void Instance_OnDisconnectedWithRT() { throw new NotImplementedException(); } private static void Instance_OnEvent(EventItem evt) { switch (evt.Type) { case EventType.EventUI_Notify: break; case EventType.Dialog_Nofity: break; case EventType.KickOut_Notify: break; case EventType.LoginBySameUser_Notify: if (Guid.TryParse(evt.Description, out var token) && evt.Tag is Credential requestingCred) { if (_loginCred != null && token == _loginCred.Token) { Console.WriteLine( @"Some users is requesting to login the system, you will be forced to switch to read-only mode, do you agree?"); __prompt: Console.Write("[Y]es/[N]o: "); var ack = Console.ReadLine(); switch (ack) { case "Y": AccountClient.Instance.Service.ConfirmLoginRequest(requestingCred); AccountClient.Instance.Service.LogoutEx(_loginCred); break; case "N": AccountClient.Instance.Service.RejectLoginRequest(requestingCred); break; default: goto __prompt; } } } break; case EventType.Sound_Notify: break; case EventType.UIMessage_Notify: //PopUIMessage(obj); break; } } } }