Esempio n. 1
0
 public ChatMessageAction(Func <ChatMessage, bool> func, bool removeOnSuccess, LobbyController lc, EventRunner eventRunner)
 {
     _func           = func;
     RemoveOnSuccess = removeOnSuccess;
     _lc             = lc;
     _evRunner       = eventRunner;
 }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Portfolio"/> class.
        /// </summary>
        /// <param name="clock">The clock.</param>
        /// <param name="actionscheduler">The actionscheduler.</param>
        /// <param name="brokerconnection">The brokerconnection.</param>
        /// <param name="brokermodel">The brokermodel.</param>
        /// <param name="currency">The currency.</param>
        /// <param name="eventrunner">The eventrunner.</param>
        /// <param name="exceptionhandler">The exceptionhandler.</param>
        /// <param name="orderTicketHandler">The order ticket handler.</param>
        /// <param name="brokeraccount">The brokeraccount.</param>
        /// <param name="cashmanager">The cashmanager.</param>
        /// <param name="runmode">The runmode.</param>
        /// <param name="datafeed">The datafeed.</param>
        /// <param name="benchmark">The benchmark.</param>
        /// <param name="id">The identifier.</param>
        public Portfolio(WorldClock clock, ActionsScheduler actionscheduler, BrokerConnection brokerconnection, BrokerModel brokermodel,
                         Currency currency, EventRunner eventrunner, ExceptionHandler exceptionhandler, OrderTicketHandler orderTicketHandler,
                         BrokerAccount brokeraccount, CashManager cashmanager, RunMode runmode, DataFeed datafeed, Benchmark benchmark, string id = "")
        {
            //Set references
            ActionsScheduler   = actionscheduler;
            BrokerAccount      = brokeraccount;
            BrokerConnection   = brokerconnection;
            BrokerModel        = brokermodel;
            Clock              = clock;
            Currency           = currency;
            EventRunner        = eventrunner;
            ExceptionHandler   = exceptionhandler;
            CashManager        = cashmanager;
            OrderTicketHandler = orderTicketHandler;
            _porfolioBenchmark = benchmark;

            //Set initial items
            Id            = id;
            IsBacktesting = runmode == RunMode.Backtester;
            OrderFactory  = new OrderFactory(this, BrokerModel);
            OrderTracker  = new OrderTracker(this);
            Subscription  = new DataSubscriptionManager(datafeed, CashManager);
            Results       = new Result(0, _porfolioBenchmark);

            //Portfolio benchmark is not used
            benchmark.OnCalc(x => 0);
        }
            /************************************************************************************************************************/

            /// <summary>
            /// If the <see cref="AnimancerEvent.Sequence"/> was acquired from the <see cref="ObjectPool"/>, this
            /// method clears it. Otherwise it simply discards the reference.
            /// </summary>
            public static void TryClear(EventRunner events)
            {
                if (events != null && events._Events != null)
                {
                    events.Events = null;
                }
            }
Esempio n. 4
0
        /// <summary>
        /// Send Error message
        /// </summary>
        /// <param name="severity"></param>
        /// <param name="message">The message.</param>
        /// <param name="fundid"></param>
        public void Log(LogLevel severity, string message, string fundid = "")
        {
            //Send to user log
            _userlog.Log(severity, message);

            //Send as message
            EventRunner.Enqueue(LoggingMessage.Create(fundid, message, severity.Name));
        }
Esempio n. 5
0
        /// <summary>
        /// Removes the quant fund from this portfolio.
        /// </summary>
        /// <param name="quantfund">The quantfund.</param>
        /// <exception cref="NotImplementedException"></exception>
        public void RemoveFund(IQuantFund quantfund)
        {
            throw new NotImplementedException();

            //Send updates (so we know this quant fund was remvoved)
            EventRunner.Enqueue(FundInfoMessage.Generate(Id, quantfund), true);

            //Remove funds
            CashManager.RemoveQuantFund(quantfund);
        }
Esempio n. 6
0
 public UpdateSettings(LobbyController lc, EventRunner evr) : base(lc, evr)
 {
     _settingParsers = new Dictionary <string, Action <string> >()
     {
         { "room name: ", new Action <string>(s => ((Settings)lc.Settings).RoomName = s) },
         { "history: ", new Action <string>(s => ((Settings)lc.Settings).HistoryUrl = s) },
         { "team mode: ", new Action <string>(s => ((Settings)lc.Settings).TeamMode = Enum.Parse <TeamMode>(s)) },
         { "win condition: ", new Action <string>(s => ((Settings)lc.Settings).WinCondition = Enum.Parse <WinCondition>(s)) }
     };
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public ScreenWorld(IScreenLoader screenLoader, ITileLoader tileLoader, IEntityLoader entityLoader, EventRunner eventRunner) : base(screenLoader)
 {
     this.tileLoader    = tileLoader;
     this.entityLoader  = entityLoader;
     this.eventRunner   = eventRunner;
     worldObjects       = new List <WorldObject>();
     eventSwitchHandler = new EventSwitchHandler();
     eventSwitchHandler.AddEventSwitch(new EventSwitch {
         Id = 1, Name = "Test", On = false
     });
 }
Esempio n. 8
0
        public override void Run(GameState gameState)
        {
            for (int i = 0; i < this.DrawCount; i++)
            {
                var drawEventPlayer1 = new PlayerDrawCardEvent(Player.Player1);
                var drawEventPlayer2 = new PlayerDrawCardEvent(Player.Player2);

                EventRunner.RunEvent(drawEventPlayer1, gameState);
                EventRunner.RunEvent(drawEventPlayer2, gameState);
            }
        }
        public async Task HandleEvent_TaskEventResult()
        {
            // Arrange
            kernel.Bind <ITestEventTask>().ToConstant(new TestEventTask());

            // Act
            var runner = new EventRunner(this.kernel);
            var result = await runner.HandleEvent <ITestEventTask>(t => t.DoStuffEventResult(123), new Event());

            // Assert
            Assert.That(result.SourceIds.First(), Is.EqualTo(456));
        }
        public async Task HandleEvent_Action()
        {
            // Arrange
            kernel.Bind <ITestEventTask>().ToConstant(new TestEventTask());

            // Act
            var runner = new EventRunner(this.kernel);
            var result = await runner.HandleEvent <ITestEventTask>(t => t.DoStuff2(123), new Event());

            // Assert
            Assert.That(result.Succeeded, Is.True);
        }
Esempio n. 11
0
 /// <summary>
 /// Sends the event messages.
 /// </summary>
 public void SendEventMessages()
 {
     //Send all message updates
     if (_lastmessagesend < (Clock.CurrentUtc + _mintwaitmessageupdates))
     {
         EventRunner.SendAccountInfoMessages(this);
         EventRunner.SendFundInfoMessages(Id, QuantFunds);
         EventRunner.SendInstanceInfoMessage(BrokerConnection);
         EventRunner.SendPendingOrderInfoMessages(QuantFunds, OrderTracker, Id);
         EventRunner.SendPerformanceInfoMessages(BrokerAccount, QuantFunds);
         EventRunner.SendPositionInformationMessages(QuantFunds, CashManager, BrokerAccount);
         _lastmessagesend = Clock.CurrentUtc;
     }
 }
Esempio n. 12
0
        static void Main(string[] args)
        {
            var server = new NetworkGameServer();

            EventRunner.RegisterGameServer(server);

            Handshake(server);

            var gameLoop = new GameLoop(new NetworkEventProvider(server), MakePlayerDeck(), MakePlayerDeck());

            gameLoop.PlayGame();

            Console.ReadKey();
        }
Esempio n. 13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PortfolioImplementations"/> class.
 /// </summary>
 /// <param name="actionsScheduler">The actions scheduler.</param>
 /// <param name="api">The API.</param>
 /// <param name="brokerconnection">The brokerconnection.</param>
 /// <param name="cluster">The cluster.</param>
 /// <param name="datafeed">The datafeed.</param>
 /// <param name="datafilter">The datafilter.</param>
 /// <param name="eventrunner">The eventrunner.</param>
 /// <param name="exceptionhandler">The exceptionhandler.</param>
 /// <param name="messagequeue">The messagequeue.</param>
 /// <param name="ordertickethandler">The ordertickethandler.</param>
 /// <param name="currency">The currency.</param>
 public PortfolioImplementations(ActionsScheduler actionsScheduler, Benchmark benchmark,
                                 BrokerConnection brokerconnection, Cluster cluster, DataFeed datafeed,
                                 DataFilter datafilter, EventRunner eventrunner, ExceptionHandler exceptionhandler,
                                 MessageQueue messagequeue, OrderTicketHandler ordertickethandler, Currency currency)
 {
     ActionsScheduler   = actionsScheduler;
     Benchmark          = benchmark;
     BrokerConnection   = brokerconnection;
     Cluster            = cluster;
     DataFeed           = datafeed;
     DataFilter         = datafilter;
     EventRunner        = eventrunner;
     ExceptionHandler   = exceptionhandler;
     MessageQueue       = messagequeue;
     OrderTicketHandler = ordertickethandler;
     Currency           = currency;
 }
Esempio n. 14
0
        public override void Run(GameState gameState)
        {
            if (gameState == null)
            {
                throw new System.ArgumentNullException(nameof(gameState));
            }

            var dealDamageEvent = new CardAttackDealDamageEvent(this.Target, this.Attacker);

            EventRunner.RunEvent(dealDamageEvent, gameState);

            // the deal damage event may have triggered other actions that killed the target.
            if (this.Target.Value.IsAlive)
            {
                var takeDamageEvent = new CardAttackTakeDamageEvent(this.Target, this.Attacker);
                EventRunner.RunEvent(takeDamageEvent, gameState);
            }
        }
Esempio n. 15
0
 public static List <ChatMessageAction> ToList(LobbyController lc, EventRunner evRunner)
 {
     return(new List <ChatMessageAction>()
     {
         new UserLeft(lc, evRunner),
         new UserJoined(lc, evRunner),
         new UserMoved(lc, evRunner),
         new UserScore(lc, evRunner),
         new UpdateSettings(lc, evRunner),
         new AllUsersReady(lc, evRunner),
         new MapFinished(lc, evRunner),
         new MatchStarted(lc, evRunner),
         new MapChanged(lc, evRunner),
         new MatchStartsIn(lc, evRunner),
         new QueueMatchStart(lc, evRunner),
         new AbortMatch(lc, evRunner)
     });
 }
Esempio n. 16
0
        public void DrawCard()
        {
            const int    StartingDeckSize = 10;
            const Player playerToDraw     = Player.Player2;

            var deck1 = new Deck().WithCardCount(StartingDeckSize);
            var deck2 = new Deck().WithCardCount(StartingDeckSize);

            var gameState = new GameState(deck1, deck2);

            int startingHandSize = gameState.GetHand(playerToDraw).Size;

            var drawEvent = new PlayerDrawCardEvent(playerToDraw);

            EventRunner.RunEvent(drawEvent, gameState);

            Assert.Equal(StartingDeckSize - 1, deck2.Size);
            Assert.Equal(startingHandSize + 1, gameState.GetHand(playerToDraw).Size);
        }
        private static bool RunEvents(string target, long eps, int messageSize)
        {
            var done = new ManualResetEvent[coreCount];

            Spammer.Log.Start(target, coreCount, eps, duration, eps * duration * coreCount);
            var timer = new Stopwatch();

            timer.Start();
            for (int i = 0; i < coreCount; ++i)
            {
                done[i] = new ManualResetEvent(false);
                var runner = new EventRunner(eps, duration, messageSize, done[i]);
                ThreadPool.QueueUserWorkItem(runner.Task);
            }
            WaitHandle.WaitAll(done);
            timer.Stop();
            bool stopped = false;

            while (!stopped)
            {
                try
                {
                    Spammer.Log.Stop(target, timer.ElapsedMilliseconds, eventsLost);
                    stopped = true;
                }
                catch (EventSourceException)
                {
                    ++eventsLost;
                    Thread.Sleep(10);
                }
            }

            if (eventsLost > 0)
            {
                eventsLost = 0;
                return(false);
            }
            return(true);
        }
Esempio n. 18
0
 public UserScore(LobbyController lc, EventRunner evr) : base(lc, evr)
 {
 }
Esempio n. 19
0
 public GameLogicTests()
 {
     EventRunner.RegisterGameServer(new TestServer());
 }
Esempio n. 20
0
 public UserMoved(LobbyController lc, EventRunner evr) : base(lc, evr)
 {
 }
Esempio n. 21
0
 public ChangeHost(LobbyController lc, EventRunner ev) : base(lc, ev)
 {
 }
Esempio n. 22
0
 public AbortMatch(LobbyController lc, EventRunner evr) : base(lc, evr)
 {
 }
Esempio n. 23
0
 public QueueMatchStart(LobbyController lc, EventRunner evr) : base(lc, evr)
 {
 }
Esempio n. 24
0
 public MatchStartsIn(LobbyController lc, EventRunner evr) : base(lc, evr)
 {
 }
Esempio n. 25
0
 public MapChanged(LobbyController lc, EventRunner evr) : base(lc, evr)
 {
 }
        private static bool RunEvents(string target, long eps, int messageSize)
        {
            var done = new ManualResetEvent[coreCount];

            Spammer.Log.Start(target, coreCount, eps, duration, eps * duration * coreCount);
            var timer = new Stopwatch();
            timer.Start();
            for (int i = 0; i < coreCount; ++i)
            {
                done[i] = new ManualResetEvent(false);
                var runner = new EventRunner(eps, duration, messageSize, done[i]);
                ThreadPool.QueueUserWorkItem(runner.Task);
            }
            WaitHandle.WaitAll(done);
            timer.Stop();
            bool stopped = false;
            while (!stopped)
            {
                try
                {
                    Spammer.Log.Stop(target, timer.ElapsedMilliseconds, eventsLost);
                    stopped = true;
                }
                catch (EventSourceException)
                {
                    ++eventsLost;
                    Thread.Sleep(10);
                }
            }

            if (eventsLost > 0)
            {
                eventsLost = 0;
                return false;
            }
            return true;
        }
Esempio n. 27
0
 public MapFinished(LobbyController lc, EventRunner evr) : base(lc, evr)
 {
 }
Esempio n. 28
0
 public AllUsersReady(LobbyController lc, EventRunner evr) : base(lc, evr)
 {
 }
Esempio n. 29
0
 protected ChatMessageAction(LobbyController lc, EventRunner eventRunner)
 {
     _lc       = lc;
     _evRunner = eventRunner;
 }