public bool VerifyPoisonMessage(string poisonId, out int crashCount) { if (string.IsNullOrEmpty(poisonId)) { throw new ArgumentNullException("poisonId"); } if (!this.Enabled || this.storeDriverPoisonInfo.Count == 0) { crashCount = 0; return(false); } CrashProperties crashProperties = null; if (this.storeDriverPoisonInfo.TryGetValue(poisonId, out crashProperties)) { if (this.IsExpired(crashProperties)) { this.MarkPoisonMessageHandled(poisonId); } else if (this.IsMessagePoison(crashProperties)) { crashCount = (int)crashProperties.CrashCount; return(true); } } crashCount = 0; return(false); }
public virtual void SavePoisonContext() { if (!this.Enabled) { return; } if (PoisonHandler <TPoisonHandlerContext> .Context == null) { TraceHelper.GeneralTracer.TracePass(TraceHelper.MessageProbeActivityId, 0L, "No poison context information stored on the crashing thread. Exiting..."); return; } using (RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(this.storeDriverPoisonMsgLocation)) { TPoisonHandlerContext tpoisonHandlerContext = PoisonHandler <TPoisonHandlerContext> .Context; string text = tpoisonHandlerContext.ToString(); int num = 1; if (registryKey.GetValue(text) != null) { if (registryKey.GetValueKind(text) != RegistryValueKind.MultiString) { registryKey.DeleteValue(text, false); } else { string[] array = (string[])registryKey.GetValue(text); if (array == null || array.Length != 2) { registryKey.DeleteValue(text, false); } else if (!int.TryParse(array[0], out num)) { registryKey.DeleteValue(text, false); } else { num++; } } } else { this.DeleteOldestPoisonEntryIfNecessary(registryKey); } CrashProperties crashProperties = new CrashProperties((double)num, DateTime.UtcNow); registryKey.SetValue(text, new string[] { Convert.ToString(crashProperties.CrashCount), crashProperties.LastCrashTime.ToString("u") }, RegistryValueKind.MultiString); this.storeDriverPoisonInfo[text] = crashProperties; } }
protected virtual bool IsExpired(CrashProperties crashProperties) { if (crashProperties == null) { return(false); } try { if (DateTime.UtcNow > crashProperties.LastCrashTime + this.poisonEntryExpiryWindow) { return(true); } } catch (ArgumentOutOfRangeException) { return(true); } return(false); }
public virtual void Load() { using (RegistryKey registryKey = Registry.LocalMachine.CreateSubKey(this.storeDriverPoisonMsgLocation)) { foreach (string text in registryKey.GetValueNames()) { bool flag = registryKey.GetValueKind(text) != RegistryValueKind.MultiString; string[] array = (string[])registryKey.GetValue(text); if (array.Length != 2) { flag = true; } int value; DateTime lastCrashTime; if (flag) { TraceHelper.GeneralTracer.TraceFail <string, RegistryKey>(TraceHelper.MessageProbeActivityId, 0L, "Invalid value {0} in {1} registry key. Deleting it.", text, registryKey); registryKey.DeleteValue(text, false); } else if (!int.TryParse(array[0], out value) || !DateTime.TryParseExact(array[1], "u", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.AllowLeadingWhite | DateTimeStyles.AllowTrailingWhite | DateTimeStyles.AllowInnerWhite | DateTimeStyles.RoundtripKind, out lastCrashTime)) { TraceHelper.GeneralTracer.TraceFail <string, RegistryKey>(TraceHelper.MessageProbeActivityId, 0L, "Invalid value {0} in {1} registry key. Deleting it.", text, registryKey); registryKey.DeleteValue(text, false); } else { CrashProperties crashProperties = new CrashProperties(Convert.ToDouble(value), lastCrashTime); if (!this.IsExpired(crashProperties)) { this.storeDriverPoisonInfo[text] = crashProperties; } else { registryKey.DeleteValue(text, false); } } } } this.loaded = true; }
protected override bool IsMessagePoison(CrashProperties crashProperties) { return(!this.IsExpired(crashProperties) && base.IsMessagePoison(crashProperties)); }
protected virtual bool IsMessagePoison(CrashProperties crashProperties) { return(crashProperties.CrashCount >= (double)this.PoisonThreshold); }