Example #1
0
        public void Load()
        {
            if (!File.Exists("./lottery"))
            {
                return;
            }

            IFormatter formatter = new BinaryFormatter();
            FileStream fs        = new FileStream("./lottery", FileMode.Open);

            CurrentLottery = (LotteryState)formatter.Deserialize(fs);

            fs.Close();
        }
Example #2
0
        public LotteryResult End()
        {
            if (CurrentLottery == null)
            {
                return(null);
            }

            var result = new LotteryResult(CurrentLottery.Draw(), CurrentLottery.Stake);

            Save();

            if (!Directory.Exists("./lotteries"))
            {
                Directory.CreateDirectory("./lotteries");
            }

            File.Move("./lottery", "./lotteries/lottery-" + DateTime.Now.ToString("yyyy-dd-M--HH-mm-ss"));

            CurrentLottery = null;

            return(result);
        }
Example #3
0
        //public void Loop()
        //{
        //    while(true)
        //    {
        //        try
        //        {
        //            while (CurrentLottery == null)
        //                Thread.Sleep(1000);

        //            var span = (DateTime.Now - CurrentLottery.End);
        //            Thread.Sleep(span);

        //        }
        //        catch
        //        { }
        //    }
        //}

        public void Start(long stake, TimeSpan span)
        {
            var lottery = new LotteryState(DateTime.Now + span, stake);

            CurrentLottery = lottery;
        }