コード例 #1
0
ファイル: UserRepository.cs プロジェクト: zzms/Exceptionless
        public Task <long> CountByOrganizationIdAsync(string organizationId)
        {
            var filter = Filter <User> .Term(u => u.OrganizationIds, new[] { organizationId });

            var options = new ExceptionlessQuery().WithElasticFilter(filter);

            return(CountAsync(options));
        }
コード例 #2
0
        public Task HideAllByClientIpAndDateAsync(string organizationId, string clientIp, DateTime utcStart, DateTime utcEnd)
        {
            var query = new ExceptionlessQuery()
                        .WithElasticFilter(Filter <PersistentEvent> .Term("client_ip_address", clientIp))
                        .WithDateRange(utcStart, utcEnd, EventIndex.Fields.PersistentEvent.Date)
                        .WithIndices(utcStart, utcEnd, $"'{_index.VersionedName}-'yyyyMM");

            return(UpdateAllAsync(organizationId, query, new { is_hidden = true }));
        }
コード例 #3
0
        public Task <long> HideAllByClientIpAndDateAsync(string organizationId, string clientIp, DateTime utcStart, DateTime utcEnd)
        {
            var query = new ExceptionlessQuery()
                        .WithOrganizationId(organizationId)
                        .WithElasticFilter(Filter <PersistentEvent> .Term("client_ip_address", clientIp))
                        .WithDateRange(utcStart, utcEnd, EventIndexType.Fields.Date)
                        .WithIndexes(utcStart, utcEnd);

            return(PatchAllAsync(query, new { is_hidden = true }));
        }
コード例 #4
0
        public Task <long> HideAllByClientIpAndDateAsync(string organizationId, string clientIp, DateTime utcStart, DateTime utcEnd)
        {
            var query = new ExceptionlessQuery()
                        .WithOrganizationId(organizationId)
                        .WithElasticFilter(Query <PersistentEvent> .Term(EventIndexType.Alias.IpAddress, clientIp))
                        .WithDateRange(utcStart, utcEnd, (PersistentEvent e) => e.Date)
                        .WithIndexes(utcStart, utcEnd);

            return(PatchAllAsync(query, new { is_hidden = true, updated_utc = SystemClock.UtcNow }));
        }
コード例 #5
0
        public override Task <long> RemoveAllByOrganizationIdAsync(string organizationId)
        {
            if (String.IsNullOrEmpty(organizationId))
            {
                throw new ArgumentNullException(nameof(organizationId));
            }

            var query = new ExceptionlessQuery().WithOrganizationId(organizationId);

            return(PatchAllAsync(query, new { is_deleted = true, updated_utc = SystemClock.UtcNow }));
        }
コード例 #6
0
        public Task <FindResults <Project> > GetByNextSummaryNotificationOffsetAsync(byte hourToSendNotificationsAfterUtcMidnight, int limit = 50)
        {
            var filter = Filter <Project> .Range(r => r.OnField(o => o.NextSummaryEndOfDayTicks).Lower(SystemClock.UtcNow.Ticks - (TimeSpan.TicksPerHour *hourToSendNotificationsAfterUtcMidnight)));

            var query = new ExceptionlessQuery()
                        .WithElasticFilter(filter)
                        .WithPaging(new ElasticPagingOptions().UseSnapshotPaging().WithLimit(limit))
                        .WithSort(EventIndexType.Fields.OrganizationId);

            return(FindAsync(query));
        }
コード例 #7
0
        public Task <FindResults <PersistentEvent> > GetByFilterAsync(IExceptionlessSystemFilterQuery systemFilter, string userFilter, string sort, string field, DateTime utcStart, DateTime utcEnd, PagingOptions paging)
        {
            var search = new ExceptionlessQuery()
                         .WithDateRange(utcStart, utcEnd, field ?? ElasticType.GetFieldName(e => e.Date))
                         .WithIndexes(utcStart, utcEnd)
                         .WithSystemFilter(systemFilter)
                         .WithFilter(userFilter)
                         .WithPaging(paging);

            search = !String.IsNullOrEmpty(sort) ? search.WithSort(sort) : search.WithSortDescending((PersistentEvent e) => e.Date);
            return(FindAsync(search));
        }
コード例 #8
0
        public Task <FindResults <Stack> > GetByFilterAsync(IExceptionlessSystemFilterQuery systemFilter, string userFilter, string sort, string field, DateTime utcStart, DateTime utcEnd, PagingOptions paging)
        {
            var search = new ExceptionlessQuery()
                         .WithDateRange(utcStart, utcEnd, field ?? ElasticType.GetFieldName(s => s.LastOccurrence))
                         .WithSystemFilter(systemFilter)
                         .WithFilter(userFilter)
                         .WithPaging(paging)
                         .WithSort(sort);

            search = !String.IsNullOrEmpty(sort) ? search.WithSort(sort) : search.WithSortDescending((Stack s) => s.LastOccurrence);
            return(FindAsync(search));
        }
コード例 #9
0
        public Task <FindResults <Stack> > GetNewAsync(string projectId, DateTime utcStart, DateTime utcEnd, PagingOptions paging, string filter)
        {
            var filterContainer = Filter <Stack> .Range(r => r.OnField(s => s.FirstOccurrence).GreaterOrEquals(utcStart)) && Filter <Stack> .Range(r => r.OnField(s => s.FirstOccurrence).LowerOrEquals(utcEnd));

            var query = new ExceptionlessQuery()
                        .WithProjectId(projectId)
                        .WithElasticFilter(filterContainer)
                        .WithFilter(filter)
                        .WithSort(StackIndex.Fields.Stack.FirstOccurrence, SortOrder.Descending)
                        .WithPaging(paging);

            return(FindAsync(query));
        }
コード例 #10
0
        public Task UpdateHiddenByStackAsync(string organizationId, string stackId, bool isHidden, bool sendNotifications = true)
        {
            if (String.IsNullOrEmpty(stackId))
            {
                throw new ArgumentNullException(nameof(stackId));
            }

            var query = new ExceptionlessQuery()
                        .WithOrganizationId(organizationId)
                        .WithStackId(stackId)
                        .WithFieldEquals(Fields.IsHidden, !isHidden);

            // TODO: Update this to use the update by query syntax that's coming in 2.3.
            return(UpdateAllAsync(organizationId, query, new { is_hidden = isHidden }, sendNotifications));
        }
コード例 #11
0
        public Task <long> UpdateHiddenByStackAsync(string organizationId, string projectId, string stackId, bool isHidden, bool sendNotifications = true)
        {
            if (String.IsNullOrEmpty(stackId))
            {
                throw new ArgumentNullException(nameof(stackId));
            }

            var query = new ExceptionlessQuery()
                        .WithOrganizationId(organizationId)
                        .WithProjectId(projectId)
                        .WithStackId(stackId)
                        .WithFieldEquals((PersistentEvent e) => e.IsHidden, !isHidden);

            // TODO: Update this to use the update by query syntax that's coming in 2.3.
            return(PatchAllAsync(query, new { is_hidden = isHidden, updated_utc = SystemClock.UtcNow }));
        }
コード例 #12
0
        public Task <long> UpdateFixedByStackAsync(string organizationId, string projectId, string stackId, bool isFixed, bool sendNotifications = true)
        {
            if (String.IsNullOrEmpty(stackId))
            {
                throw new ArgumentNullException(nameof(stackId));
            }

            var query = new ExceptionlessQuery()
                        .WithOrganizationId(organizationId)
                        .WithProjectId(projectId)
                        .WithStackId(stackId)
                        .WithFieldEquals(EventIndexType.Fields.IsFixed, !isFixed);

            // TODO: Update this to use the update by query syntax that's coming in 2.3.
            return(PatchAllAsync(query, new { is_fixed = isFixed }));
        }
コード例 #13
0
        public async Task <User> GetByEmailAddressAsync(string emailAddress)
        {
            if (String.IsNullOrWhiteSpace(emailAddress))
            {
                return(null);
            }

            emailAddress = emailAddress.ToLowerInvariant().Trim();
            var query = new ExceptionlessQuery()
                        .WithElasticFilter(Filter <User> .Term(u => u.EmailAddress, emailAddress))
                        .WithCacheKey(String.Concat("Email:", emailAddress));

            var hit = await FindOneAsync(query).AnyContext();

            return(hit?.Document);
        }
コード例 #14
0
        public Task <FindResults <Stack> > GetByFilterAsync(string systemFilter, string userFilter, string sort, SortOrder sortOrder, string field, DateTime utcStart, DateTime utcEnd, PagingOptions paging)
        {
            if (String.IsNullOrEmpty(sort))
            {
                sort      = StackIndex.Fields.Stack.LastOccurrence;
                sortOrder = SortOrder.Descending;
            }

            var search = new ExceptionlessQuery()
                         .WithDateRange(utcStart, utcEnd, field ?? StackIndex.Fields.Stack.LastOccurrence)
                         .WithSystemFilter(systemFilter)
                         .WithFilter(userFilter)
                         .WithPaging(paging)
                         .WithSort(sort, sortOrder);

            return(FindAsync(search));
        }
コード例 #15
0
        public Task <FindResults <PersistentEvent> > GetByFilterAsync(string systemFilter, string userFilter, string sort, SortOrder sortOrder, string field, DateTime utcStart, DateTime utcEnd, PagingOptions paging)
        {
            if (String.IsNullOrEmpty(sort))
            {
                sort      = EventIndex.Fields.PersistentEvent.Date;
                sortOrder = SortOrder.Descending;
            }

            var search = new ExceptionlessQuery()
                         .WithDateRange(utcStart, utcEnd, field ?? EventIndex.Fields.PersistentEvent.Date)
                         .WithIndices(utcStart, utcEnd, $"'{_index.VersionedName}-'yyyyMM")
                         .WithSystemFilter(systemFilter)
                         .WithFilter(userFilter)
                         .WithPaging(paging)
                         .WithSort(sort, sortOrder);

            return(FindAsync(search));
        }
コード例 #16
0
        public Task <FindResults <Stack> > GetByFilterAsync(IExceptionlessSystemFilterQuery systemFilter, string userFilter, SortingOptions sorting, string field, DateTime utcStart, DateTime utcEnd, PagingOptions paging)
        {
            if (sorting.Fields.Count == 0)
            {
                sorting.Fields.Add(new FieldSort {
                    Field = StackIndexType.Fields.LastOccurrence, Order = SortOrder.Descending
                });
            }

            var search = new ExceptionlessQuery()
                         .WithDateRange(utcStart, utcEnd, field ?? StackIndexType.Fields.LastOccurrence)
                         .WithSystemFilter(systemFilter)
                         .WithFilter(userFilter)
                         .WithPaging(paging)
                         .WithSort(sorting);

            return(FindAsync(search));
        }
コード例 #17
0
        public Task <FindResults <PersistentEvent> > GetByFilterAsync(string systemFilter, string userFilter, SortingOptions sorting, string field, DateTime utcStart, DateTime utcEnd, PagingOptions paging)
        {
            if (sorting.Fields.Count == 0)
            {
                sorting.Fields.Add(new FieldSort {
                    Field = EventIndex.Fields.PersistentEvent.Date, Order = SortOrder.Descending
                });
            }

            var search = new ExceptionlessQuery()
                         .WithDateRange(utcStart, utcEnd, field ?? EventIndex.Fields.PersistentEvent.Date)
                         .WithIndices(utcStart, utcEnd, $"'{_index.VersionedName}-'yyyyMM")
                         .WithSystemFilter(systemFilter)
                         .WithFilter(userFilter)
                         .WithPaging(paging)
                         .WithSort(sorting);

            return(FindAsync(search));
        }
コード例 #18
0
        protected virtual async Task <IHttpActionResult> GetCountAsync(IExceptionlessSystemFilterQuery sf, TimeInfo ti, string filter = null, string aggregations = null)
        {
            var pr = await _validator.ValidateQueryAsync(filter);

            if (!pr.IsValid)
            {
                return(BadRequest(pr.Message));
            }

            var far = await _validator.ValidateAggregationsAsync(aggregations);

            if (!far.IsValid)
            {
                return(BadRequest(far.Message));
            }

            sf.UsesPremiumFeatures = pr.UsesPremiumFeatures || far.UsesPremiumFeatures;
            IRepositoryQuery query = new ExceptionlessQuery()
                                     .WithSystemFilter(ShouldApplySystemFilter(sf, filter) ? sf : null)
                                     .WithDateRange(ti.Range.UtcStart, ti.Range.UtcEnd, ti.Field)
                                     .WithIndexes(ti.Range.UtcStart, ti.Range.UtcEnd);

            CountResult result;

            try {
                result = await _repository.CountBySearchAsync(query, filter, aggregations);
            } catch (Exception ex) {
                _logger.Error().Exception(ex)
                .Message("An error has occurred. Please check your filter or aggregations.")
                .Property("Search Filter", new { SystemFilter = sf, UserFilter = filter, Time = ti, Aggregations = aggregations })
                .Tag("Search")
                .Identity(CurrentUser.EmailAddress)
                .Property("User", CurrentUser)
                .SetActionContext(ActionContext)
                .Write();

                return(BadRequest("An error has occurred. Please check your search filter."));
            }

            return(Ok(result));
        }
コード例 #19
0
        public async Task <BillingPlanStats> GetBillingPlanStatsAsync()
        {
            var query = new ExceptionlessQuery()
                        .WithSelectedFields("plan_id", "is_suspended", "billing_price", "billing_status")
                        .WithSort(OrganizationIndex.Fields.Organization.PlanId, SortOrder.Descending);

            var results = (await FindAsync(query).AnyContext()).Documents;

            List <Organization> smallOrganizations  = results.Where(o => String.Equals(o.PlanId, BillingManager.SmallPlan.Id) && o.BillingPrice > 0).ToList();
            List <Organization> mediumOrganizations = results.Where(o => String.Equals(o.PlanId, BillingManager.MediumPlan.Id) && o.BillingPrice > 0).ToList();
            List <Organization> largeOrganizations  = results.Where(o => String.Equals(o.PlanId, BillingManager.LargePlan.Id) && o.BillingPrice > 0).ToList();
            decimal             monthlyTotalPaid    = smallOrganizations.Where(o => !o.IsSuspended && o.BillingStatus == BillingStatus.Active).Sum(o => o.BillingPrice)
                                                      + mediumOrganizations.Where(o => !o.IsSuspended && o.BillingStatus == BillingStatus.Active).Sum(o => o.BillingPrice)
                                                      + largeOrganizations.Where(o => !o.IsSuspended && o.BillingStatus == BillingStatus.Active).Sum(o => o.BillingPrice);

            List <Organization> smallYearlyOrganizations  = results.Where(o => String.Equals(o.PlanId, BillingManager.SmallYearlyPlan.Id) && o.BillingPrice > 0).ToList();
            List <Organization> mediumYearlyOrganizations = results.Where(o => String.Equals(o.PlanId, BillingManager.MediumYearlyPlan.Id) && o.BillingPrice > 0).ToList();
            List <Organization> largeYearlyOrganizations  = results.Where(o => String.Equals(o.PlanId, BillingManager.LargeYearlyPlan.Id) && o.BillingPrice > 0).ToList();
            decimal             yearlyTotalPaid           = smallYearlyOrganizations.Where(o => !o.IsSuspended && o.BillingStatus == BillingStatus.Active).Sum(o => o.BillingPrice)
                                                            + mediumYearlyOrganizations.Where(o => !o.IsSuspended && o.BillingStatus == BillingStatus.Active).Sum(o => o.BillingPrice)
                                                            + largeYearlyOrganizations.Where(o => !o.IsSuspended && o.BillingStatus == BillingStatus.Active).Sum(o => o.BillingPrice);

            return(new BillingPlanStats {
                SmallTotal = smallOrganizations.Count,
                SmallYearlyTotal = smallYearlyOrganizations.Count,
                MediumTotal = mediumOrganizations.Count,
                MediumYearlyTotal = mediumYearlyOrganizations.Count,
                LargeTotal = largeOrganizations.Count,
                LargeYearlyTotal = largeYearlyOrganizations.Count,
                MonthlyTotal = monthlyTotalPaid + (yearlyTotalPaid / 12),
                YearlyTotal = (monthlyTotalPaid * 12) + yearlyTotalPaid,
                MonthlyTotalAccounts = smallOrganizations.Count + mediumOrganizations.Count + largeOrganizations.Count,
                YearlyTotalAccounts = smallYearlyOrganizations.Count + mediumYearlyOrganizations.Count + largeYearlyOrganizations.Count,
                FreeAccounts = results.Count(o => String.Equals(o.PlanId, BillingManager.FreePlan.Id)),
                PaidAccounts = results.Count(o => !String.Equals(o.PlanId, BillingManager.FreePlan.Id) && o.BillingPrice > 0),
                FreeloaderAccounts = results.Count(o => !String.Equals(o.PlanId, BillingManager.FreePlan.Id) && o.BillingPrice <= 0),
                SuspendedAccounts = results.Count(o => o.IsSuspended),
            });
        }
コード例 #20
0
        public Task <long> CountByOrganizationIdAsync(string organizationId)
        {
            var options = new ExceptionlessQuery().WithOrganizationId(organizationId);

            return(CountAsync(options));
        }
コード例 #21
0
        public Task <FindResults <Organization> > GetByCriteriaAsync(string criteria, PagingOptions paging, OrganizationSortBy sortBy, bool?paid = null, bool?suspended = null)
        {
            var filter = Filter <Organization> .MatchAll();

            if (!String.IsNullOrWhiteSpace(criteria))
            {
                filter &= Filter <Organization> .Term(o => o.Name, criteria);
            }

            if (paid.HasValue)
            {
                if (paid.Value)
                {
                    filter &= !Filter <Organization> .Term(o => o.PlanId, BillingManager.FreePlan.Id);
                }
                else
                {
                    filter &= Filter <Organization> .Term(o => o.PlanId, BillingManager.FreePlan.Id);
                }
            }

            if (suspended.HasValue)
            {
                if (suspended.Value)
                {
                    filter &= Filter <Organization> .And(and => ((
                                                                     !Filter <Organization> .Term(o => o.BillingStatus, BillingStatus.Active) &&
                                                                     !Filter <Organization> .Term(o => o.BillingStatus, BillingStatus.Trialing) &&
                                                                     !Filter <Organization> .Term(o => o.BillingStatus, BillingStatus.Canceled)
                                                                     ) || Filter <Organization> .Term(o => o.IsSuspended, true)));
                }
                else
                {
                    filter &= Filter <Organization> .And(and => ((
                                                                     Filter <Organization> .Term(o => o.BillingStatus, BillingStatus.Active) &&
                                                                     Filter <Organization> .Term(o => o.BillingStatus, BillingStatus.Trialing) &&
                                                                     Filter <Organization> .Term(o => o.BillingStatus, BillingStatus.Canceled)
                                                                     ) || Filter <Organization> .Term(o => o.IsSuspended, false)));
                }
            }

            var query = new ExceptionlessQuery().WithPaging(paging).WithElasticFilter(filter);

            switch (sortBy)
            {
            case OrganizationSortBy.Newest:
                query.WithSort(OrganizationIndex.Fields.Organization.Id, SortOrder.Descending);
                break;

            case OrganizationSortBy.Subscribed:
                query.WithSort(OrganizationIndex.Fields.Organization.SubscribeDate, SortOrder.Descending);
                break;

            // case OrganizationSortBy.MostActive:
            //    query.WithSort(OrganizationIndex.Fields.Organization.TotalEventCount, SortOrder.Descending);
            //    break;
            default:
                query.WithSort(OrganizationIndex.Fields.Organization.Name, SortOrder.Ascending);
                break;
            }

            return(FindAsync(query));
        }
コード例 #22
0
        public Task <long> RemoveAllByStackIdAsync(string organizationId, string projectId, string stackId)
        {
            var query = new ExceptionlessQuery().WithOrganizationId(organizationId).WithProjectId(projectId).WithStackId(stackId);

            return(PatchAllAsync(query, new { is_deleted = true, updated_utc = SystemClock.UtcNow }));
        }