当前位置: 首页>>代码示例>>C#>>正文


C# Executor.execute方法代码示例

本文整理汇总了C#中Executor.execute方法的典型用法代码示例。如果您正苦于以下问题:C# Executor.execute方法的具体用法?C# Executor.execute怎么用?C# Executor.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Executor的用法示例。


在下文中一共展示了Executor.execute方法的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);
     }
 }
开发者ID:apolol92,项目名称:SmartTransfer,代码行数:84,代码来源:DServer.cs


注:本文中的Executor.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。