本文整理汇总了C#中BsonBinaryData类的典型用法代码示例。如果您正苦于以下问题:C# BsonBinaryData类的具体用法?C# BsonBinaryData怎么用?C# BsonBinaryData使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BsonBinaryData类属于命名空间,在下文中一共展示了BsonBinaryData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
示例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);
}
示例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);
}
示例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
}
}
}
示例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);
}
示例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);
}
示例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();
}
示例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
}
示例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);
}
示例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));
}
示例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>();
}
}
示例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));
}
示例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;
}
}
示例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.");
}
}
示例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.");
}
}