Пример #1
0
        private static TimelineEntity MaskFields(TimelineEntity entity, EnumSet <TimelineReader.Field
                                                                                 > fields)
        {
            // Conceal the fields that are not going to be exposed
            TimelineEntity entityToReturn = new TimelineEntity();

            entityToReturn.SetEntityId(entity.GetEntityId());
            entityToReturn.SetEntityType(entity.GetEntityType());
            entityToReturn.SetStartTime(entity.GetStartTime());
            entityToReturn.SetDomainId(entity.GetDomainId());
            // Deep copy
            if (fields.Contains(TimelineReader.Field.Events))
            {
                entityToReturn.AddEvents(entity.GetEvents());
            }
            else
            {
                if (fields.Contains(TimelineReader.Field.LastEventOnly))
                {
                    entityToReturn.AddEvent(entity.GetEvents()[0]);
                }
                else
                {
                    entityToReturn.SetEvents(null);
                }
            }
            if (fields.Contains(TimelineReader.Field.RelatedEntities))
            {
                entityToReturn.AddRelatedEntities(entity.GetRelatedEntities());
            }
            else
            {
                entityToReturn.SetRelatedEntities(null);
            }
            if (fields.Contains(TimelineReader.Field.PrimaryFilters))
            {
                entityToReturn.AddPrimaryFilters(entity.GetPrimaryFilters());
            }
            else
            {
                entityToReturn.SetPrimaryFilters(null);
            }
            if (fields.Contains(TimelineReader.Field.OtherInfo))
            {
                entityToReturn.AddOtherInfo(entity.GetOtherInfo());
            }
            else
            {
                entityToReturn.SetOtherInfo(null);
            }
            return(entityToReturn);
        }
Пример #2
0
 /// <exception cref="System.IO.IOException"/>
 public virtual TimelineEntities GetEntities(string entityType, long limit, long windowStart
                                             , long windowEnd, string fromId, long fromTs, NameValuePair primaryFilter, ICollection
                                             <NameValuePair> secondaryFilters, EnumSet <TimelineReader.Field> fields, TimelineDataManager.CheckAcl
                                             checkAcl)
 {
     lock (this)
     {
         if (limit == null)
         {
             limit = DefaultLimit;
         }
         if (windowStart == null)
         {
             windowStart = long.MinValue;
         }
         if (windowEnd == null)
         {
             windowEnd = long.MaxValue;
         }
         if (fields == null)
         {
             fields = EnumSet.AllOf <TimelineReader.Field>();
         }
         IEnumerator <TimelineEntity> entityIterator = null;
         if (fromId != null)
         {
             TimelineEntity firstEntity = entities[new EntityIdentifier(fromId, entityType)];
             if (firstEntity == null)
             {
                 return(new TimelineEntities());
             }
             else
             {
                 entityIterator = new TreeSet <TimelineEntity>(entities.Values).TailSet(firstEntity
                                                                                        , true).GetEnumerator();
             }
         }
         if (entityIterator == null)
         {
             entityIterator = new PriorityQueue <TimelineEntity>(entities.Values).GetEnumerator
                                  ();
         }
         IList <TimelineEntity> entitiesSelected = new AList <TimelineEntity>();
         while (entityIterator.HasNext())
         {
             TimelineEntity entity = entityIterator.Next();
             if (entitiesSelected.Count >= limit)
             {
                 break;
             }
             if (!entity.GetEntityType().Equals(entityType))
             {
                 continue;
             }
             if (entity.GetStartTime() <= windowStart)
             {
                 continue;
             }
             if (entity.GetStartTime() > windowEnd)
             {
                 continue;
             }
             if (fromTs != null && entityInsertTimes[new EntityIdentifier(entity.GetEntityId()
                                                                          , entity.GetEntityType())] > fromTs)
             {
                 continue;
             }
             if (primaryFilter != null && !MatchPrimaryFilter(entity.GetPrimaryFilters(), primaryFilter
                                                              ))
             {
                 continue;
             }
             if (secondaryFilters != null)
             {
                 // AND logic
                 bool flag = true;
                 foreach (NameValuePair secondaryFilter in secondaryFilters)
                 {
                     if (secondaryFilter != null && !MatchPrimaryFilter(entity.GetPrimaryFilters(), secondaryFilter
                                                                        ) && !MatchFilter(entity.GetOtherInfo(), secondaryFilter))
                     {
                         flag = false;
                         break;
                     }
                 }
                 if (!flag)
                 {
                     continue;
                 }
             }
             if (entity.GetDomainId() == null)
             {
                 entity.SetDomainId(TimelineDataManager.DefaultDomainId);
             }
             if (checkAcl == null || checkAcl.Check(entity))
             {
                 entitiesSelected.AddItem(entity);
             }
         }
         IList <TimelineEntity> entitiesToReturn = new AList <TimelineEntity>();
         foreach (TimelineEntity entitySelected in entitiesSelected)
         {
             entitiesToReturn.AddItem(MaskFields(entitySelected, fields));
         }
         entitiesToReturn.Sort();
         TimelineEntities entitiesWrapper = new TimelineEntities();
         entitiesWrapper.SetEntities(entitiesToReturn);
         return(entitiesWrapper);
     }
 }