コード例 #1
0
        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;
        }
コード例 #2
0
        public static IDisposable All(params IDisposable[] tokens)
        {
            return new DisposableAction(() =>
            {
                var exceptions = new List<Exception>();

                foreach (var token in tokens)
                {
                    try
                    {
                        token.Dispose();
                    }
                    catch (Exception ex)
                    {
                        exceptions.Add(ex);
                    }
                }

                if (exceptions.Any())
                {
                    throw new AggregateException(exceptions);
                }
            });
        }
コード例 #3
0
        public virtual ActionResult ListPackages(string q, string sortOrder = null, int page = 1, bool prerelease = true, bool moderatorQueue = false)
        {
            if (page < 1) page = 1;

            IQueryable<Package> packageVersions = packageSvc.GetPackagesForListing(prerelease);
            IEnumerable<Package> packagesToShow = new List<Package>();

            if (moderatorQueue)
            {
                var unknownStatus = PackageStatusType.Unknown.GetDescriptionOrValue();

                //This is going to be fun. Unknown status ones would be listed, but sometimes a few might slip through the cracks if a maintainer unlists a package.
                // A user can just email us to catch those though.
                packageVersions = packageVersions.Where(p => !p.IsPrerelease).Where(p => p.StatusForDatabase == unknownStatus || p.StatusForDatabase == null);
            }

            q = (q ?? "").Trim();

            if (String.IsNullOrEmpty(sortOrder))
            {
                // Determine the default sort order. If no query string is specified, then the sortOrder is DownloadCount
                // If we are searching for something, sort by relevance.
                sortOrder = q.IsEmpty() ? Constants.PopularitySortOrder : Constants.RelevanceSortOrder;
            }

            int totalHits = 0;
            int updatedPackagesCount = 0;
            int unreviewedPackagesCount = 0;
            int waitingPackagesCount = 0;
            var searchFilter = GetSearchFilter(q, sortOrder, page, prerelease);

            if (moderatorQueue)
            {
                var submittedPackages = packageSvc.GetSubmittedPackages().ToList();

                var updatedStatus = PackageSubmittedStatusType.Updated.ToString();
                var readyStatus = PackageSubmittedStatusType.Ready.ToString();
                var waitingStatus = PackageSubmittedStatusType.Waiting.ToString();

                //var resubmittedPackages = submittedPackages.Where(p => p.ReviewedDate.HasValue && p.Published > p.ReviewedDate).OrderBy(p => p.Published).ToList();
                var resubmittedPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == updatedStatus).OrderBy(p => p.Published).ToList();
                updatedPackagesCount = resubmittedPackages.Count;

                var unreviewedPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == readyStatus || p.SubmittedStatusForDatabase == null).OrderBy(p => p.Published).ToList();
                unreviewedPackagesCount = unreviewedPackages.Count;

                //var waitingForMaintainerPackages = submittedPackages.Where(p => p.ReviewedDate >= p.Published).OrderByDescending(p => p.ReviewedDate).ToList();
                var waitingForMaintainerPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == waitingStatus).OrderByDescending(p => p.ReviewedDate).ToList();
                waitingPackagesCount = waitingForMaintainerPackages.Count;

                packagesToShow = resubmittedPackages.Union(unreviewedPackages).Union(waitingForMaintainerPackages);

                totalHits = packagesToShow.Count() + packageVersions.Count();

                if ((searchFilter.Skip + searchFilter.Take) >= packagesToShow.Count()) packagesToShow = packagesToShow.Union(packageVersions.OrderByDescending(pv => pv.DownloadCount));

                packagesToShow = packagesToShow.Skip(searchFilter.Skip).Take(searchFilter.Take);
            } else packagesToShow = searchSvc.Search(packageVersions, searchFilter, out totalHits).ToList();

            if (page == 1 && !packagesToShow.Any())
            {
                // In the event the index wasn't updated, we may get an incorrect count. 
                totalHits = 0;
            }

            var viewModel = new PackageListViewModel(
                packagesToShow, q, sortOrder, totalHits, page - 1, Constants.DefaultPackageListPageSize, Url, prerelease, moderatorQueue, updatedPackagesCount, unreviewedPackagesCount, waitingPackagesCount);

            ViewBag.SearchTerm = q;

            return View("~/Views/Packages/ListPackages.cshtml", viewModel);
        }
コード例 #4
0
        public virtual ActionResult ListPackages(string q, string sortOrder = null, int page = 1, bool prerelease = false, bool moderatorQueue = false)
        {
            if (page < 1) page = 1;
            q = (q ?? string.Empty).Trim();

            IQueryable<Package> packageVersions = packageSvc.GetPackagesForListing(prerelease);
            IEnumerable<Package> packagesToShow = new List<Package>();

            if (moderatorQueue)
            {
                var unknownStatus = PackageStatusType.Unknown.GetDescriptionOrValue();

                //This is going to be fun. Unknown status ones would be listed, but sometimes a few might slip through the cracks if a maintainer unlists a package.
                // A user can just email us to catch those though.
                packageVersions = packageVersions.Where(p => !p.IsPrerelease).Where(p => p.StatusForDatabase == unknownStatus || p.StatusForDatabase == null);
            }

            q = (q ?? "").Trim();

            if (String.IsNullOrEmpty(sortOrder))
            {
                // Determine the default sort order. If no query string is specified, then the sortOrder is DownloadCount
                // If we are searching for something, sort by relevance.
                sortOrder = q.IsEmpty() ? Constants.PopularitySortOrder : Constants.RelevanceSortOrder;
            }

            int totalHits = 0;
            int updatedPackagesCount = 0;
            int respondedPackagesCount = 0;
            int unreviewedPackagesCount = 0;
            int waitingPackagesCount = 0;
            var searchFilter = GetSearchFilter(q, sortOrder, page, prerelease);

            if (moderatorQueue)
            {
                var submittedPackages = packageSvc.GetSubmittedPackages().ToList();

                var updatedStatus = PackageSubmittedStatusType.Updated.ToString();
                var respondedStatus = PackageSubmittedStatusType.Responded.ToString();
                var readyStatus = PackageSubmittedStatusType.Ready.ToString();
                var pendingStatus = PackageSubmittedStatusType.Pending.ToString();
                var waitingStatus = PackageSubmittedStatusType.Waiting.ToString();

                //var resubmittedPackages = submittedPackages.Where(p => p.ReviewedDate.HasValue && p.Published > p.ReviewedDate).OrderBy(p => p.Published).ToList();
                var resubmittedPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == updatedStatus).OrderBy(p => p.Published).ToList();
                updatedPackagesCount = resubmittedPackages.Count;

                var respondedPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == respondedStatus).OrderBy(p => p.LastUpdated).ToList();
                respondedPackagesCount = respondedPackages.Count;

                var unreviewedPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == readyStatus).OrderBy(p => p.Published).ToList();
                unreviewedPackagesCount = unreviewedPackages.Count;

                var pendingAutoReviewPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == pendingStatus || p.SubmittedStatusForDatabase == null).OrderBy(p => p.Published).ToList();
                unreviewedPackagesCount += pendingAutoReviewPackages.Count;

                //var waitingForMaintainerPackages = submittedPackages.Where(p => p.ReviewedDate >= p.Published).OrderByDescending(p => p.ReviewedDate).ToList();
                var waitingForMaintainerPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == waitingStatus).OrderByDescending(p => p.ReviewedDate).ToList();
                waitingPackagesCount = waitingForMaintainerPackages.Count;

                packagesToShow = resubmittedPackages.Union(respondedPackages).Union(unreviewedPackages).Union(pendingAutoReviewPackages).Union(waitingForMaintainerPackages);

                if (!string.IsNullOrWhiteSpace(q))
                {
                    packagesToShow = packagesToShow.AsQueryable().Search(q).ToList();
                }

                switch (searchFilter.SortProperty)
                {
                    case SortProperty.DisplayName:
                        packagesToShow = packagesToShow.OrderBy(p => p.Title);
                        break;
                    case SortProperty.Recent:
                        packagesToShow = packagesToShow.OrderByDescending(p => p.Published);
                        break;
                    default:
                        //do not change the search order
                        break;
                }

                totalHits = packagesToShow.Count() + packageVersions.Count();

                if ((searchFilter.Skip + searchFilter.Take) >= packagesToShow.Count() & string.IsNullOrWhiteSpace(q)) packagesToShow = packagesToShow.Union(packageVersions.OrderByDescending(pv => pv.PackageRegistration.DownloadCount).ToList());

                packagesToShow = packagesToShow.Skip(searchFilter.Skip).Take(searchFilter.Take);
            }
            else
            {
                SearchResults results;

                 // fetch most common query from cache to relieve load on the search service
                if (string.IsNullOrEmpty(q) && page == 1)
                {
                    results = Cache.Get(
                        string.Format(
                            "searchResults-{0}-{1}-{2}-{3}-{4}",
                            searchFilter.SearchTerm,
                            searchFilter.IncludePrerelease,
                            searchFilter.Skip,
                            searchFilter.SortProperty.to_string(),
                            searchFilter.SortDirection),
                        DateTime.UtcNow.AddMinutes(10),
                        () => searchSvc.Search(searchFilter));
                  
                }
                else
                {
                     results = Cache.Get(
                        string.Format(
                            "searchResults-{0}-{1}-{2}-{3}-{4}",
                            searchFilter.SearchTerm,
                            searchFilter.IncludePrerelease,
                            searchFilter.Skip,
                            searchFilter.SortProperty.to_string(),
                            searchFilter.SortDirection),
                        DateTime.UtcNow.AddSeconds(30),
                        () => searchSvc.Search(searchFilter));
                }

                totalHits = results.Hits;

                packagesToShow = results.Data.ToList();
            }
            
            if (page == 1 && !packagesToShow.Any())
            {
                // In the event the index wasn't updated, we may get an incorrect count. 
                totalHits = 0;
            }

            var viewModel = new PackageListViewModel(
                packagesToShow, q, sortOrder, totalHits, page - 1, Constants.DefaultPackageListPageSize, Url, prerelease, moderatorQueue, updatedPackagesCount, unreviewedPackagesCount, waitingPackagesCount, respondedPackagesCount);

            ViewBag.SearchTerm = q;

            return View("~/Views/Packages/ListPackages.cshtml", viewModel);
        }
コード例 #5
0
        public virtual ActionResult ListPackages(string q, string sortOrder = null, int page = 1, bool prerelease = false, bool moderatorQueue = false)
        {
            if (page < 1) page = 1;
            q = (q ?? string.Empty).Trim();

            IQueryable<Package> packageVersions = packageSvc.GetPackagesForListing(prerelease);
            IEnumerable<Package> packagesToShow = new List<Package>();

            if (moderatorQueue)
            {
                var unknownStatus = PackageStatusType.Unknown.GetDescriptionOrValue();

                //This is going to be fun. Unknown status ones would be listed, but sometimes a few might slip through the cracks if a maintainer unlists a package.
                // A user can just email us to catch those though.
                packageVersions = packageVersions.Where(p => !p.IsPrerelease).Where(p => p.StatusForDatabase == unknownStatus || p.StatusForDatabase == null);
            }

            q = (q ?? "").Trim();

            if (String.IsNullOrEmpty(sortOrder))
            {
                // Determine the default sort order. If no query string is specified, then the sortOrder is DownloadCount
                // If we are searching for something, sort by relevance.
                sortOrder = q.IsEmpty() ? Constants.PopularitySortOrder : Constants.RelevanceSortOrder;
            }

            int totalHits = 0;
            int updatedPackagesCount = 0;
            int respondedPackagesCount = 0;
            int unreviewedPackagesCount = 0;
            int waitingPackagesCount = 0;
            var searchFilter = GetSearchFilter(q, sortOrder, page, prerelease);

            if (moderatorQueue)
            {
                var submittedPackages = packageSvc.GetSubmittedPackages(useCache: !Request.IsAuthenticated).ToList();

                var updatedStatus = PackageSubmittedStatusType.Updated.ToString();
                var respondedStatus = PackageSubmittedStatusType.Responded.ToString();
                var readyStatus = PackageSubmittedStatusType.Ready.ToString();
                var pendingStatus = PackageSubmittedStatusType.Pending.ToString();
                var waitingStatus = PackageSubmittedStatusType.Waiting.ToString();

                //var resubmittedPackages = submittedPackages.Where(p => p.ReviewedDate.HasValue && p.Published > p.ReviewedDate).OrderBy(p => p.Published).ToList();
                var resubmittedPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == updatedStatus).OrderBy(p => p.Published).ToList();
                updatedPackagesCount = resubmittedPackages.Count;

                var respondedPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == respondedStatus).OrderBy(p => p.LastUpdated).ToList();
                respondedPackagesCount = respondedPackages.Count;

                var unreviewedPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == readyStatus).OrderBy(p => p.Published).ToList();
                unreviewedPackagesCount = unreviewedPackages.Count;

                var pendingAutoReviewPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == pendingStatus || p.SubmittedStatusForDatabase == null).OrderBy(p => p.Published).ToList();
                unreviewedPackagesCount += pendingAutoReviewPackages.Count;

                //var waitingForMaintainerPackages = submittedPackages.Where(p => p.ReviewedDate >= p.Published).OrderByDescending(p => p.ReviewedDate).ToList();
                var waitingForMaintainerPackages = submittedPackages.Where(p => p.SubmittedStatusForDatabase == waitingStatus).OrderByDescending(p => p.ReviewedDate).ToList();
                waitingPackagesCount = waitingForMaintainerPackages.Count;

                packagesToShow = resubmittedPackages.Union(respondedPackages).Union(unreviewedPackages).Union(pendingAutoReviewPackages).Union(waitingForMaintainerPackages);

                if (!string.IsNullOrWhiteSpace(q))
                {
                    packagesToShow = packagesToShow.AsQueryable().Search(q).ToList();
                }

                switch (searchFilter.SortProperty)
                {
                    case SortProperty.DisplayName:
                        packagesToShow = packagesToShow.OrderBy(p => p.Title);
                        break;
                    case SortProperty.Recent:
                        packagesToShow = packagesToShow.OrderByDescending(p => p.Published);
                        break;
                    default:
                        //do not change the search order
                        break;
                }

                totalHits = packagesToShow.Count() + packageVersions.Count();

                if ((searchFilter.Skip + searchFilter.Take) >= packagesToShow.Count() & string.IsNullOrWhiteSpace(q)) packagesToShow = packagesToShow.Union(packageVersions.OrderByDescending(pv => pv.PackageRegistration.DownloadCount).ToList());

                packagesToShow = packagesToShow.Skip(searchFilter.Skip).Take(searchFilter.Take);
            }
            else
            {
                var results = searchSvc.Search(searchFilter);

                var cacheTime = DateTime.UtcNow.AddSeconds(30);
                // fetch most common query from cache to relieve load on the search service
                if (string.IsNullOrEmpty(q) && page == 1)
                {
                    cacheTime = DateTime.UtcNow.AddMinutes(10);
                }

                totalHits = 0;
                int.TryParse(Cache.Get(
                   string.Format(
                       "searchResultsHits-{0}-{1}-{2}-{3}-{4}",
                       searchFilter.SearchTerm.to_lower(),
                       searchFilter.IncludePrerelease,
                       searchFilter.Skip,
                       searchFilter.SortProperty.to_string(),
                       searchFilter.SortDirection.to_string()),
                   cacheTime,
                   () => results.Hits.to_string()), out totalHits);

                packagesToShow = Cache.Get(
                   string.Format(
                       "searchResults-{0}-{1}-{2}-{3}-{4}",
                       searchFilter.SearchTerm.to_lower(),
                       searchFilter.IncludePrerelease,
                       searchFilter.Skip,
                       searchFilter.SortProperty.to_string(),
                       searchFilter.SortDirection.to_string()),
                   cacheTime,
                   () => results.Data.ToList());
            }
            
            if (page == 1 && !packagesToShow.Any())
            {
                // In the event the index wasn't updated, we may get an incorrect count. 
                totalHits = 0;
            }

            var viewModel = new PackageListViewModel(
                packagesToShow, q, sortOrder, totalHits, page - 1, Constants.DefaultPackageListPageSize, Url, prerelease, moderatorQueue, updatedPackagesCount, unreviewedPackagesCount, waitingPackagesCount, respondedPackagesCount);

            ViewBag.SearchTerm = q;

            return View("~/Views/Packages/ListPackages.cshtml", viewModel);
        }