Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public OperationResult <ModelAnnotations> Search(AnnotationSearchFilter f)
        {
            OperationResult <ModelAnnotations> res = null;

            try
            {
                var entities = DataContext
                               .Annotations
                               .ForActiveOrg()
                               .Filter(f)
                               .OrderByDescending(x => x.Epoch)
                               .Include(x => x.Tags)
                               .ThenInclude(x => x.AnnotationTag)
                               .Include(x => x.User)
                               .ToList();

                if (f.SearchByTags)
                {
                    entities = entities.FilterByTags(f);
                }

                var models = entities
                             .Select(x => x.ToModel())
                             .ToList();

                res = OperationResult <ModelAnnotations> .Create(models);
            }
            catch (Exception e)
            {
                res = OperationResult <ModelAnnotations> .Create(ErrorCode.BadGetAnnotations, e);
            }

            return(res);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="r"></param>
        /// <param name="f"></param>
        /// <returns></returns>
        public static List <Annotation> FilterByTags(
            this List <Annotation> r, AnnotationSearchFilter f)
        {
            Func <Annotation, bool> tagPred = x => (!f.MatchAny) ?
                                              f.Tags.Intersect(x.Tags.Select(y => y.AnnotationTag.Term)).Count() == f.Tags.Count() :
                                              f.Tags.Intersect(x.Tags.Select(y => y.AnnotationTag.Term)).Count() > 0;

            return(r.Where(tagPred).ToList());
        }
Ejemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="r"></param>
        /// <param name="f"></param>
        /// <returns></returns>
        public static IQueryable <Annotation> Filter(
            this IQueryable <Annotation> r, AnnotationSearchFilter f)
        {
            if (f.From.HasValue)
            {
                r = r.Where(x =>
                            (0 == x.EpochEnd && x.Epoch >= f.From) ||
                            (0 != x.EpochEnd && (x.Epoch >= f.From || x.EpochEnd >= f.From)));
            }

            if (f.To.HasValue)
            {
                r = r.Where(x =>
                            (0 == x.EpochEnd && x.Epoch <= f.To) ||
                            (0 != x.EpochEnd && (x.Epoch <= f.To || x.EpochEnd <= f.To)));
            }

            if (f.Type.HasValue)
            {
                r = (f.Type.Value == AnnotationSearchFilter.Kind.Alert) ?
                    r.Where(x => x.AlertId.HasValue && x.AlertId > 0) :
                    r.Where(x => !x.AlertId.HasValue || 0 == x.AlertId);
                //
            }

            if (f.SearchByDashboard)
            {
                if (f.DashboardId.HasValue)
                {
                    r = r.Where(x => x.DashboardId == f.DashboardId.Value);
                }

                if (f.PanelId.HasValue)
                {
                    r = r.Where(x => x.PanelId == f.PanelId.Value);
                }

                if (f.UserId.HasValue)
                {
                    r = r.Where(x => x.UserId == f.UserId);
                }
            }

            if (f.Limit.HasValue)
            {
                r = r.Take(f.Limit.Value);
            }

            return(r);
        }