Inheritance: System.EventArgs
示例#1
0
 protected void OnWinnerChosen(WinnerChosenEventArgs e)
 {
     WinnerChosen(this, e);
 }
示例#2
0
        public void DrawWinner()
        {
            // Create a random instance with timebased seed
            Random rnd = new Random((int)DateTime.Now.Ticks);

            // Create a copy of the current entry list to work with
            // This also prevents people to enter when rolling is happening
            List<string> workList = new List<string>(entries);

            // Manupilate workList to add subscriber luck

            /*
                    // Not really needed as the forloop will limit this but to increase performance
                    // it won't load subscriber list if subluck is set to 1 (off)
                    if (SubscriberLuck > 1)
                    {
                        List<string> subList = new List<string>();

                        // TODO: Fetch complete subscriber list from Twitch API and add to subList

                        // Create another list with Intersect restult as it is going to enumerate
                        // over this while editing workList to prevent modified execeptions.
                        List<string> crossCheck = new List<string>(workList.Intersect(subList));
                        foreach (string subEntry in crossCheck)
                        {
                            for (int i = 1; i < subscriberLuck; i++)
                            {
                                workList.Insert(rnd.Next(0, workList.Count), subEntry);
                            }
                        }
                    }
            */

            // Roll initial winner and get the Viewer object
            // No need to verify if user exist as it SHOULD exist
            int index = rnd.Next(0, workList.Count);
            Viewer rolledViewer = MainWindow.colDatabase.FirstOrDefault(x =>
                x.UserName == workList[index]);

            // Verify if the winner is eligable, if not remove from
            // the workList and reroll a winner without user interaction
            while (!MeetsRequirements(rolledViewer) || rolledViewer == null)
            {
                try
                {
                    // Remove failed winner from workList
                    workList.RemoveAll(x => x == rolledViewer.UserName);

                    // Reroll winner
                    index = rnd.Next(0, workList.Count);
                    rolledViewer = MainWindow.colDatabase.FirstOrDefault(x =>
                        x.UserName == workList[index]);
                }
                catch (Exception)
                {
                }
            }

            // We finally have a winner!
            winners.Add(rolledViewer.UserName);
            winner = rolledViewer;

            WinnerChosenEventArgs args = new WinnerChosenEventArgs(rolledViewer);
            OnWinnerChosen(args);
        }