2023-09-13 18:05:49 +08:00
|
|
|
|
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();
|
2023-09-15 17:44:30 +08:00
|
|
|
|
Console.ForegroundColor = ConsoleColor.DarkGreen;
|
|
|
|
|
Console.WriteLine(@"Accounts:");
|
2023-09-13 18:05:49 +08:00
|
|
|
|
foreach (var acc in accounts)
|
|
|
|
|
{
|
2023-09-18 10:13:40 +08:00
|
|
|
|
Console.WriteLine($@" {acc.LoginName}");
|
2023-09-13 18:05:49 +08:00
|
|
|
|
}
|
|
|
|
|
Console.ResetColor();
|
2023-09-15 17:44:30 +08:00
|
|
|
|
|
2023-09-18 10:13:40 +08:00
|
|
|
|
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)
|
2023-09-15 17:44:30 +08:00
|
|
|
|
{
|
|
|
|
|
var cmd = WaitCommand();
|
|
|
|
|
if(string.IsNullOrEmpty(cmd))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (cmd == "exit")
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
ParseCommand(cmd);
|
|
|
|
|
}
|
2023-09-18 10:13:40 +08:00
|
|
|
|
*/
|
2023-09-15 17:44:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
2023-09-18 10:13:40 +08:00
|
|
|
|
AccountClient.Instance.Service.LogoutEx(_loginCred.Token);
|
2023-09-13 18:05:49 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|