Example #1
0
 void RegisterUserDeviceOnServer()
 {
     var device = new Device ();
     string deviceId = device.DeviceId;
     Debug.Log("deviceId: " + deviceId + " device Model: " + device.Model + " device UniqueIdentifier: " + device.UniqueIdentifier);
     WebServiceAdapter wsa = new WebServiceAdapter ();
     StartCoroutine (wsa.GetUserByKey(device.DeviceId, Application.systemLanguage.ToString()));
 }
        // TODO: Move into a common ConsoleHelper class.
        // TODO: Move parameters into a GameRunnerConfiguration class.
        private static void RunSolverInConsole <TGameState, TSolver>(
            string appName, string serverUrl, string loggingRootFolder, string gameFilePath, int tickToReplayTo, bool errorReadingTickToReplayTo)
            where TGameState : GameState <TGameState>, new()
            where TSolver : ISolver <TGameState>, new()
        {
            // Set up debugging:
            DebugHelper.InitializeLogFolder(DateTime.Now, loggingRootFolder, appName);
            DebugHelper.WireUpDebugListeners(includeConsoleListener: true);
            try
            {
                // Set up web service adapter:
                WebServiceAdapter wsAdapter = new WebServiceAdapter
                {
                    Url = serverUrl,
                    EndPointConfigurationName = "ChallengePort"
                };

                // Set up solvers and coordinators:
                ISolver <TGameState> solver = new TSolver();

                if (!string.IsNullOrEmpty(gameFilePath))
                {
                    DebugHelper.LogDebugMessage(appName, "Replaying game: {0}", gameFilePath);
                    if (errorReadingTickToReplayTo)
                    {
                        DebugHelper.LogDebugMessage(appName,
                                                    "WARNING: The fourth parameter can't be parsed as a 'Tick To Replay To'. Using default.");
                    }

                    Game gameToReplay = Game.Load(gameFilePath);
                    if (tickToReplayTo == -1)
                    {
                        tickToReplayTo = gameToReplay.CurrentTurn.Tick;
                    }
                    DebugHelper.LogDebugMessage(appName, "Replaying to turn {0}.", tickToReplayTo);
                    if (gameToReplay.Turns[tickToReplayTo].TankActionsTakenAfterPreviousTurn == null)
                    {
                        throw new ApplicationException(
                                  String.Format(
                                      "No tank actions were recorded for the game's last tick ({0})",
                                      tickToReplayTo
                                      )
                                  );
                    }

                    solver.GameToReplay   = gameToReplay;
                    solver.TickToReplayTo = tickToReplayTo;
                }

                ICommunicatorCallback    communicatorCallback = new RemoteCommunicatorCallback();
                Coordinator <TGameState> coordinator          = new Coordinator <TGameState>(solver, wsAdapter, communicatorCallback);

                // Write log file headers and set the coordinator running:
                DebugHelper.LogDebugMessage(appName, "Running solver: {0}", solver.Name);
                DebugHelper.WriteLine('=');
                DebugHelper.WriteLine();
                try
                {
                    coordinator.Run();
                }
                catch (Exception exc)
                {
                    DebugHelper.LogDebugError(appName, exc);
                }
            }
            finally
            {
                DebugHelper.LogDebugMessage(appName, "EXITING");
                DebugHelper.WriteLine('-');
            }
        }