/// <summary>
        /// Initialize the cache by performing the initial data population and setting up the scheduler.
        /// </summary>
        public static void Initialize()
        {
            if (startHour < 0 || startHour > 23)
            {
                throw new ConfigurationErrorsException("cache:RefreshHourOfDay must be between 0 and 23.");
            }

            if (interval < 1)
            {
                throw new ConfigurationErrorsException("cache:RefreshIntervalHours must be greater than 1.");
            }

            // Performs initial data population
            ContactMap.Refresh();

            // Setting up the scheduler
            IScheduler scheduler = Quartz.Impl.StdSchedulerFactory.GetDefaultScheduler();

            scheduler.Start();

            IJobDetail job = JobBuilder.Create <ContactMapRefreshJob>().Build();

            ITrigger trigger = TriggerBuilder.Create()
                               .WithDailyTimeIntervalSchedule
                                   (s =>
                                   s.WithIntervalInHours(interval)
                                   .OnEveryDay()
                                   .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(startHour, 0))
                                   )
                               .Build();

            scheduler.ScheduleJob(job, trigger);
        }
        /// <summary>
        /// Refresh the cache.
        /// </summary>
        public static void Refresh()
        {
            List <Message> messagesList = new List <Message>();

            // The new data
            Dictionary <string, int> userComboPlusScore      = new Dictionary <string, int>();
            Dictionary <string, List <UserScore> > wkwScores = new Dictionary <string, List <UserScore> >();

            messagesList = ContactMap.GetMessages();
            if (messagesList == null || messagesList.Count == 0)
            {
                return;
            }

            userComboPlusScore = ContactMap.ComputeUserComboScore(messagesList);
            wkwScores          = ContactMap.WhoKnowsWhoScoreMap(userComboPlusScore);

            if (wkwScores.Count() == 0)
            {
                // don't update if there is nothing
                return;
            }

            // Commit the new data as the official copy.
            myLock.Wait();

            try
            {
                theWkwScoreMap = wkwScores;
                samples        = wkwScores.Keys.ToList();
                lastLoadTime   = DateTimeOffset.UtcNow;
            }
            finally
            {
                myLock.Release();
            }
        }
 /// <summary>
 /// Callback for scheduled execution.
 /// </summary>
 /// <param name="context">The execution context</param>
 public void Execute(IJobExecutionContext context)
 {
     ContactMap.Refresh();
 }