本文整理汇总了C#中Executor.createErrorCommand方法的典型用法代码示例。如果您正苦于以下问题:C# Executor.createErrorCommand方法的具体用法?C# Executor.createErrorCommand怎么用?C# Executor.createErrorCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Executor
的用法示例。
在下文中一共展示了Executor.createErrorCommand方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: run
/// <summary>
/// Use this method to run the server
/// </summary>
public void run()
{
//This Factory creates commands
CommandFactory MyCommandFactory = new CommandFactory();
//This Guardian protects the current user
Guardian MyGuardian = new Guardian();
//This Executor executes commands
Executor MyExecutor = new Executor(MyGuardian);
while (true)
{
//This Command will be the response command
Command ResponseCommand;
//Wait for a client
TcpClient client = server.AcceptTcpClient();
//Get RequestCommand as String
String RequestCommandStr = getRequestCommandStr(client);
//Extract RequestCommandStr
Command CurrentCommand = MyCommandFactory.extractCommandFromStr(RequestCommandStr);
//Wrong command?
if(CurrentCommand == null)
{
continue;
}
//Is no user under protection/login?
if (!MyGuardian.isGuarding() && CurrentCommand.Typ ==9)
{
//If Password correct.. Login
if (CurrentCommand.Parameter == MyGuardian.ServerPassword)
{
CurrentCommand.Id = MyGuardian.generateGuardingId();
//Activate keep alive
MyGuardian.keepClientAlive();
}
else
{
//TODO: Wrong PASSWORD!!
}
}
//No user is logged in, but no incoming login
else if(!MyGuardian.isGuarding() && CurrentCommand.Typ != 9)
{
//Continue if no login
continue;
}
//Is this the protected user & all alright?
if(MyGuardian.getGuardingId()==CurrentCommand.Id && MyGuardian.isClientAlive())
{
ResponseCommand = MyExecutor.execute(CurrentCommand);
//Generate new ID for security reasons
ResponseCommand.Id = generateNewId(CurrentCommand.Id);
//Let the new ID know by the guardian
MyGuardian.setGuardingId(ResponseCommand.Id);
}
//Client is dead and sent command to late
else if(MyGuardian.getGuardingId() == CurrentCommand.Id && !MyGuardian.isClientAlive())
{
CurrentCommand.Typ = 8; //Simulate User logout
//Kill Client..
ResponseCommand = MyExecutor.execute(CurrentCommand);
}
//Other user is connecting while main user is dead
else if(!MyGuardian.isClientAlive())
{
//Reset rest
MyGuardian.resetProtection();
//Generate new command
CurrentCommand.Id = MyGuardian.generateGuardingId();
//Activate keep alive
MyGuardian.keepClientAlive();
//Create Response with login successed
ResponseCommand = MyExecutor.execute(CurrentCommand);
}
else
{
//No access, because other user is using the server
ResponseCommand = MyExecutor.createErrorCommand(CurrentCommand);
}
//Send response
sendResponseCommand(ResponseCommand);
}
}