コード例 #1
0
        protected void TestWithError(Action <IMachineRuntime> test, Configuration configuration = null,
                                     string[] expectedErrors = null, bool replay = false)
        {
            configuration = configuration ?? GetConfiguration();

            var logger = new Common.TestOutputLogger(this.TestOutput);

            try
            {
                var bfEngine = BugFindingEngine.Create(configuration, test);
                bfEngine.SetLogger(logger);
                bfEngine.Run();

                CheckErrors(bfEngine, expectedErrors);

                if (replay && !configuration.EnableCycleDetection)
                {
                    var rEngine = ReplayEngine.Create(configuration, test, bfEngine.ReproducableTrace);
                    rEngine.SetLogger(logger);
                    rEngine.Run();

                    Assert.True(rEngine.InternalError.Length == 0, rEngine.InternalError);
                    CheckErrors(rEngine, expectedErrors);
                }
            }
            catch (Exception ex)
            {
                Assert.False(true, ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                logger.Dispose();
            }
        }
コード例 #2
0
ファイル: BaseTest.cs プロジェクト: notfarfromorion/PSharp
        protected void AssertFailedWithException(Configuration configuration, Action <IMachineRuntime> test, Type exceptionType)
        {
            Assert.True(exceptionType.IsSubclassOf(typeof(Exception)), "Please configure the test correctly. " +
                        $"Type '{exceptionType}' is not an exception type.");

            var logger = new Common.TestOutputLogger(this.TestOutput);

            try
            {
                var bfEngine = BugFindingEngine.Create(configuration, test);
                bfEngine.SetLogger(logger);
                bfEngine.Run();

                CheckErrors(bfEngine, exceptionType);

                if (!configuration.EnableCycleDetection)
                {
                    var rEngine = ReplayEngine.Create(configuration, test, bfEngine.ReproducableTrace);
                    rEngine.SetLogger(logger);
                    rEngine.Run();

                    Assert.True(rEngine.InternalError.Length == 0, rEngine.InternalError);
                    CheckErrors(rEngine, exceptionType);
                }
            }
            catch (Exception ex)
            {
                Assert.False(true, ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                logger.Dispose();
            }
        }
コード例 #3
0
ファイル: BaseTest.cs プロジェクト: wxdtony/PSharp
        protected void AssertFailed(Configuration configuration, Action <PSharpRuntime> test, int numExpectedErrors, ISet <string> expectedOutputs)
        {
            InMemoryLogger logger = new InMemoryLogger();

            try
            {
                var bfEngine = BugFindingEngine.Create(configuration, test);
                bfEngine.SetLogger(logger);
                bfEngine.Run();

                CheckErrors(bfEngine, numExpectedErrors, expectedOutputs);

                if (!configuration.EnableCycleDetection)
                {
                    var rEngine = ReplayEngine.Create(configuration, test, bfEngine.ReproducableTrace);
                    rEngine.SetLogger(logger);
                    rEngine.Run();

                    Assert.True(rEngine.InternalError.Length == 0, rEngine.InternalError);
                    CheckErrors(rEngine, numExpectedErrors, expectedOutputs);
                }
            }
            catch (Exception ex)
            {
                Assert.False(true, ex.Message + "\n" + ex.StackTrace);
            }
            finally
            {
                logger.Dispose();
            }
        }
コード例 #4
0
 public override void CancelExchange()
 {
     if (ReplayEngine != null)
     {
         ReplayEngine.Dispose();
     }
     ReplayEngine = null;
     Client.Character.SmithMagicInstance = null;
     Client = null;
 }
コード例 #5
0
 public override void CancelExchange()
 {
     if (ReplayEngine != null)
     {
         ReplayEngine.Dispose();
     }
     ReplayEngine = null;
     CraftedItems = null;
     Client.Character.CraftInstance = null;
     Client = null;
 }
コード例 #6
0
ファイル: ReplayLauncher.cs プロジェクト: kellyelton/OCTGN
        protected override async Task <Window> Load(ILoadingView loadingView)
        {
            try {
                var replayClient = new ReplayClient();
                Program.Client = replayClient;

                Program.IsHost = true;

                loadingView.UpdateStatus("Loading Replay..");
                ReplayReader reader = null;
                ReplayEngine engine = null;
                try {
                    reader = ReplayReader.FromStream(File.OpenRead(_replayPath));
                    engine = new ReplayEngine(reader, replayClient);

                    loadingView.UpdateStatus("Loading Game...");
                    var game = GameManager.Get().GetById(reader.Replay.GameId);

                    loadingView.UpdateStatus("Loading Game Engine...");
                    Program.CurrentOnlineGameName = game.Name;
                    Program.GameEngine            = new GameEngine(engine, game, reader.Replay.User);
                } catch {
                    reader?.Dispose();
                    engine?.Dispose();

                    throw;
                }

                var dispatcher = Dispatcher.CurrentDispatcher;

                Window window = null;
                await dispatcher.InvokeAsync(() => {
                    window = WindowManager.PlayWindow = new PlayWindow();

                    window.Closed += PlayWindow_Closed;

                    window.Show();
                }, DispatcherPriority.Background);

                return(window);
            } catch (UserMessageException) {
                throw;
            } catch (Exception e) {
                var msg = $"Error launching replay from {_replayPath}: {e.Message}";

                Log.Warn(msg, e);

                throw new UserMessageException(UserMessageExceptionMode.Blocking, msg, e);
            }
        }
コード例 #7
0
        public void End()
        {
            Program.GameMess.OnMessage -= GameMess_OnMessage;

            SaveHistory();
            ReplayWriter?.Dispose();
            ReplayEngine?.Dispose();
            _logStream?.Dispose();

            Program.GameEngine = null;
            Player.Reset();
            Card.Reset();
            CardIdentity.Reset();
            Selection.Clear();
        }
コード例 #8
0
        /// <summary>
        /// Replays messages that were created from <paramref name="start"/> to <paramref name=
        /// "end"/>, invoking the <paramref name="callback"/> delegate for each message. If
        /// <paramref name="end"/> is null, then messages that were created from <paramref name=
        /// "start"/> to the current UTC time are replayed.
        /// </summary>
        /// <param name="start">The start time.</param>
        /// <param name="end">
        /// The end time, or <see langword="null"/> to indicate that the the current UTC time
        /// should be used.
        /// </param>
        /// <param name="callback">
        /// The delegate to invoke for each replayed message, or <see langword="null"/> to indicate
        /// that <see cref="Receiver.MessageHandler"/> should handle replayed messages.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// If the receiver has not been started yet and <paramref name="callback"/> is null.
        /// </exception>
        public Task Replay(DateTime start, DateTime?end, Func <IReceiverMessage, Task> callback = null)
        {
            if (callback is null)
            {
                if (MessageHandler != null)
                {
                    callback = message => MessageHandler.OnMessageReceivedAsync(this, message);
                }
                else
                {
                    throw new InvalidOperationException($"Replay cannot be called with a null '{nameof(callback)}' parameter before the receiver has been started.");
                }
            }

            return(ReplayEngine.Replay(start, end, callback, Topic, BootstrapServers, EnableAutoOffsetStore, AutoOffsetReset));
        }
コード例 #9
0
        public void Begin()
        {
            if (_BeginCalled)
            {
                return;
            }
            _BeginCalled = true;
            // Register oneself to the server
            Version oversion = Const.OctgnVersion;

            Program.Client.Rpc.Hello(this.Nickname, Player.LocalPlayer.UserId, Player.LocalPlayer.PublicKey,
                                     Const.ClientName, oversion, oversion,
                                     Program.GameEngine.Definition.Id, Program.GameEngine.Definition.Version, this.Password
                                     , Spectator);
            Program.IsGameRunning = true;

            if (IsReplay)
            {
                ReplayEngine.Start();
            }
        }
コード例 #10
0
        public GameEngine(ReplayEngine replayEngine, Game def, string nickname)
        {
            ReplayEngine = replayEngine;
            IsReplay     = true;

            LoadedCards          = new ObservableDeck();
            LoadedCards.Sections = new ObservableCollection <ObservableSection>();

            DeckStats = new DeckStatsViewModel();

            Spectator = false;
            Program.GameMess.Clear();
            if (def.ScriptVersion.Equals(new Version(0, 0, 0, 0)))
            {
                Program.GameMess.Warning("This game doesn't have a Script Version specified. Please contact the game developer.\n\n\nYou can get in contact of the game developer here {0}", def.GameUrl);
                def.ScriptVersion = new Version(3, 1, 0, 0);
            }
            if (Versioned.ValidVersion(def.ScriptVersion) == false)
            {
                Program.GameMess.Warning(
                    "Can't find API v{0}. Loading the latest version.\n\nIf you have problems, get in contact of the developer of the game to get an update.\nYou can get in contact of them here {1}",
                    def.ScriptVersion, def.GameUrl);
                def.ScriptVersion = Versioned.LowestVersion;
            }
            else
            {
                var vmeta = Versioned.GetVersion(def.ScriptVersion);
                if (vmeta.DeleteDate <= DateTime.Now)
                {
                    Program.GameMess.Warning("This game requires an API version {0} which is no longer supported by OCTGN.\nYou can still play, however some aspects of the game may no longer function as expected, and it may be removed at any time.\nYou may want to contact the developer of this game and ask for an update.\n\nYou can find more information about this game at {1}."
                                             , def.ScriptVersion, def.GameUrl);
                }
            }
            //Program.ChatLog.ClearEvents();
            IsLocal    = true;
            Definition = def;
            Password   = string.Empty;
            _table     = new Table(def.Table);
            if (def.Phases != null)
            {
                byte PhaseId = 1;
                _allPhases = def.Phases.Select(x => new Phase(PhaseId++, x)).ToList();
            }
            GlobalVariables = new Dictionary <string, string>();
            foreach (var varDef in def.GlobalVariables)
            {
                GlobalVariables.Add(varDef.Key, varDef.Value.Value);
            }
            ScriptApi     = Versioned.Get <ScriptApi>(Definition.ScriptVersion);
            this.Nickname = nickname;

            // Init fields
            CurrentUniqueId = 1;
            TurnNumber      = 0;
            if (Definition.GameBoards.ContainsKey(""))
            {
                GameBoard = Definition.GameBoards[""];
            }
            ActivePlayer = null;

            foreach (var size in Definition.CardSizes)
            {
                var front = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Front));
                var back  = ImageUtils.CreateFrozenBitmap(new Uri(size.Value.Back));
                _cardFrontsBacksCache.Add(size.Value.Name, new Tuple <BitmapImage, BitmapImage>(front, back));
            }
            Application.Current.Dispatcher.Invoke(new Action(() => {
                // clear any existing players
                Play.Player.All.Clear();
                Player.Spectators.Clear();
                // Create the global player, if any
                if (Definition.GlobalPlayer != null)
                {
                    Play.Player.GlobalPlayer = new Play.Player(Definition, IsReplay);
                }
                // Create the local player
                Play.Player.LocalPlayer = new Player(Definition, this.Nickname, Program.UserId, 255, Crypto.ModExp(Prefs.PrivateKey), false, true, IsReplay);

                IsConnected = true;
            }));
        }