Esempio n. 1
0
        public static Query BuildLogFilterQuery(LogChronicleFilter filter)
        {
            var query = new Query();

            var andNodes = new List <BSONDocumentElement>();

            void add(BSONElement elm) => andNodes.Add(new BSONDocumentElement(new BSONDocument().Set(elm)));


            if (!filter.Gdid.IsZero)
            {
                add(DataDocConverter.GDID_CLRtoBSON(BsonConvert.FLD_GDID, filter.Gdid));
            }

            if (filter.Id.HasValue)
            {
                add(DataDocConverter.GUID_CLRtoBSON(BsonConvert.FLD_GUID, filter.Id.Value));
            }

            if (filter.RelId.HasValue)
            {
                add(DataDocConverter.GUID_CLRtoBSON(BsonConvert.FLD_RELATED_TO, filter.RelId.Value));
            }

            if (filter.Channel.HasValue && !filter.Channel.Value.IsZero)
            {
                add(new BSONInt64Element(BsonConvert.FLD_CHANNEL, (long)filter.Channel.Value.ID));
            }

            if (filter.Application.HasValue && !filter.Application.Value.IsZero)
            {
                add(new BSONInt64Element(BsonConvert.FLD_APP, (long)filter.Application.Value.ID));
            }

            if (filter.TimeRange.HasValue && filter.TimeRange.Value.Start.HasValue)
            {
                add(new BSONDocumentElement(BsonConvert.FLD_TIMESTAMP, new BSONDocument().Set(new BSONDateTimeElement("$gte", filter.TimeRange.Value.Start.Value))));
            }

            if (filter.TimeRange.HasValue && filter.TimeRange.Value.End.HasValue)
            {
                add(new BSONDocumentElement(BsonConvert.FLD_TIMESTAMP, new BSONDocument().Set(new BSONDateTimeElement("$lte", filter.TimeRange.Value.End.Value))));
            }


            if (filter.MinType.HasValue)
            {
                add(new BSONDocumentElement(BsonConvert.FLD_TYPE, new BSONDocument().Set(new BSONInt32Element("$gte", (int)filter.MinType.Value))));
            }

            if (filter.MaxType.HasValue)
            {
                add(new BSONDocumentElement(BsonConvert.FLD_TYPE, new BSONDocument().Set(new BSONInt32Element("$lte", (int)filter.MaxType.Value))));
            }

            if (andNodes.Count > 0)
            {
                query.Set(new BSONArrayElement("$and", andNodes.ToArray()));
            }

            //todo: Finish the Advanced filter
            //var ctx = m_LogXlat.TranslateInContext(filter.AdvancedFilter);
            // var query = query;// ctx.Query;

            return(query);
        }
Esempio n. 2
0
        public static BSONDocument ToBson(Message msg)
        {
            var doc = new BSONDocument();

            doc.Set(DataDocConverter.GDID_CLRtoBSON(FLD_GDID, msg.Gdid));
            doc.Set(DataDocConverter.GUID_CLRtoBSON(FLD_GUID, msg.Guid));
            doc.Set(DataDocConverter.GUID_CLRtoBSON(FLD_RELATED_TO, msg.RelatedTo));

            doc.Set(new BSONInt64Element(FLD_CHANNEL, (long)msg.Channel.ID));
            doc.Set(new BSONInt64Element(FLD_APP, (long)msg.App.ID));
            doc.Set(new BSONInt32Element(FLD_TYPE, (int)msg.Type));
            doc.Set(new BSONInt32Element(FLD_SOURCE, msg.Source));
            doc.Set(new BSONDateTimeElement(FLD_TIMESTAMP, msg.UTCTimeStamp));

            if (msg.Host.IsNullOrWhiteSpace())
            {
                doc.Set(new BSONNullElement(FLD_HOST));
            }
            else
            {
                doc.Set(new BSONStringElement(FLD_HOST, msg.Host));
            }

            if (msg.From.IsNullOrWhiteSpace())
            {
                doc.Set(new BSONNullElement(FLD_FROM));
            }
            else
            {
                doc.Set(new BSONStringElement(FLD_FROM, msg.From));
            }

            if (msg.Topic.IsNullOrWhiteSpace())
            {
                doc.Set(new BSONNullElement(FLD_TOPIC));
            }
            else
            {
                doc.Set(new BSONStringElement(FLD_TOPIC, msg.Topic));
            }


            if (msg.Text.IsNullOrWhiteSpace())
            {
                doc.Set(new BSONNullElement(FLD_TEXT));
            }
            else
            {
                doc.Set(new BSONStringElement(FLD_TEXT, msg.Text));
            }

            if (msg.Parameters.IsNullOrWhiteSpace())
            {
                doc.Set(new BSONNullElement(FLD_PARAMETERS));
            }
            else
            {
                doc.Set(new BSONStringElement(FLD_PARAMETERS, msg.Parameters));
            }

            if (msg.ExceptionData != null)
            {
                doc.Set(new BSONStringElement(FLD_EXCEPTION, msg.ExceptionData.ToJson(JsonWritingOptions.CompactRowsAsMap)));
            }
            else
            {
                doc.Set(new BSONNullElement(FLD_EXCEPTION));
            }

            var ad = ArchiveConventions.DecodeArchiveDimensionsMap(msg);

            if (ad == null)
            {
                doc.Set(new BSONNullElement(FLD_AD));
            }
            else
            {
                var adDoc = ad.ToBson();
                doc.Set(new BSONDocumentElement(FLD_AD, adDoc));
            }

            return(doc);
        }