Exemple #1
0
        private static void SpeedUP(Feed feed)
        {
            TazehaContext Context = new TazehaContext();

            feed.LastUpdateDateTime = DateTime.Now;
            if (feed.UpdateSpeed > 5)
            {
                //------feed ro saritar pooyesh kon(TAghire level)----
                var newdurations = Context.UpdateDurations.FromHttpCache <UpdateDuration>().Where <UpdateDuration>(x => x.PriorityLevel < feed.UpdateDuration.PriorityLevel);
                if (newdurations.Count() == 0)
                {
                    //-------agar be kamtarin baze updater resid---1Hour-----
                    feed.UpdateSpeed = 0;
                }
                else
                {
                    UpdateDuration newduration = newdurations.OrderByDescending(x => x.PriorityLevel).First();
                    feed.Id          = newduration.Id;
                    feed.UpdateSpeed = 0;
                }
            }
            else
            {
                feed.UpdateSpeed = feed.UpdateSpeed.HasValue ? feed.UpdateSpeed + 1 : 1;
            }
        }
Exemple #2
0
        public void SpeedUP(Feed feed)
        {
            feed.LastUpdateDateTime = DateTime.Now;
            if (feed.UpdateSpeed > 5)
            {
                //------feed ro saritar pooyesh kon(TAghire level)----
                var newdurations = _dbContext.Set <UpdateDuration>().Where(x => x.PriorityLevel < feed.UpdateDuration.PriorityLevel);
                if (!newdurations.Any())
                {
                    //-------agar be kamtarin baze updater resid---1Hour-----
                    feed.UpdateSpeed = 0;
                }
                else
                {
                    UpdateDuration newduration = newdurations.OrderByDescending(x => x.PriorityLevel).First();
                    feed.UpdateDurationId = newduration.Id;
                    feed.UpdateSpeed      = -4;
                    GeneralLogs.WriteLogInDB("Change Duration(+) of Feed:" + feed.Id + " Link:" + feed.Link + " NewDuration:" + newduration.Id);
                }
            }
            else
            {
                feed.UpdateSpeed = feed.UpdateSpeed + 1;
            }

            GeneralLogs.WriteLog("SpeedUp Feed:" + feed.Id + " Link:" + feed.Link, TypeOfLog.Info);
        }
Exemple #3
0
        public void UpdateFeedsPerDuration(UpdateDuration duration)
        {
            var delaytime  = TimeSpan.Parse(duration.DelayTime);
            var Partnumber = delaytime.Hours * 60 / Config.GetTimeInterval();//20 min intervall
            var TopCount   = (duration.FeedsCount / Partnumber) != 0 ? (duration.FeedsCount / Partnumber) : (duration.FeedsCount % Partnumber);

            var feeds = FeedBiz.GetList().Where(x => x.UpdateDurationId.Value == duration.Id &&
                                                ((int)x.Deleted < 1 || (int)x.Deleted > 10)).OrderBy(feed => feed.Id).Skip(duration.StartIndex).Take(TopCount).ToList();

            if (TopCount == 0)
            {
                return;
            }

            GeneralLogs.WriteLog("Start updating duration " + duration.Code + " Start at:" + duration.StartIndex, TypeOfLog.Start, typeof(FeedUpdater));

            foreach (var feed in feeds)
            {
                GeneralLogs.WriteLog("Feed updating. Id:" + feed.Id, TypeOfLog.Start, typeof(FeedUpdater));
                UpdatingFeed(feed);
            }

            duration.FeedsCount = FeedBiz.GetList().Where(x => x.UpdateDurationId.Value == duration.Id && ((int)x.Deleted < 1 || (int)x.Deleted > 10)).Count();
            duration.StartIndex = (duration.StartIndex + TopCount) >= duration.FeedsCount ? 0 : (duration.StartIndex + TopCount);
            var res = DurationBiz.Edit(duration);

            if (res.Status)
            {
                GeneralLogs.WriteLog("Duration updated. Id:" + duration.Id + " Start Index: " + duration.StartIndex, TypeOfLog.OK, typeof(FeedUpdater));
            }
        }
Exemple #4
0
 private void AfterOneCall(StartUp inputParams, UpdateDuration duration)
 {
     #region NoIsParting
     TazehaContext context = new TazehaContext();
     int           ItemCountPriorityCode = context.Feeds.Where <Feed>(x => x.UpdateDurationId.Value == duration.Id && x.Site.IsBlog == inputParams.IsBlog && (x.Deleted == 0 || (int)x.Deleted > 10)).Count();
     int           LastCount             = context.Feeds.Where <Feed>(x => x.UpdateDurationId.Value == duration.Id && x.Site.IsBlog == inputParams.IsBlog && (x.Deleted == 0 || (int)x.Deleted > 10)).OrderBy(x => x.Id).Skip(inputParams.StartIndex).Take <Feed>(inputParams.TopCount).Count();
     int           NextCount             = context.Feeds.Where <Feed>(x => x.UpdateDurationId.Value == duration.Id && x.Site.IsBlog == inputParams.IsBlog && (x.Deleted == 0 || (int)x.Deleted > 10)).OrderBy(x => x.Id).Skip(inputParams.StartIndex + inputParams.TopCount).Take <Feed>(inputParams.TopCount).Count();
     if (NextCount > 0)
     {
         var LastUpdateIndex = context.ProjectSetups.SingleOrDefault(x => x.Title == "LastUpdat:" + inputParams.StartUpConfig);
         if (LastUpdateIndex != null)
         {
             //LastUpdateIndex.Value = (InputParams.StartIndex + InputParams.TopCount + InputParams.TopCount).ToString();
             LastUpdateIndex.Value = (inputParams.StartIndex + inputParams.TopCount).ToString();
             context.SaveChanges();
         }
         else
         {
             //entiti.ProjectSetup.AddObject(new ProjectSetup { Title = "LastUpdat:" + InputParams.StartUpConfig, Value = (InputParams.StartIndex + InputParams.TopCount + InputParams.TopCount).ToString(), Meaning = "last index updater of feed of priority" });
             context.ProjectSetups.Add(new ProjectSetup {
                 Title = "LastUpdat:" + inputParams.StartUpConfig, Value = (inputParams.StartIndex + inputParams.TopCount).ToString(), Meaning = "last index updater of feed of priority"
             });
             context.SaveChanges();
         }
         inputParams.StartIndex += inputParams.TopCount;
         if (!duration.IsParting.HasValue || !duration.IsParting.Value)
         {
             StartByDuration(inputParams, null, 0);
         }
     }
     else
     {
         //-----------------------When all items updated------------------
         if (duration != null)
         {
             var LastUpdateIndex = context.ProjectSetups.SingleOrDefault(x => x.Title == "LastUpdat:" + inputParams.StartUpConfig);
             if (LastUpdateIndex != null)
             {
                 LastUpdateIndex.Value = "0";
                 context.SaveChanges();
             }
             else
             {
                 context.ProjectSetups.Add(new ProjectSetup {
                     Title = "LastUpdat:" + inputParams.StartUpConfig, Value = "0", Meaning = "last index updater of feed of priority"
                 });
                 context.SaveChanges();
             }
             GeneralLogs.WriteLogInDB(">OK UpdaterSleeping... duration:" + duration.Code);
             ///for test task with windows----
         }
     }
     #endregion
 }
Exemple #5
0
        private static void SpeedDOWN(Feed feed)
        {
            TazehaContext Context = new TazehaContext();

            feed.LastUpdateDateTime = DateTime.Now;
            //-----feed hanooz update nashode ast------------
            if (feed.UpdateSpeed < -5)
            {
                UpdateDuration newduration = Context.UpdateDurations.FromHttpCache <UpdateDuration>().Where <UpdateDuration>(x => x.PriorityLevel > feed.UpdateDuration.PriorityLevel).OrderBy(x => x.PriorityLevel).First();
                feed.Id          = newduration.Id;
                feed.UpdateSpeed = 4;
            }
            else
            {
                feed.UpdateSpeed = feed.UpdateSpeed.HasValue ? feed.UpdateSpeed - 1 : -1;
            }
        }
Exemple #6
0
        public List <FeedContract> getLatestFeedsByDuration(string DurationCode, int MaxSize, int IsBlog)
        {
            UpdateDuration duration = UpdateDurationManager.getLast(DurationCode, MaxSize);
            TazehaContext  context  = new TazehaContext();

            GeneralLogs.WriteLog("getLatestFeedsByDuration :" + DurationCode + " StartIndex:" + duration.StartIndex, TypeOfLog.Info);
            List <Feed> arr = new List <Feed>();

            arr = context.Feeds.Where <Feed>(x => x.UpdateDurationId.Value == duration.UpdateDurationId &&
                                             (x.Site.IsBlog == IsBlog || IsBlog == 2) &&
                                             (x.Deleted == 0 || x.Deleted > 10)).OrderBy(x => x.FeedId).Skip(duration.StartIndex).Take <Feed>(MaxSize).ToList();

            var res = arr.ConvertToFeedContract().ToList();

            //GeneralLogs.WriteLogInDB(string.Format("Return {0} Feed to remote client,start index {1}", res.Count(), duration.StartIndex), TypeOfLog.Info);
            //System.Web.HttpRuntime.Cache.AddToChache_Hours("Duration_" + DurationCode, duration.StartIndex, 12);
            return(res);
        }
Exemple #7
0
 public void SpeedDOWN(Feed feed)
 {
     feed.LastUpdateDateTime = DateTime.Now;
     //-----feed hanooz update nashode ast------------
     if (feed.UpdateSpeed < -5)
     {
         UpdateDuration newduration = _dbContext.Set <UpdateDuration>().Where(x => x.PriorityLevel > feed.UpdateDuration.PriorityLevel)
                                      .OrderBy(x => x.PriorityLevel).First();
         feed.UpdateDurationId = newduration.Id;
         feed.UpdateSpeed      = 4;
         Mn.NewsCms.Common.EventsLog.GeneralLogs.WriteLogInDB("Change Duration(-) of Feed:" + feed.Id + " Link:" + feed.Link + " NewDuration:" + newduration.Id);
     }
     else
     {
         feed.UpdateSpeed = feed.UpdateSpeed - 1;
     }
     Mn.NewsCms.Common.EventsLog.GeneralLogs.WriteLog("SpeedDown Feed:" + feed.Id + " Link:" + feed.Link, TypeOfLog.Info);
 }
Exemple #8
0
 public override bool StartByDuration(StartUp start, UpdateDuration duration, int counter)
 {
     throw new NotImplementedException();
 }
Exemple #9
0
 public abstract bool StartByDuration(StartUp start, UpdateDuration duration, int counter);
Exemple #10
0
        public override bool StartByDuration(StartUp inputParams, UpdateDuration duration, int counter)
        {
            try
            {
                var context = new TazehaContext();
                GeneralLogs.WriteLogInDB("BaseUpdaterServer StartUptare PriorityCode:" + inputParams.StartUpConfig + " StartIndex:" + inputParams.StartIndex);
                IEnumerable <Feed> arr = null;
                //IEnumerable<Feed> arrLocaly = null;
                if (duration == null)
                {
                    duration = context.UpdateDurations.FromHttpCache <UpdateDuration>().SingleOrDefault(x => x.Code == inputParams.StartUpConfig);
                }
                if (duration.IsLocalyUpdate == true && IsLocaly == true)
                {
                    arr = context.Feeds.Where <Feed>(x => x.UpdateDurationId.Value == duration.Id &&
                                                     //(x.Site.IsBlog == inputParams.IsBlog || inputParams.IsBlog == 2) &&
                                                     (x.Deleted == 0 || (int)x.Deleted > 10)).OrderBy(x => x.Id)
                          .Skip(inputParams.StartIndex)
                          .Take <Feed>(inputParams.TopCount).ToList();
                }
                else
                {
                    if (counter == 0 && FeedsCandidate.Count > Config.GetConfig <int>("MaxFeedCountAsService") * 2)
                    {
                        return(false);
                    }

                    arr = context.Feeds.Where <Feed>(x => x.UpdateDurationId.Value == duration.Id &&
                                                     x.Site.IsBlog == inputParams.IsBlog &&
                                                     (x.Deleted == 0 || (int)x.Deleted > 10)).OrderBy(x => x.Id).Skip(inputParams.StartIndex).Take <Feed>(inputParams.TopCount).ToList();
                }



                #region for sync client & server
                //in shart baraye inke server o updater ba ham hamahang shavand,va list alaki tond tond por nashavad
                //int sleepConter = 0;
                //while ((FeedsCandidate.Count > Config.getConfig<int>("MaxFeedCountAsService") * 2 ||
                //    (FeedsCandidateLocaly.Count > Config.getConfig<int>("MaxFeedCountAsService") * 2)) &&
                //    arr.Count() > Config.getConfig<int>("MaxFeedCountAsService") * 2)
                //{
                //    if (++sleepConter > 5)
                //    {
                //        PokeClients();
                //        sleepConter = 0;
                //    }
                //    System.Threading.Thread.Sleep(1000 * 60 * 2);//2 min;
                //    GeneralLogs.WriteLog("Thread.Sleep 2 min(Feed Buffer OverFlow) [AsService]", TypeOfLog.Info);
                //}
                #endregion

                if (arr.Count() > 0 && duration.IsLocalyUpdate == true && IsLocaly == true)
                {
                    FeedsCandidateLocaly.AddRange(arr.ToList().ConvertToFeedContract());
                }
                else if (arr.Count() > 0)
                {
                    FeedsCandidate.AddRange(arr.ToList().ConvertToFeedContract());
                }

                GeneralLogs.WriteLog(string.Format("Add {0} Feed to Buffer.", arr.Count()), TypeOfLog.Info);
                //if (FeedsCandidate.Count > Config.getConfig<int>("MaxFeedCountAsService") ||
                //    FeedsCandidateLocaly.Count > Config.getConfig<int>("MaxFeedCountAsService"))
                //    PokeClients();
                //System.Threading.Thread.Sleep(1000 * 60);
                #region AfterFor
                //if (!duration.IsParting.Value)
                //    AfterOneCall(inputParams, duration);
                #endregion

                return(true);
            }
            catch (Exception ex)
            {
                GeneralLogs.WriteLogInDB("StartByDuration " + ex.Message, TypeOfLog.Error);
                return(false);
            }
        }
Exemple #11
0
 public UpdaterByDuration(UpdateDuration BaseDuration)
 {
     duration = BaseDuration;
 }