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(); var ret = await AccountClient.Instance.Service.LoginEx("admin", "admin", "0", new LoginClientInfo()); if (ret.Result == LoginRequestResults.Confirmed) { Console.WriteLine("Login Succeeded!"); } else { Console.WriteLine($"Login Failed, {ret.Result}"); } Console.WriteLine("Press ENTER to exit..."); Console.ReadLine(); AccountClient.Instance.Service.LogoutEx(ret.Credential.Token); /* 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.Token); } 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.Sound_Notify: break; case EventType.UIMessage_Notify: //PopUIMessage(obj); break; } } } }