override public void SetCapacity(int capacity) { SqlBinary[] newValues = new SqlBinary[capacity]; if (null != values) { Array.Copy(values, 0, newValues, 0, Math.Min(capacity, values.Length)); } values = newValues; }
public static SqlString ComputeMD5AsBase64(SqlBinary byteArray) { if (byteArray.IsNull) return SqlString.Null; System.Security.Cryptography.MD5 sscMD5 = System.Security.Cryptography.MD5.Create(); byte[] mHash = sscMD5.ComputeHash(byteArray.Value); return Convert.ToBase64String(mHash); }
public static SqlString AAM(SqlBinary reaction, SqlString options, SqlString bingo_schema) { using (SqlConnection conn = new SqlConnection("context connection=true")) { conn.Open(); prepareContext(conn, bingo_schema.Value, 0, 0); } return new SqlString(BingoCore.ringoAAM(reaction.Value, options.Value)); }
public static SqlString ExtractString(SqlBinary binary) { using (var decompressed = new MemoryStream(binary.Value)) { using (var stream = ExtractStream(decompressed)) { return MemoryStreamToString(stream as MemoryStream, Encoding.UTF8); } } }
public static SqlString AAM(SqlBinary reaction, SqlString options, SqlString bingo_schema) { ContextFlags flags = ContextFlags.X_PSEUDO | ContextFlags.IGNORE_CBDM; using (SqlConnection conn = new SqlConnection("context connection=true")) { conn.Open(); prepareContext(conn, bingo_schema.Value, 0, flags); } return new SqlString(BingoCore.ringoAAM(reaction.Value, options.Value)); }
internal static SqlParameter AddInParameterExactSized(this SqlCommand cmd, string name, SqlBinary value) { var prm = cmd.CreateParameter(); prm.Direction = ParameterDirection.Input; prm.ParameterName = name; prm.SqlDbType = SqlDbType.Binary; prm.SqlValue = value; prm.Size = value.Length; cmd.Parameters.Add(prm); return prm; }
public override object ConvertXmlToObject(string s) { SqlBinary binary = new SqlBinary(); StringReader input = new StringReader("<col>" + s + "</col>"); IXmlSerializable serializable = binary; using (XmlTextReader reader = new XmlTextReader(input)) { serializable.ReadXml(reader); } return new SqlBytes((SqlBinary) serializable); }
public SqlBytes (SqlBinary value) { if (value.IsNull) { notNull = false; buffer = null; } else { notNull = true; buffer = value.Value; storage = StorageState.Buffer; } }
public static SqlString ExtractStringWithEncoding(SqlBinary binary, string encodingName) { using (var decompressed = new MemoryStream(binary.Value)) { using (var stream = ExtractStream(decompressed)) { if (encodingName == string.Empty || encodingName == null) encodingName = "utf-8"; return MemoryStreamToString(stream as MemoryStream, Encoding.GetEncoding(encodingName)); } } }
public static SqlString CanSmiles(SqlBinary molecule, SqlString bingo_schema) { using (BingoSession session = new BingoSession()) { using (SqlConnection conn = new SqlConnection("context connection=true")) { conn.Open(); prepareContext(conn, bingo_schema.Value, 0, 0); } return BingoCore.mangoSMILES(molecule.Value, true); } }
// Compares this instance with a specified object /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override bool Equals(Object value) { if (!(value is SqlBinary)) { return(false); } SqlBinary i = (SqlBinary)value; if (i.IsNull || IsNull) { return(i.IsNull && IsNull); } else { return((this == i).Value); } }
public SqlBinaryTest() { byte[] b1 = new byte[2]; byte[] b2 = new byte[3]; byte[] b3 = new byte[2]; b1[0] = 240; b1[1] = 15; b2[0] = 10; b2[1] = 10; b2[2] = 10; b3[0] = 240; b3[1] = 15; _test1 = new SqlBinary(b1); _test2 = new SqlBinary(b2); _test3 = new SqlBinary(b3); }
public void GetReady() { byte [] b1 = new Byte [2]; byte [] b2 = new Byte [3]; byte [] b3 = new Byte [2]; b1 [0] = 240; b1 [1] = 15; b2 [0] = 10; b2 [1] = 10; b2 [2] = 10; b3 [0] = 240; b3 [1] = 15; Test1 = new SqlBinary(b1); Test2 = new SqlBinary(b2); Test3 = new SqlBinary(b3); }
protected void Page_Load(object sender, EventArgs e) { Response.Buffer = true; Response.ContentType = "image/gif"; System.Data.SqlTypes.SqlBinary bmpBytes = Employee.GetEmployeeByEmployeeId(Int32.Parse(Request["ImageBinary"], System.Globalization.CultureInfo.CurrentCulture.NumberFormat)).Photo; if ((!bmpBytes.IsNull)) { byte[] bytearray = (byte[])bmpBytes; Response.BinaryWrite(bytearray); } else { System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/image/noimage.gif")); MemoryStream ms = new MemoryStream(); img.Save(ms, System.Drawing.Imaging.ImageFormat.Gif); Response.BinaryWrite(ms.ToArray()); } }
private static SqlInt32 _Match (SqlBinary target, SqlString query, SqlString options, SqlString bingo_schema, string search_type, bingoCallback prepare_match, bingoCallback process_matched) { using (BingoSession sessions = new BingoSession()) { ContextFlags flags = 0; if (options.Value.Contains("TAU")) flags |= ContextFlags.TAU_RULES; if (search_type == "SIM") flags |= ContextFlags.FINGERPRINTS; using (SqlConnection conn = new SqlConnection("context connection=true")) { conn.Open(); prepareContext(conn, bingo_schema.Value, 0, flags); } int res = BingoCore.lib.mangoSetupMatch(search_type, query.Value, options.Value); if (res < 0) throw new Exception(BingoCore.lib.bingoGetError()); if (prepare_match != null) prepare_match(); res = BingoCore.lib.mangoMatchTarget(target.Value, target.Value.Length); if (res == -2) throw new Exception(BingoCore.lib.bingoGetError()); if (res == -1) { // can not use SqlContext.Pipe from inside the function, // so just returning NULL without printing the error message return SqlInt32.Null; } if (res == 1 && process_matched != null) process_matched(); return new SqlInt32(res); } }
public bool equals(Object obj) { if (obj == null) { return(false); } if (obj is SqlBinary) { SqlBinary o = (SqlBinary)obj; if (IsNull && o.IsNull) { return(true); } if (IsNull || o.IsNull) { return(false); } if (_value.Length != o._value.Length) { return(false); } for (int i = 0; i < _value.Length; i++) { if (_value[i] != o._value[i]) { return(false); } } return(true); } return(false); }
public int CompareTo(SqlBinary value) { // If both Null, consider them equal. // Otherwise, Null is less than anything. if (IsNull) { return(value.IsNull ? 0 : -1); } else if (value.IsNull) { return(1); } if (this < value) { return(-1); } if (this > value) { return(1); } return(0); }
public int CompareTo(SqlBinary value) { if (this.IsNull) { if (!value.IsNull) { return(-1); } return(0); } if (value.IsNull) { return(1); } if (SqlBoolean.op_True(this < value)) { return(-1); } if (SqlBoolean.op_True(this > value)) { return(1); } return(0); }
// For hashing purpose /// <devdoc> /// <para>[To be supplied.]</para> /// </devdoc> public override int GetHashCode() { if (IsNull) { return(0); } byte[] rgbSortKey; if (FBinarySort()) { rgbSortKey = x_UnicodeEncoding.GetBytes(_value.TrimEnd()); } else { // VSDevDiv 479660 // GetHashCode should not throw just because this instance has an invalid LCID or compare options. CompareInfo cmpInfo; CompareOptions options; try { SetCompareInfo(); cmpInfo = _cmpInfo; options = CompareOptionsFromSqlCompareOptions(_flag); } catch (ArgumentException) { // SetCompareInfo throws this when instance's LCID is unsupported // CompareOptionsFromSqlCompareOptions throws this when instance's options are invalid cmpInfo = CultureInfo.InvariantCulture.CompareInfo; options = CompareOptions.None; } return(cmpInfo.GetHashCode(_value.TrimEnd(), options)); } return(SqlBinary.HashByteArray(rgbSortKey, rgbSortKey.Length)); }
public static SqlSingle Mass (SqlBinary molecule, SqlString type, SqlString bingo_schema) { using (BingoSession session = new BingoSession()) { using (SqlConnection conn = new SqlConnection("context connection=true")) { conn.Open(); prepareContext(conn, bingo_schema.Value, 0, 0); } float mass; int ret = BingoCore.lib.mangoMass(molecule.Value, molecule.Value.Length, type.Value, out mass); if (ret != 1) return SqlSingle.Null; return mass; } }
public static SqlGuid op_Explicit(SqlBinary x) { return(new SqlGuid(x.Value)); }
public static byte[] op_Explicit(SqlBinary x) { return(x.Value); }
static SqlBinary() { Null = new SqlBinary(true); }
public static SqlInt32 Exact (SqlBinary target, SqlString query, SqlString options, SqlString bingo_schema) { return _Match(target, query, options, bingo_schema, "EXACT", null, null); }
public static SqlInt32 RSMARTS (SqlBinary target, SqlString query, SqlString bingo_schema) { string highlighting = null; return _RMatch(target, query, "", bingo_schema, "RSMARTS", false, ref highlighting); }
public static SqlInt32 RExact (SqlBinary target, SqlString query, SqlString options, SqlString bingo_schema) { string highlighting = null; return _RMatch(target, query, options, bingo_schema, "REXACT", false, ref highlighting); }
public static SqlBoolean op_LessThanOrEqual(SqlBinary x, SqlBinary y) { return(LessThanOrEqual(x, y)); }
// Alternative method for operator < public static SqlBoolean LessThan(SqlBinary x, SqlBinary y) { return(x < y); }
internal static void SetSqlBinary( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData, SqlBinary value ) { ThrowIfInvalidSetterAccess( metaData, ExtendedClrTypeCode.SqlBinary ); SetSqlBinary_LengthChecked( sink, setters, ordinal, metaData, value, 0 ); }
private static void SetSqlBinary_Unchecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SqlBinary value, int offset, int length ) { if ( value.IsNull ) { setters.SetDBNull( sink, ordinal ); } else { SetByteArray_Unchecked( sink, setters, ordinal, value.Value, offset, length ); } sink.ProcessMessagesAndThrow(); }
// Create a SqlBytes from a SqlBinary public SqlBytes(SqlBinary value) : this(value.IsNull ? (byte[])null : value.Value) { }
public void SetSqlBinary (int i, SqlBinary value) { throw new NotImplementedException (); }
public static SqlBoolean op_GreaterThanOrEqual(SqlBinary x, SqlBinary y) { return(GreaterThanOrEqual(x, y)); }
public static SqlString Name(SqlBinary molecule, SqlString bingo_schema) { using (BingoSession session = new BingoSession()) { return BingoCore.bingoGetNameCore(molecule.Value); } }
// Alternative method for operator > public static SqlBoolean GreaterThan(SqlBinary x, SqlBinary y) { return(x > y); }
public static int GetBondCount (SqlBinary molecule, SqlString bingo_schema) { using (BingoSession session = new BingoSession()) { return BingoCore.lib.mangoGetBondCount(molecule.Value, molecule.Value.Length); } }
// Alternative method for operator <= public static SqlBoolean LessThanOrEqual(SqlBinary x, SqlBinary y) { return(x <= y); }
public static SqlString RSMARTSHi (SqlBinary target, SqlString query, SqlString bingo_schema) { string highlighting = null; _RMatch(target, query, "", bingo_schema, "RSMARTS", true, ref highlighting); return highlighting; }
// Alternative method for operator >= public static SqlBoolean GreaterThanOrEqual(SqlBinary x, SqlBinary y) { return(x >= y); }
public static SqlString CheckMolecule (SqlBinary molecule, SqlString bingo_schema) { using (SqlConnection conn = new SqlConnection("context connection=true")) { conn.Open(); prepareContext(conn, bingo_schema.Value, 0, 0); } string res = BingoCore.checkMolecule(molecule.Value); if (res == null) return SqlString.Null; return new SqlString(res); }
public static SqlBoolean op_Inequality(SqlBinary x, SqlBinary y) { return(NotEquals(x, y)); }
public static SqlInt32 SMARTS (SqlBinary target, SqlString query, SqlString options, SqlString bingo_schema) { return _Match(target, query, options, bingo_schema, "SMARTS", null, null); }
public static SqlBinary op_Addition(SqlBinary x, SqlBinary y) { throw new NotImplementedException("The method op_Addition in class SqlBinary is not supported"); }
private static string MatchWithHighlighting (SqlBinary target, SqlString query, SqlString parameters, SqlString bingo_schema, string search_type) { string highlighting = null; bingoCallback prepare = () => { BingoCore.lib.mangoSetHightlightingMode(1); }; bingoCallback handle = () => { highlighting = BingoCore.mangoGetHightlightedMolecule(); }; _Match(target, query, parameters, bingo_schema, search_type, prepare, handle); return highlighting; }
// Create a SqlBytes from a SqlBinary public SqlBytes(SqlBinary value) : this(value.IsNull ? null : value.Value !) { }
/// <summary> /// TBD is this method calling itself when using this.Write iso base.Write ??? /// </summary> /// <param name="b"></param> public void Write(SqlBinary b) { short l = (short) b.Value.Length; this.Write(l); base.Write(b.Value); }
//-------------------------------------------------- // Alternative methods for overloaded operators //-------------------------------------------------- // Alternative method for operator + public static SqlBinary Add(SqlBinary x, SqlBinary y) { return(x + y); }
public static void ssb_create_certificate_from_blob( SqlString dbName, SqlString certName, SqlString userName, SqlBinary blob) { SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder(); scsb.ContextConnection = true; SqlConnection connection = new SqlConnection(scsb.ConnectionString); connection.Open(); using (connection) { connection.ChangeDatabase(dbName.Value); string tempPath = Path.GetTempPath(); string certFile = Path.Combine( tempPath, Path.GetRandomFileName()); try { if (false == Directory.Exists(tempPath)) { Directory.CreateDirectory(tempPath); } File.WriteAllBytes(certFile, blob.Value); SqlCommand cmd = new SqlCommand( String.Format( @"CREATE CERTIFICATE [{0}] AUTHORIZATION [{1}] FROM FILE = '{2}';", certName.Value.Replace("]", "]]"), userName.Value.Replace("]", "]]"), certFile), connection); cmd.ExecuteNonQuery(); } finally { if (File.Exists(certFile)) { try { File.Delete(certFile); } catch (IOException) { } } } } }
public static SqlBinary Concat(SqlBinary x, SqlBinary y) { return(x + y); }
private static void SetSqlBinary_LengthChecked( SmiEventSink_Default sink, ITypedSettersV3 setters, int ordinal, SmiMetaData metaData, SqlBinary value, int offset ) { int length = 0; if ( !value.IsNull ) { length = CheckXetParameters( metaData.SqlDbType, metaData.MaxLength, NoLengthLimit /* actual */, 0, value.Length, offset, value.Length - offset ); Debug.Assert( length >= 0, "value.Length was invalid!" ); } SetSqlBinary_Unchecked( sink, setters, ordinal, value, offset, length ); }
// Alternative method for operator == public static SqlBoolean Equals(SqlBinary x, SqlBinary y) { return(x == y); }
public SqlBinary Adjust(SqlBinary value) { if (SqlDbType.Binary == SqlDbType || SqlDbType.Timestamp == SqlDbType) { if (!value.IsNull) { // Pad fixed-length types if (value.Length < MaxLength) { byte[] rgbValue = value.Value; byte[] rgbNewValue = new byte[MaxLength]; Buffer.BlockCopy(rgbValue, 0, rgbNewValue, 0, rgbValue.Length); Array.Clear(rgbNewValue, rgbValue.Length, rgbNewValue.Length - rgbValue.Length); return new SqlBinary(rgbNewValue); } } } else if (SqlDbType.VarBinary != SqlDbType && SqlDbType.Image != SqlDbType) ThrowInvalidType(); // Handle null values if (value.IsNull) { return value; } // trim all types if (value.Length > MaxLength && Max != MaxLength) { byte[] rgbValue = value.Value; byte[] rgbNewValue = new byte[MaxLength]; Buffer.BlockCopy(rgbValue, 0, rgbNewValue, 0, (int)MaxLength); value = new SqlBinary(rgbNewValue); } return value; }
// Alternative method for operator != public static SqlBoolean NotEquals(SqlBinary x, SqlBinary y) { return(x != y); }