public static List <FeedContract> getCandidateFeeds(int MaxSize, bool?IsLocaly) { if (IsLocaly == true) { lock (FeedsCandidateLocaly) { var ret = FeedsCandidateLocaly.Take(MaxSize).ToArray(); if (FeedsCandidateLocaly.Count > MaxSize) { FeedsCandidateLocaly.RemoveRange(0, MaxSize); } else if (FeedsCandidateLocaly.Count > 0) { FeedsCandidateLocaly.Clear(); } return(ret.ToList()); } } else { lock (FeedsCandidate) { var ret = FeedsCandidate.Take(MaxSize).ToArray(); if (FeedsCandidate.Count > MaxSize) { FeedsCandidate.RemoveRange(0, MaxSize); } else if (FeedsCandidate.Count > 0) { FeedsCandidate.Clear(); } return(ret.ToList()); } } }
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); } }