private bool ShouldReturnToPool(T pooledObject) { if (PoolPolicy.ErrorOnIncorrectUsage && _Pool.Contains(pooledObject)) { throw new InvalidOperationException("Object already exists in pool. Duplicate add detected."); } return(!IsPoolFull()); }
private static void _SendWatchDogs(string datatype, string[] ids, string userid, string date, string specificemail, bool forceSend = false, Expression <Func <WatchDog, bool> > predicate = null) { HlidacStatu.Util.Consts.Logger.Info("Starting SendWatchDogs type:" + datatype); IEnumerable <int> watchdogs = null; using (Lib.Data.DbEntities db = new DbEntities()) { var data = db.WatchDogs.AsNoTracking() .Where(m => m.StatusId > 0); if (!string.IsNullOrEmpty(userid)) { data = data.Where(m => m.UserId == userid); } if (!string.IsNullOrEmpty(datatype)) { data = data.Where(m => m.dataType == datatype); } if (predicate != null) { data = data.Where(predicate); } if (ids != null) { data = data.Where(m => ids.Contains(m.Id.ToString())); } watchdogs = data .Select(m => m.Id) .ToArray(); } System.Collections.Concurrent.ConcurrentBag <string> alreadySendInfo = new System.Collections.Concurrent.ConcurrentBag <string>(); try { Devmasters.Core.Batch.Manager.DoActionForAll <int, object>(watchdogs, (wdid, obj) => { string log = ""; var mainWatchdog = WatchDog.Load(wdid); var mainWDBs = WatchDog.GetWatchDogBase(mainWatchdog); var notifResult = true; foreach (var wdb in mainWDBs) { HlidacStatu.Util.Consts.Logger.Debug($"Starting watchdog {wdb.ToString()}"); var mainDatatype = wdb.OrigWD.dataType; var user = wdb.OrigWD.User(); if (user == null) //is not confirmed { var uuser = wdb.OrigWD.UnconfirmedUser(); wdb.OrigWD.DisableWDBySystem(DisabledBySystemReasons.NoConfirmedEmail, alreadySendInfo.Contains(uuser.Id) ); alreadySendInfo.Add(uuser.Id); break; //exit for } if (user != null && wdb.OrigWD.StatusId > 0) //check again, some of them could change to disabled { try { notifResult = notifResult | _processIndividualWD(wdb, date, null, specificemail, forceSend); } catch (Exception e) { HlidacStatu.Util.Consts.Logger.Error("WatchDog search error", e); log += "WatchDog search error " + e.ToString(); //throw; } } } if (notifResult && date == null && forceSend == false) { DateTime toDate = WatchDogProcessor.DefaultRoundWatchdogTime(mainWatchdog.Period, DateTime.Now); if (mainWatchdog.LastSearched.HasValue == false || mainWatchdog.LastSearched < toDate) { mainWatchdog.LastSearched = toDate; } mainWatchdog.RunCount++; var latestRec = toDate; if (mainWatchdog.LatestRec.HasValue == false) { mainWatchdog.LatestRec = latestRec; } else if (latestRec > mainWatchdog.LatestRec) { mainWatchdog.LatestRec = latestRec; } mainWatchdog.LastSent = mainWatchdog.LastSearched; mainWatchdog.Save(); } return(new Devmasters.Core.Batch.ActionOutputData() { CancelRunning = false, Log = log }); }, null, HlidacStatu.Util.Consts.outputWriter.OutputWriter, HlidacStatu.Util.Consts.progressWriter.ProgressWriter, System.Diagnostics.Debugger.IsAttached ? false : true); } catch (Exception e) { HlidacStatu.Util.Consts.Logger.Fatal($"Watchdoga DoActionForAll error", e); } }
private async Task ReceiveAsync() { if (_cts != null) { throw new InvalidOperationException(); } _cts = new CancellationTokenSource(); _receivedItemIds = new System.Collections.Concurrent.ConcurrentBag <string>(); while (!_cts.IsCancellationRequested) { var waitTimeMs = 1000 * CommentRetrieveIntervalSec; var accWaitTime = 0; string lastItemId = null; try { var(streamChecker, streamCheckerRaw) = await API.GetStreamChecker(_server, _broadcasterId, lastItemId).ConfigureAwait(false); if (streamChecker.Items != null && streamChecker.Items.Count > 0) { var lastItem = streamChecker.Items[streamChecker.Items.Count - 1]; var lastItemIdBefore = lastItemId == null ? 0 : long.Parse(lastItemId); lastItemId = Math.Max(lastItemIdBefore, long.Parse(lastItem.Id)).ToString(); } MetadataReceived?.Invoke(this, new Metadata { Title = streamChecker.Telop, CurrentViewers = streamChecker.CurrentViewers.ToString(), TotalViewers = streamChecker.TotalViewers.ToString(), IsLive = streamChecker.LiveId.HasValue, LiveId = streamChecker.LiveId, }); foreach (var item in streamChecker.Items) { try { if (_receivedItemIds.Contains(item.Id)) { continue; } _receivedItemIds.Add(item.Id); ItemReceived?.Invoke(this, new InternalItem(item)); } catch (ParseException ex) { _logger.LogException(ex); } catch (Exception ex) { _logger.LogException(ex); } } LiveIdReceived?.Invoke(this, streamChecker.LiveId); } catch (HttpRequestException ex) { _logger.LogException(ex); string message; if (ex.InnerException != null) { message = ex.InnerException.Message; } else { message = ex.Message; } SendInfo(message, InfoType.Debug); } catch (ParseException ex) { _logger.LogException(ex); SendInfo(ex.Message, InfoType.Debug); } catch (TaskCanceledException) { break; } catch (Exception ex) { _logger.LogException(ex); //Infoでエラー内容を通知。ただし同じエラーが連続する場合は通知しない SendInfo(ex.Message, InfoType.Debug); } try { var restWait = waitTimeMs - accWaitTime; if (restWait > 0) { await Task.Delay(restWait, _cts.Token); } } catch (TaskCanceledException) { break; } } _cts = null; }
public TranslationComponents ParseXmlFiles(List <FileInfo> allStringTablePaths) { var lstHeader = new System.Collections.Concurrent.ConcurrentBag <string>(); var allModInfos = new System.Collections.Concurrent.ConcurrentBag <ModInfoContainer>(); var transComp = new TranslationComponents(); Parallel.ForEach(allStringTablePaths, (currentFile) => { var modInfo = new ModInfoContainer { FileInfoStringTable = currentFile, Name = currentFile.Directory.Name }; XDocument xdoc; try { xdoc = XDocument.Load(currentFile.FullName); } catch (XmlException xmlException) { throw new GenericXmlException("", currentFile.FullName, xmlException.Message); } IEnumerable <XElement> keys = xdoc.Descendants().Where(x => x.Name == KEY_NAME); var dicKeyWithTranslations = new Dictionary <string, Dictionary <string, string> >(); // all keys foreach (XElement key in keys) { string currentKeyId = key.Attribute(ID_NAME).Value; var dicTranslations = new Dictionary <string, string>(); // all languages of a key foreach (XElement language in key.Descendants()) { string languageName = language.Name.ToString(); if (dicTranslations.ContainsKey(languageName)) { throw new DuplicateKeyException(languageName, currentFile.FullName, currentKeyId); } dicTranslations.Add(languageName, language.Value); // save all the languages if (lstHeader.Contains(languageName) == false) { lstHeader.Add(languageName); } } if (dicKeyWithTranslations.ContainsKey(currentKeyId)) { throw new DuplicateKeyException(currentKeyId, currentFile.FullName, currentKeyId); } dicKeyWithTranslations.Add(currentKeyId, dicTranslations); } modInfo.Values = dicKeyWithTranslations; allModInfos.Add(modInfo); }); transComp.AllModInfo = allModInfos.OrderBy(mic => mic.Name).ToList(); transComp.Headers = lstHeader.OrderBy(h => h).ToList(); return(transComp); }