本文整理汇总了C#中Binary类的典型用法代码示例。如果您正苦于以下问题:C# Binary类的具体用法?C# Binary怎么用?C# Binary使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Binary类属于命名空间,在下文中一共展示了Binary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CanCompareToOtherBytes
public void CanCompareToOtherBytes()
{
var lhs = new Binary(new Byte[] { 1, 2, 3 });
var rhs = new Binary(new Byte[] { 1, 2, 3 });
Assert.Equal(0, lhs.CompareTo(rhs));
}
示例2: CanSerializeToBson
public void CanSerializeToBson()
{
var binary = new Binary(Guid.Parse("a6c45a28-c572-4d5b-ac18-7b0ec2d723fb").ToByteArray());
var bson = WriteBson(new BinaryContainer { Value = binary });
Validate(bson, "IQAAAAVWYWx1ZQAQAAAAAChaxKZyxVtNrBh7DsLXI/sA");
}
示例3: WrapUnderlyingBytes
public void WrapUnderlyingBytes()
{
var rawBytes = new Byte[0];
var bytes = new Binary(rawBytes);
Assert.Same(rawBytes, (Byte[])bytes);
}
示例4: CanCompareToBoxedRawBytes
public void CanCompareToBoxedRawBytes()
{
var lhs = new Binary(new Byte[] { 1, 2, 3 });
var rhs = new Byte[] { 1, 2, 3 };
Assert.Equal(0, lhs.CompareTo((Object)rhs));
}
示例5: CanBeCloned
public void CanBeCloned(){
var binarySource = new Binary(new byte[] {10, 20}, BinarySubtype.UserDefined);
var binaryDest = binarySource.Clone() as Binary;
Assert.IsNotNull(binaryDest);
Assert.AreEqual(binarySource.Bytes,binaryDest.Bytes);
Assert.AreEqual(binarySource.Subtype,binaryDest.Subtype);
}
示例6: TestUpdates
public void TestUpdates()
{
SessionStateItemCollection items = new SessionStateItemCollection();
items["Val1"] = "value";
byte[] serializedItems = Serialize(items);
Binary b = new Binary(serializedItems);
List<string> ids = new List<string>();
ICursor allSessions;
using (var mongo = new Mongo(config))
{
mongo.Connect();
allSessions = mongo["session_store"]["sessions"].FindAll();
foreach (Document session in allSessions.Documents)
{
string id = (string)session["SessionId"];
ids.Add(id);
}
}
foreach (string s in ids)
{
var sessionStore = new SessionStore("test");
sessionStore.UpdateSession(s, 2, b, "AppName", items.Count, 0);
}
}
示例7: SaveMacroPlanTest
public void SaveMacroPlanTest(string imagepath)
{
//assign
var shapemodelpath = "filepath";
var note = "note";
var exportUnit = "mm";
var image = new HImage(imagepath);
var imageBinData = new Binary(ImageConventer.ConvertHalconImageToByteArray(image, false));
var matchingParam = new MatchingParam();
var matchingParamByteArray = ModelSerializer.DoSerialize(matchingParam);
var matchingParamBinData = new Binary(matchingParamByteArray);
BindingList<GeoDataGridViewModel> a = new BindingList<GeoDataGridViewModel>();
a.Add(new GeoDataGridViewModel() { RecordID = "aaa" });
var measureBinData = ModelSerializer.DoSerialize(a);
//BindingList a;
var ma = new MeasureAssistant();
var maParam = ma.GetMeasureAssistantParam();
var maParamBin = ModelSerializer.DoSerialize(maParam);
LightChannel upper = new LightChannel() { Channel = "00", Intensity = 100, OnOff = LightSwitch.On };
LightChannel bottom = new LightChannel() { Channel = "01", Intensity = 200, OnOff = LightSwitch.OFF };
//act
var success = SDMSRepo.SaveMacroPlan("Test", Guid.NewGuid().ToString(), shapemodelpath, note, imageBinData, exportUnit, matchingParamBinData, measureBinData, maParamBin, upper, bottom, new ShapeViewModel() { }, "system", "");
//assert
Assert.True(success);
}
示例8: CanDeserializeValidJson
public void CanDeserializeValidJson()
{
var expected = new Binary(Guid.Parse("a6c45a28-c572-4d5b-ac18-7b0ec2d723fb").ToByteArray());
var actual = ReadJson<Binary>("\"KFrEpnLFW02sGHsOwtcj+w==\"");
Assert.Equal(expected, actual);
}
示例9: ConvertBinaryToItemId
private string ConvertBinaryToItemId(Binary binary)
{
byte[] binaryString = binary.ToArray();
// if the original encoding was ASCII
string x = Encoding.ASCII.GetString(binaryString);
// if the original encoding was UTF-8
string y = Encoding.UTF8.GetString(binaryString);
// if the original encoding was UTF-16
string z = Encoding.Unicode.GetString(binaryString);
string strBinary = binary.ToString();
StringBuilder result = new StringBuilder(strBinary.Length / 8 + 1);
// TODO: check all 1's or 0's... Will throw otherwise
int mod4Len = binary.Length % 8;
if (mod4Len != 0)
{
// pad to length multiple of 8
strBinary = strBinary.PadLeft(((strBinary.Length / 8) + 1) * 8, '0');
}
for (int i = 0; i < binary.Length; i += 8)
{
string eightBits = strBinary.Substring(i, 8);
result.AppendFormat("{0:X2}", System.Convert.ToByte(eightBits, 2));
}
return result.ToString();
}
示例10: Load
public static UIConfig Load()
{
var cfg = XConfig.Current;
if (cfg.Extend.IsNullOrWhiteSpace()) return null;
Byte[] buf = null;
try
{
buf = cfg.Extend.ToBase64();
}
catch { return null; }
var ms = new MemoryStream(buf);
var binary = new Binary();
binary.EncodeInt = true;
binary.AddHandler<BinaryFont>(11);
binary.AddHandler<BinaryColor>(12);
binary.AddHandler<BinaryUnknown>(20);
binary.Stream = ms;
//binary.Debug = true;
//binary.EnableTrace();
try
{
return binary.Read(typeof(UIConfig)) as UIConfig;
}
catch { return null; }
}
示例11: Compile
internal Binary Compile()
{
//CSharpCompiler = new CSharpCodeProvider().CreateCompiler();
//parameters = new CompilerParameters();
//foreach (var require in Require) {
// parameters.ReferencedAssemblies.Add(string.Format("{0}.dll", require));
//}
//parameters.GenerateInMemory = true;
var compiler = CodeDomProvider.CreateProvider("CSharp");
var parameters = new CompilerParameters(Require.ToArray());
var codeUnit = new CodeCompileUnit();
codeNamespace = new CodeNamespace("Unahi.CRake.RuntimeGenerated");
codeUnit.Namespaces.Add(codeNamespace);
binary = new Binary();
foreach (var item in Imports) {
codeNamespace.Imports.Add(new CodeNamespaceImport(item));
}
CompileClass("", Tasks, Namespaces, null);
//CompileTasks(binary, "", Tasks, this, codeNamespace, null);
//CompileNamespaces(binary, "", Namespaces, codeNamespace, null);
binary.CompiledResult = compiler.CompileAssemblyFromDom(parameters, codeUnit);
return binary;
}
示例12: CanSerializeToJson
public void CanSerializeToJson()
{
var binary = new Binary(Guid.Parse("a6c45a28-c572-4d5b-ac18-7b0ec2d723fb").ToByteArray());
var json = WriteJson(binary);
Validate(json, "\"KFrEpnLFW02sGHsOwtcj+w==\"");
}
示例13: CanImplicitConvertedToBytes
public void CanImplicitConvertedToBytes(){
var bytes = new byte[]{10,12};
var binary = new Binary(bytes);
var converted = (byte[])binary;
Assert.IsNotNull(converted);
Assert.AreEqual(bytes, converted);
}
示例14: ToString
/// <summary>
/// Converts binary value to string.
/// </summary>
/// <param name="version">Binary version number.</param>
/// <returns>Base64 version number.</returns>
public static string ToString(Binary version)
{
if (version == null)
return null;
return Convert.ToBase64String(version.ToArray());
}
示例15: fluDocument_UploadedComplete
protected void fluDocument_UploadedComplete(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
{
if (this.fluDocument.HasFile)
{
if (this.fluDocument.PostedFile.ContentType.Equals("image/pjpeg") || this.fluDocument.PostedFile.ContentType.Equals("image/x-png"))
{
byte[] fileByte = this.fluDocument.FileBytes;
Binary binaryObj = new Binary(fileByte);
Ajancy.Kimia_Ajancy db = new Ajancy.Kimia_Ajancy(Public.ConnectionString);
Ajancy.Doument doc = db.Douments.FirstOrDefault<Ajancy.Doument>(d => d.PersonID == Public.ActiveUserRole.User.PersonID && d.DocumentType == 1);
if (doc == null)
{
doc = new Ajancy.Doument
{
DocumentType = Public.ToByte(this.drpType.SelectedValue),
PersonID = Public.ActiveUserRole.User.PersonID,
Picture = binaryObj,
SubmitDate = DateTime.Now
};
db.Douments.InsertOnSubmit(doc);
}
else
{
doc.Picture = binaryObj;
}
db.SubmitChanges();
db.Dispose();
}
}
}