Beispiel #1
0
        static async Task Main()
        {
            await Casino.Bootstrap().ConfigureAwait(false);

            Casino.Instance.RunActualTest();
            Console.ReadLine();
        }
        public void RollTheDice()
        {
            Result = new int[NumberSize];

            /*var luckManipulation = _collector.OrderBy(x => x.Value).Select(x => x.Key).ToArray();
             * for (int i = 0; i < NumberSize; i++)
             * {
             *  int num;
             *  do
             *  {
             *      num = luckManipulation[Rand.Next(0, PoolSize / 2)];
             *  } while (Result.Contains(num));
             *
             *  Result[i] = num;
             * }*/
            Result = Casino.RandomSequence();
            Status = LotteryStatus.Over;
        }
Beispiel #3
0
        //static Casino()
        //{
        //    var url = Local ? "http://localhost:8080" : "http://10.0.0.69:8090";
        //    Instance = new Casino(url, "CorruptedCasino", "Karmel");
        //    Instance.Initialize();
        //    Name = Store.Database;
        //}

        public Casino(string orchestratorUrl, string testName, int round) : base(orchestratorUrl, testName, "Karmel", round)
        {
            Instance = this;
        }
        public static async Task <Lottery> CreateLottery()
        {
            var lottery = new Lottery($"Lottery/{DateTime.UtcNow}/" + Guid.NewGuid())
            {
                DueTime = DateTime.UtcNow.AddMinutes(1),
                Status  = LotteryStatus.Open
            };

            using (var session = Casino.GetSessionAsync)
            {
                session.Advanced.WaitForReplicationAfterSaveChanges(timeout: TimeSpan.FromSeconds(180), replicas: Casino.ReplicaCount());
                await session.StoreAsync(lottery, lottery.Id).ConfigureAwait(false);

                await session.SaveChangesAsync().ConfigureAwait(false);
            }

            return(lottery);
        }
        public async Task Complete()
        {
            using (var session = Casino.GetSessionAsync)
            {
                session.Advanced.WaitForReplicationAfterSaveChanges(TimeSpan.FromSeconds(180), replicas: Casino.ReplicaCount());

                var lottery = await session.LoadAsync <Lottery>(Id).ConfigureAwait(false);

                lottery.Result = Result;
                lottery.Status = Status;
                await session.SaveChangesAsync().ConfigureAwait(false);
            }
        }
        public async Task FinalizeBets()
        {
            using (var session = Casino.GetSessionAsync)
            {
                // ensures that no more bets accepted after this session is committed
                session.Advanced.WaitForReplicationAfterSaveChanges(TimeSpan.FromSeconds(180), replicas: Casino.ReplicaCount());

                var lottery = await session.LoadAsync <Lottery>(Id).ConfigureAwait(false);

                lottery.Status = LotteryStatus.PendingResults;

                await session.StoreAsync(new Bet
                {
                    LotteryId = Id,
                    BetStatus = Bet.Status.Closed
                }, $"close/{Id}").ConfigureAwait(false);

                await session.SaveChangesAsync().ConfigureAwait(false);
            }

            if (_collecting.WaitOne(TimeSpan.FromSeconds(60)) == false)
            {
                throw new TimeoutException();
            }
        }