• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# BsonBinaryData类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中BsonBinaryData的典型用法代码示例。如果您正苦于以下问题:C# BsonBinaryData类的具体用法?C# BsonBinaryData怎么用?C# BsonBinaryData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



BsonBinaryData类属于命名空间,在下文中一共展示了BsonBinaryData类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: TestBsonBinaryDataEquals

 public void TestBsonBinaryDataEquals() {
     BsonBinaryData lhs = new BsonBinaryData(new byte[] { 1, 2, 3 }, BsonBinarySubType.Binary);
     BsonBinaryData rhs = new BsonBinaryData(new byte[] { 1, 2, 3 }, BsonBinarySubType.Binary);
     Assert.AreNotSame(lhs, rhs);
     Assert.AreEqual(lhs, rhs);
     Assert.AreEqual(lhs.GetHashCode(), rhs.GetHashCode());
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonEqualsTests.cs


示例2: TestMapBsonBinaryData

 public void TestMapBsonBinaryData() {
     var value = new BsonBinaryData(new byte[] { 1, 2, 3 });
     var bsonValue = (BsonBinaryData) BsonTypeMapper.MapToBsonValue(value);
     Assert.AreSame(value, bsonValue);
     var bsonBinary = (BsonBinaryData) BsonTypeMapper.MapToBsonValue(value, BsonType.Binary);
     Assert.AreSame(value, bsonBinary);
 }
开发者ID:simi--,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonTypeMapperTests.cs


示例3: TestBsonBinaryDataEquals

        public void TestBsonBinaryDataEquals()
        {
            var a = new BsonBinaryData(new byte[] { 1, 2, 3 });
            var b = new BsonBinaryData(new byte[] { 1, 2, 3 });
            var c = new BsonBinaryData(new byte[] { 2, 3, 4 });
            var n = (BsonBinaryData)null;

            Assert.IsTrue(object.Equals(a, b));
            Assert.IsFalse(object.Equals(a, c));
            Assert.IsFalse(object.Equals(a, BsonNull.Value));
            Assert.IsFalse(a.Equals(n));
            Assert.IsFalse(a.Equals(null));

            Assert.IsTrue(a == b);
            Assert.IsFalse(a == c);
            Assert.IsFalse(a == BsonNull.Value);
            Assert.IsFalse(a == null);
            Assert.IsFalse(null == a);
            Assert.IsTrue(n == null);
            Assert.IsTrue(null == n);

            Assert.IsFalse(a != b);
            Assert.IsTrue(a != c);
            Assert.IsTrue(a != BsonNull.Value);
            Assert.IsTrue(a != null);
            Assert.IsTrue(null != a);
            Assert.IsFalse(n != null);
            Assert.IsFalse(null != n);
        }
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:29,代码来源:BsonValueEqualsTests.cs


示例4: BsonBinaryReader_should_support_reading_more_than_2GB

        public void BsonBinaryReader_should_support_reading_more_than_2GB()
        {
            RequireEnvironmentVariable.IsDefined("EXPLICIT");

            var binaryData = new BsonBinaryData(new byte[1024 * 1024]);

            var tempFileName = Path.GetTempFileName();
            try
            {
                using (var stream = new FileStream(tempFileName, FileMode.Open))
                {
                    using (var binaryWriter = new BsonBinaryWriter(stream))
                    {
                        while (stream.Position < (long)int.MaxValue * 4)
                        {
                            binaryWriter.WriteStartDocument();
                            binaryWriter.WriteName("x");
                            binaryWriter.WriteBinaryData(binaryData);
                            binaryWriter.WriteEndDocument();
                        }
                    }

                    var endOfFilePosition = stream.Position;
                    stream.Position = 0;

                    using (var binaryReader = new BsonBinaryReader(stream))
                    {
                        while (!binaryReader.IsAtEndOfFile())
                        {
                            binaryReader.ReadStartDocument();
                            var bookmark = binaryReader.GetBookmark();

                            binaryReader.ReadName("x");
                            binaryReader.ReturnToBookmark(bookmark);

                            binaryReader.ReadName("x");
                            var readBinaryData = binaryReader.ReadBinaryData();
                            Assert.Equal(binaryData.Bytes.Length, readBinaryData.Bytes.Length);

                            binaryReader.ReadEndDocument();
                        }
                    }

                    Assert.Equal(endOfFilePosition, stream.Position);
                }
            }
            finally
            {
                try
                {
                    File.Delete(tempFileName);
                }
                catch
                {
                    // ignore exceptions
                }
            }
        }
开发者ID:RavenZZ,项目名称:MDRelation,代码行数:58,代码来源:BsonBinaryReaderTests.cs


示例5: TestGuidJavaLegacy

 public void TestGuidJavaLegacy() {
     var guid = new Guid("01020304-0506-0708-090a-0b0c0d0e0f10");
     var binaryData = new BsonBinaryData(guid, GuidRepresentation.JavaLegacy);
     var expected = new byte[] { 8, 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, 13, 12, 11, 10, 9 };
     Assert.IsTrue(expected.SequenceEqual(binaryData.Bytes));
     Assert.AreEqual(BsonBinarySubType.UuidLegacy, binaryData.SubType);
     Assert.AreEqual(GuidRepresentation.JavaLegacy, binaryData.GuidRepresentation);
     Assert.AreEqual(guid, binaryData.AsGuid);
     Assert.AreEqual(guid, binaryData.RawValue);
 }
开发者ID:redforks,项目名称:mongo-csharp-driver,代码行数:10,代码来源:BsonBinaryDataTests.cs


示例6: TestGuidBigEndian

 public void TestGuidBigEndian() {
     var guid = new Guid("01020304-0506-0708-090a-0b0c0d0e0f10");
     var binaryData = new BsonBinaryData(guid, GuidByteOrder.BigEndian);
     var expected = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
     Assert.IsTrue(expected.SequenceEqual(binaryData.Bytes));
     Assert.AreEqual(BsonBinarySubType.Uuid, binaryData.SubType);
     Assert.AreEqual(GuidByteOrder.BigEndian, binaryData.GuidByteOrder);
     Assert.AreEqual(guid, binaryData.AsGuid);
     Assert.AreEqual(guid, binaryData.RawValue);
 }
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:10,代码来源:BsonBinaryDataTests.cs


示例7: WriteBinaryData

        /// <summary>
        /// Writes BSON binary data to the writer.
        /// </summary>
        /// <param name="binaryData">The binary data.</param>
        public override void WriteBinaryData(BsonBinaryData binaryData)
        {
            if (Disposed) { throw new ObjectDisposedException("BsonDocumentWriter"); }
            if (State != BsonWriterState.Value)
            {
                ThrowInvalidState("WriteBinaryData", BsonWriterState.Value);
            }

            WriteValue(binaryData);
            State = GetNextState();
        }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:15,代码来源:BsonDocumentWriter.cs


示例8: TestGuidPythonLegacy

        public void TestGuidPythonLegacy()
        {
            var guid = new Guid("01020304-0506-0708-090a-0b0c0d0e0f10");
            var binaryData = new BsonBinaryData(guid, GuidRepresentation.PythonLegacy);
            var expected = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };
            Assert.IsTrue(expected.SequenceEqual(binaryData.Bytes));
            Assert.AreEqual(BsonBinarySubType.UuidLegacy, binaryData.SubType);
            Assert.AreEqual(GuidRepresentation.PythonLegacy, binaryData.GuidRepresentation);
            Assert.AreEqual(guid, binaryData.AsGuid);
#pragma warning disable 618
            Assert.AreEqual(guid, binaryData.RawValue);
#pragma warning restore
        }
开发者ID:Bogdan0x400,项目名称:mongo-csharp-driver,代码行数:13,代码来源:BsonBinaryDataTests.cs


示例9: Session

        public Session(string id, string applicationName, int timeout, BsonBinaryData sessionItems, int sessionItemsCount, SessionStateActions actionFlags)
        {
            DateTime now = DateTime.Now;

            SessionID = id;
            ApplicationName = applicationName;
            LockDate = now;
            LockID = 0;
            Timeout = timeout;
            Locked = false;
            SessionItems = sessionItems;
            SessionItemsCount = sessionItemsCount;
            Flags = (int)actionFlags;
            Created = now;
            Expires = now.AddMinutes((Double)this.Timeout);
        }
开发者ID:paralect,项目名称:MongoSessionStore,代码行数:16,代码来源:Session.cs


示例10: TestBsonBinaryData

 public void TestBsonBinaryData() {
     var value = new BsonBinaryData(new byte[] { 1, 2 });
     Assert.Throws<InvalidCastException>(() => Convert.ToBoolean(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToByte(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToChar(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToDateTime(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToDecimal(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToDouble(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToInt16(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToInt32(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToInt64(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToSByte(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToSingle(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToString(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToUInt16(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToUInt32(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToUInt64(value));
 }
开发者ID:oskysal,项目名称:mongo-csharp-driver,代码行数:18,代码来源:BsonValueIConvertibleTests.cs


示例11: BackpatchSize_should_throw_when_size_is_larger_than_2GB

        public void BackpatchSize_should_throw_when_size_is_larger_than_2GB()
        {
            using (var stream = new NullBsonStream())
            using (var binaryWriter = new BsonBinaryWriter(stream))
            {
                var bytes = new byte[int.MaxValue / 2]; // 1GB
                var binaryData = new BsonBinaryData(bytes);

                binaryWriter.WriteStartDocument();
                binaryWriter.WriteName("array");
                binaryWriter.WriteStartArray();
                binaryWriter.WriteBinaryData(binaryData);
                binaryWriter.WriteBinaryData(binaryData);

                Action action = () => binaryWriter.WriteEndArray(); // indirectly calls private BackpatchSize method

                action.ShouldThrow<FormatException>();
            }
        }
开发者ID:narutoswj,项目名称:mongo-csharp-driver,代码行数:19,代码来源:BsonBinaryWriterTests.cs


示例12: TestBsonBinaryData

 public void TestBsonBinaryData()
 {
     var value = new BsonBinaryData(new byte[] { 1, 2 });
     Assert.AreSame(value, ((IConvertible)value).ToType(typeof(object), null));
     Assert.Throws<InvalidCastException>(() => Convert.ToBoolean(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToByte(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToChar(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToDateTime(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToDecimal(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToDouble(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToInt16(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToInt32(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToInt64(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToSByte(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToSingle(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToString(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToUInt16(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToUInt32(value));
     Assert.Throws<InvalidCastException>(() => Convert.ToUInt64(value));
 }
开发者ID:niemyjski,项目名称:mongo-csharp-driver,代码行数:20,代码来源:BsonValueIConvertibleTests.cs


示例13: CreateUninitializedItem

 public override void CreateUninitializedItem(HttpContext context, string id, int timeout)
 {
     byte[] serializedItems = new byte[0];
     BsonBinaryData sessionItems = new BsonBinaryData(serializedItems);
     Session session = new Session(id, this._applicationName, timeout, sessionItems, 0, SessionStateActions.InitializeItem);
     var sessionStore = new SessionStore(_applicationName, _connectionString);
     try
     {
         sessionStore.Insert(session);
     }
     catch (Exception e)
     {
         if (WriteExceptionsToEventLog)
         {
             WriteToEventLog(e, "CreateUninitializedItem");
             throw new ProviderException(e.Message, e.InnerException);
         }
         else
             throw e;
     }
 }
开发者ID:paralect,项目名称:MongoSessionStore,代码行数:21,代码来源:MongoSessionStoreProvider.cs


示例14: saveScript_Click

        private void saveScript_Click(object sender, EventArgs e) {
            if (!IsEmpty(scriptIdValue.Text) && !IsEmpty(scriptValue.Text) && !ScriptError) {
                byte[] scriptBytes = System.Text.Encoding.ASCII.GetBytes(scriptValue.Text);

                BsonBinaryData scriptArray = new BsonBinaryData(scriptBytes);
                
                BsonDocument doc = new BsonDocument();
                doc.Add("_id", scriptIdValue.Text);
                doc.Add(new BsonElement("Bytes", scriptArray.AsBsonValue));
                    
                

                MongoCollection collection = MongoUtils.MongoData.GetCollection("Scripts", (string)scriptTypesValue.SelectedItem);
                collection.Save(doc);
                
                scriptValidatedValue.Visible = false;
            }
            else if (ScriptError) {
                DisplayErrorBox("Script file contains errors.  Test script before saving.");
            }
        }
开发者ID:vadian,项目名称:Novus,代码行数:21,代码来源:ScriptsTab.cs


示例15: saveScript_Click

        private async void saveScript_Click(object sender, EventArgs e) {
            if (!IsEmpty(scriptIdValue.Text) && !IsEmpty(scriptValue.Text) && !ScriptError) {
                byte[] scriptBytes = System.Text.Encoding.ASCII.GetBytes(scriptValue.Text);

                BsonBinaryData scriptArray = new BsonBinaryData(scriptBytes);

                Triggers.Script newScript = new LuaScript() {
                    ID = scriptIdValue.Text,
                    ScriptByteArray = scriptBytes,
                    ScriptType = (ScriptTypes)Enum.Parse(typeof(ScriptTypes), scriptTypeValue.SelectedItem.ToString())
                };

                var collection = MongoUtils.MongoData.GetCollection<Triggers.Script>("Scripts", (string)scriptTypesValue.SelectedItem);
                await collection.ReplaceOneAsync<Triggers.Script>(s => s.ID == scriptIdValue.Text, newScript, new UpdateOptions { IsUpsert = true });
                
                scriptValidatedValue.Visible = false;
            }
            else if (ScriptError) {
                DisplayErrorBox("Script file contains errors.  Test script before saving.");
            }
        }
开发者ID:jandar78,项目名称:Novus,代码行数:21,代码来源:ScriptsTab.cs


示例16: SaveChunk

        private void SaveChunk()
        {
            var lastChunkIndex = (int) ((length + fileInfo.ChunkSize - 1) / fileInfo.ChunkSize) - 1;
            if (chunkIndex == -1 || chunkIndex > lastChunkIndex) {
                var message = string.Format("Invalid chunk index: {0}", chunkIndex);
                throw new MongoGridFSException(message);
            }

            var lastChunkSize = (int) (length % fileInfo.ChunkSize);
            if (lastChunkSize == 0) {
                lastChunkSize = fileInfo.ChunkSize;
            }

            BsonBinaryData data;
            if (chunkIndex < lastChunkIndex || lastChunkSize == fileInfo.ChunkSize) {
                data = new BsonBinaryData(chunk);
            } else {
                var lastChunk = new byte[lastChunkSize];
                Buffer.BlockCopy(chunk, 0, lastChunk, 0, lastChunkSize);
                data = new BsonBinaryData(lastChunk);
            }

            var query = Query.EQ("_id", chunkId);
            var update = new UpdateDocument {
                { "_id", chunkId },
                { "files_id", fileInfo.Id },
                { "n", chunkIndex },
                { "data", data }
            };
            gridFS.Chunks.Update(query, update, UpdateFlags.Upsert);
            chunkIsDirty = false;
        }
开发者ID:kolupaev,项目名称:mongo-csharp-driver,代码行数:32,代码来源:MongoGridFSStream.cs


示例17: WriteBinaryData

 /// <summary>
 /// Writes a BSON binary data element to the writer.
 /// </summary>
 /// <param name="name">The name of the element.</param>
 /// <param name="binaryData">The binary data.</param>
 public void WriteBinaryData(string name, BsonBinaryData binaryData)
 {
     WriteName(name);
     WriteBinaryData(binaryData);
 }
开发者ID:einaregilsson,项目名称:mongo-csharp-driver,代码行数:10,代码来源:BsonWriter.cs


示例18: WriteBinaryData

 public void WriteBinaryData(BsonBinaryData value)
 {
     SetWriteState(Newtonsoft.Json.JsonToken.Bytes, null);
     _wrappedWriter.WriteBinaryData(value);
 }
开发者ID:rstam,项目名称:mongo-csharp-driver-jsondotnet-original,代码行数:5,代码来源:JsonWriterAdapter.cs


示例19: TestClass

 public TestClass(
     BsonBinaryData value
 )
 {
     this.B = value;
     this.V = value;
 }
开发者ID:vshlos,项目名称:mongo-csharp-driver,代码行数:7,代码来源:BsonValueSerializerTests.cs


示例20: WriteBinaryData_should_have_expected_result

        public void WriteBinaryData_should_have_expected_result()
        {
            var subject = CreateSubject();
            var value = new BsonBinaryData(new byte[] { 0 }, BsonBinarySubType.UserDefined);

            WriteNested(subject, () => subject.WriteBinaryData(value));

            AssertBsonEquals(subject, "{ x : { $binary : \"AA==\", $type : \"80\" } }");
        }
开发者ID:rstam,项目名称:mongo-csharp-driver-jsondotnet-original,代码行数:9,代码来源:JsonWriterAdapterTests.cs



注:本文中的BsonBinaryData类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# BsonBinarySubType类代码示例发布时间:2022-05-24
下一篇:
C# BsonArray类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap