コード例 #1
0
 public IGameSectorsOwner Update(IGameSectorsOwner entity)
 {
     //TODO: save this query somewhere (player <=> data for game sector owner)
     foreach (var gameStateDataCommand in entity.GameSectorLayerServices.Values.SelectMany(s => s.SharedContext.DataLayer.Players.Select(plyr => plyr.LoginToken))
              .Select(loginToken => UserAuthenticationService.GetByLoginTokenHack(loginToken))
              .Where(user => (user.Roles & UserDataRole.CanSendRemoteStateCommands) != 0)
              .SelectMany(user => entity.GameSectorLayerServices.Values.Select(
                              gameSector =>
     {
         try
         {
             var gs = gameSector.SharedContext.IODataLayer.GetGameStateByLoginToken(user.LoginToken);
             return(gs.Commands);
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
         }
         return(new List <string>());
     })))
     {
         gameStateDataCommand.ForEach(cmd =>
         {
             foreach (var gameSector in entity.GameSectorLayerServices.Values)
             {
                 try{
                     gameSector.GetService.Get(cmd).Handle(gameSector);
                 }
                 catch (Exception ex) {
                     CommandInterpreter.Context = gameSector;
                     CommandInterpreter.Run(cmd);
                     CommandInterpreter.Context = null;
                 }
             }
         });
         gameStateDataCommand.Clear();
     }
     return(entity);
 }