Exemple #1
0
 public void Execute(JobExecutionContext context)
 {
     if (!_lock.TryEnter())
     {
         return;
     }
     try
     {
         LiveChannelCache.Instance.Init();
         var source  = LiveListCache.Instance.Dictionary.Values.Where(l => l.HiddenFlag == 0).Select(l => l.Main.ChannelID).ToPerfectList();
         var compare = LiveChannelCache.Instance.Items.Select(l => l.ChannelID).ToPerfectList();
         var hiddens = source.Except(compare).ToPerfectList();
         var shows   = compare.Except(source).ToPerfectList();
         if (hiddens.Count > 0)
         {
             if (hiddens.Count < AppSettingCache.LiveHiddenMaxCount)
             {
                 foreach (var hidden in hiddens)
                 {
                     if (LiveListCache.Instance.Dictionary.ContainsKey(hidden))
                     {
                         var video = LiveListCache.Instance.Dictionary[hidden];
                         video.HiddenFlag = 1;
                         LiveEpgIndex.DeleteVideo(video, LiveEpgLuceneNet.Instance.IndexDic);
                         _logger.Info(string.Format("频道{0}已下线", hidden));
                     }
                 }
             }
             else
             {
                 _logger.Info(string.Format("下线个数超过最大阀值,当前下线个数为{0}", hiddens.Count));
             }
         }
         if (shows.Count > 0)
         {
             foreach (var show in shows)
             {
                 if (LiveListCache.Instance.Dictionary.ContainsKey(show))
                 {
                     var video = LiveListCache.Instance.Dictionary[show];
                     video.HiddenFlag = 0;
                     LiveEpgIndex.InsertVideo(video, LiveEpgLuceneNet.Instance.IndexDic);
                     _logger.Info(string.Format("频道{0}已上线", show));
                 }
             }
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
     }
     finally
     {
         _lock.Exit();
     }
 }