public void Test02()
        {
            var encoded = ArchiveConventions.EncodeArchiveDimensions(new { a = 1, b = 3 });

            encoded.See();

            var decoded = ArchiveConventions.DecodeArchiveDimensionsMap(encoded);

            Aver.IsNotNull(decoded);
            Aver.AreEqual(2, decoded.Count);

            Aver.AreObjectsEqual(1, decoded["a"]);
            Aver.AreObjectsEqual(3, decoded["b"]);
        }
        public void Test01()
        {
            var got = ArchiveConventions.DecodeArchiveDimensionsMap((string)null);

            Aver.IsNull(got);

            got = ArchiveConventions.DecodeArchiveDimensionsMap("       ");
            Aver.IsNull(got);

            got = ArchiveConventions.DecodeArchiveDimensionsMap((IArchiveLoggable)null);
            Aver.IsNull(got);

            got = ArchiveConventions.DecodeArchiveDimensionsMap("not a content produced by convention");
            Aver.IsNull(got);
        }
        public void Test03()
        {
            var encoded1 = ArchiveConventions.EncodeArchiveDimensions(new { a = 1, b = 3 });
            var encoded2 = ArchiveConventions.EncodeArchiveDimensions(new { b = 3, a = 1, c = (string)null });//notice a different sequence of keys

            encoded1.See();
            encoded2.See();
            Aver.AreEqual(encoded1, encoded2);//however the strings are equal, because keys are sorted and nulls are skipped

            var decoded = ArchiveConventions.DecodeArchiveDimensionsMap(encoded1);

            Aver.IsNotNull(decoded);
            Aver.AreEqual(2, decoded.Count);

            Aver.AreObjectsEqual(1, decoded["a"]);
            Aver.AreObjectsEqual(3, decoded["b"]);
        }
Exemple #4
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);
        }