Esempio n. 1
0
        public static BSONDocument ToBson(Event evt)
        {
            var doc = new BSONDocument();

            doc.Set(DataDocConverter.GDID_CLRtoBSON(FLD_GDID, evt.Gdid));

            //long is enough to hold positive date (2^63) for 292 million years
            doc.Set(new BSONInt64Element(FLD_CREATEUTC, (long)evt.CreateUtc));
            doc.Set(new BSONInt64Element(FLD_ORIGIN, (long)evt.Origin.ID));
            doc.Set(new BSONInt64Element(FLD_CHECKPOINTUTC, (long)evt.CheckpointUtc));//same as above

            if (evt.Headers.IsNullOrWhiteSpace())
            {
                doc.Set(new BSONNullElement(FLD_HEADERS));
            }
            else
            {
                doc.Set(new BSONStringElement(FLD_HEADERS, evt.Headers));
            }

            doc.Set(new BSONInt64Element(FLD_CONTENTTYPE, (long)evt.ContentType.ID));
            doc.Set(DataDocConverter.ByteBuffer_CLRtoBSON(FLD_CONTENT, evt.Content));

            return(doc);
        }
Esempio n. 2
0
        public static Query ID_EQ_GDID(GDID id)
        {
            var result = new Query();

            result.Set(DataDocConverter.GDID_CLRtoBSON(_ID, id));
            return(result);
        }
Esempio n. 3
0
        private BSONDocument toBSON(TodoQueue queue, TodoFrame todo)
        {
            var result = new BSONDocument();
            var t      = todo.GetType();

            result.Set(DataDocConverter.GDID_CLRtoBSON(Query._ID, todo.ID));

            result.Set(new BSONStringElement(FLD_TODO_TYPE, todo.Type.ToString()));
            result.Set(new BSONDateTimeElement(FLD_TODO_CREATETIMESTAMP, todo.CreateTimestampUTC));

            result.Set(elmStr(FLD_TODO_SHARDINGKEY, todo.ShardingKey));
            result.Set(elmStr(FLD_TODO_PARALLELKEY, todo.ParallelKey));
            result.Set(new BSONInt32Element(FLD_TODO_PRIORITY, todo.Priority));
            result.Set(new BSONDateTimeElement(FLD_TODO_STARTDATE, todo.StartDate));
            result.Set(elmStr(FLD_TODO_CORRELATIONKEY, todo.CorrelationKey));
            result.Set(new BSONInt32Element(FLD_TODO_STATE, todo.State));
            result.Set(new BSONInt32Element(FLD_TODO_TRIES, todo.Tries));

            result.Set(new BSONInt32Element(FLD_TODO_SERIALIZER, todo.Serializer));
            result.Set(elmBin(FLD_TODO_CONTENT, todo.Content));

            return(result);
        }
Esempio n. 4
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. 5
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);
        }