public override void ExecuteCommand() { TableErrorLog log = new TableErrorLog(string.Format(ElmahAccountCredentials)); List<ErrorLogEntry> entities = new List<ErrorLogEntry>(); log.GetErrors(0, 500, entities); //retrieve n * LastNHours errors assuming a max of 500 errors per hour. int count = entities.Where(entity => entity.Error.Time.ToUniversalTime() > DateTime.UtcNow.AddHours(-1) && entity.Error.Time.ToUniversalTime() < DateTime.UtcNow).ToList().Count; ReportHelpers.AppendDatatoBlob(StorageAccount, "ErrorRate" + string.Format("{0:MMdd}", DateTime.Now) + ".json", new Tuple<string, string>(String.Format("{0:HH:mm}", DateTime.Now), count.ToString()), 50, ContainerName); }
public List<ElmahError> GetElmahError(DateTime start, DateTime end) { if (StorageAccount == null) StorageAccount = CloudStorageAccount.Parse(ConnectionString); List<string> nonCriticalErrorDictionary = new JavaScriptSerializer().Deserialize<List<string>>(Load(StorageAccount, "Configuration.ElmahNonCriticalErrors.json", ContainerName)); TableErrorLog log = new TableErrorLog(string.Format(ElmahAccountCredentials)); List<ErrorLogEntry> entities = new List<ErrorLogEntry>(); int lasthours = DateTime.Now.Subtract(start).Hours + 1; log.GetErrors(0, 500 * lasthours, entities); //retrieve n * LastNHours errors assuming a max of 500 errors per hour. List<ElmahError> listOfErrors = new List<ElmahError>(); //Get the error from Last N hours. if (entities.Any(entity => entity.Error.Time.ToUniversalTime() > start.ToUniversalTime() && entity.Error.Time.ToUniversalTime() < end.ToUniversalTime())) { entities = entities.Where(entity => entity.Error.Time.ToUniversalTime() > start.ToUniversalTime() && entity.Error.Time.ToUniversalTime() < end.ToUniversalTime()).ToList(); var elmahGroups = entities.GroupBy(item => item.Error.Message); //Group the error based on exception and send alerts if critical errors exceed the thresold values. foreach (IGrouping<string, ErrorLogEntry> errorGroups in elmahGroups) { Console.WriteLine(errorGroups.Key.ToString() + " " + errorGroups.Count()); int severity = 0; if (nonCriticalErrorDictionary.Any(item => errorGroups.Key.ToString().Contains(item))) { severity = 1; //sev 1 is low pri and sev 0 is high pri. } string link = "https://www.nuget.org/Admin/Errors.axd/detail?id={0}"; if (ContainerName.Contains("qa")) { link = "https://int.nugettest.org/Admin/Errors.axd/detail?id={0}"; } //for severity, assume all refresh error, severity = 0 listOfErrors.Add(new ElmahError(errorGroups.Key.ToString(), errorGroups.Count(), errorGroups.Min(item => item.Error.Time.ToLocalTime()), errorGroups.Max(item => item.Error.Time.ToLocalTime()), string.Format(link, errorGroups.First().Id), errorGroups.First().Error.Detail, severity)); } } return listOfErrors; }
private void MigrateCredentials(User user, List<Credential> creds, string password) { var toRemove = creds.Where(c => !String.Equals( c.Type, CredentialTypes.Password.Pbkdf2, StringComparison.OrdinalIgnoreCase)) .ToList(); // Remove any non PBKDF2 credentials foreach (var cred in toRemove) { creds.Remove(cred); user.Credentials.Remove(cred); CredentialRepository.DeleteOnCommit(cred); } // Now add one if there are no credentials left if (creds.Count == 0) { user.Credentials.Add(CredentialBuilder.CreatePbkdf2Password(password)); } // Save changes, if any (even though we only commit one repo, both will get saved because they just wrap entities context) UserRepository.CommitChanges(); }