public static SqlBoolean RegexMatch(SqlChars input, SqlString pattern, SqlInt32 timeout) { try { //var x = System.Text.RegularExpressions.MatchCollection var regex = new Regex(pattern.Value, Options, new TimeSpan(0, 0, 0, 0, timeout.Value)); return(regex.IsMatch(new string(input.Value))); } catch { return(false); } }
public void Read_NullBufferTest() { ExceptionAssert.Throws <ArgumentNullException>( delegate { char[] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }; SqlChars chars = new SqlChars(c1); char[] c2 = null; chars.Read(0, c2, 0, 10); Assert.Fail("#2 Should throw ArgumentNullException"); }); }
public static void Write(this BinaryWriter writer, SqlChars value) { if (writer == null) { throw new ArgumentNullException("writer"); } writer.Write(!value.IsNull); if (!value.IsNull) { writer.Write(value.Value); } }
public void Read_InvalidCountTest1() { ExceptionAssert.Throws <ArgumentOutOfRangeException>( delegate { char[] c1 = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j' }; SqlChars chars = new SqlChars(c1); char[] c2 = new char[5]; chars.Read(0, c2, 0, 10); Assert.Fail("#3 Should throw ArgumentOutOfRangeException"); }); }
public static SqlBoolean ContainsAny(SqlChars input, string search) { string strTemp = new string(input.Value); foreach (string item in search.Split(',')) { if (strTemp.Contains(item)) { return(true); } } return(false); }
private void WriteSyncLogs(IEnumerable <UserMessageBoxInfoRelation> logs) { // type=1的时候id是Tuhu_notification..MessageBoxMessageInfo的pkid type=2时id是Tuhu_notification..UserMessageBoxInfoRelation的pkid if (logs != null && logs.Any()) { Func <IEnumerable <int>, int, int> WriteLogs = (ids, type) => { if (ids != null && ids.Any()) { string sql = $@"INSERT INTO Tuhu_notification..ExpiredMessageBoxInfo ( ID , Type , CreateDateTime , LastUpdateDateTime ) SELECT ss.TargetID , {type} , GETDATE() , GETDATE() FROM @TVP AS ss;"; using (var helper = DbHelper.CreateLogDbHelper()) { using (var cmd = new SqlCommand(sql)) { cmd.CommandType = CommandType.Text; var records = new List <SqlDataRecord>(ids.Count()); foreach (var target in ids) { var record = new SqlDataRecord(new SqlMetaData("TargetID", SqlDbType.Char, 40)); var chars = new SqlChars(target.ToString()); record.SetSqlChars(0, chars); records.Add(record); } SqlParameter p = new SqlParameter("@TVP", SqlDbType.Structured); p.TypeName = "dbo.Target"; p.Value = records; cmd.Parameters.Add(p); return(helper.ExecuteNonQuery(cmd)); } } } return(0); }; var messageids = logs.Select(x => x.MessageID).Distinct(); var relationids = logs.Select(x => x.PKID); var messageresult = WriteLogs(messageids, 1); Logger.Info($"写过期消息{messageresult}个"); var relationresult = WriteLogs(relationids, 2); Logger.Info($"写过期消息关系{relationresult}个"); } }
/// <summary> /// Extends Write so that buffer offset of 0 and call to Array.Length are not needed. /// <example> /// sqlchars.Write(offset, buffer); /// </example> /// </summary> public static void Write(this SqlChars sqlchars, Int64 offset, Char[] buffer) { if (sqlchars == null) { throw new ArgumentNullException("sqlchars"); } if (buffer == null) { throw new ArgumentNullException("buffer"); } sqlchars.Write(offset, buffer, 0, buffer.Length); }
public void SqlCharsSetLength() { char[] b1 = new char[10]; SqlChars chars = new SqlChars(); Assert.Throws <SqlTypeException>(() => chars.SetLength(20)); chars = new SqlChars(b1); Assert.Equal(10, chars.Length); Assert.Throws <ArgumentOutOfRangeException>(() => chars.SetLength(-1)); Assert.Throws <ArgumentOutOfRangeException>(() => chars.SetLength(11)); chars.SetLength(2); Assert.Equal(2, chars.Length); }
private static void AddHeader(SqlChars H, WebClient client) { if (!H.IsNull) { var header = H.ToSqlString().Value; if (!string.IsNullOrWhiteSpace(header)) { foreach (string h in header.Split(';')) { client.Headers.Add(h); } } } }
public void SqlCharsLength() { char[] b = null; SqlChars chars = new SqlChars(); Assert.Throws <SqlNullValueException>(() => chars.Length); chars = new SqlChars(b); Assert.Throws <SqlNullValueException>(() => chars.Length); b = new char[10]; chars = new SqlChars(b); Assert.Equal(10, chars.Length); }
public void SqlCharsStorage() { char[] b = null; SqlChars chars = new SqlChars(); Assert.Throws <SqlNullValueException>(() => chars.Storage); chars = new SqlChars(b); Assert.Throws <SqlNullValueException>(() => chars.Storage); b = new char[10]; chars = new SqlChars(b); Assert.Equal(StorageState.Buffer, chars.Storage); }
public override void ProcessInput(int inputID, PipelineBuffer buffer) { var geoCodingService = new GeoCodingService(); var output = ComponentMetaData.OutputCollection["Output"]; while (buffer.NextRow()) { bool modified = false; string address = GetFullAddressFromBuffer(buffer); if (!string.IsNullOrWhiteSpace(address)) { var coordinates = geoCodingService.GeoCodeAddress(address); if (coordinates != null) { if (_columnIndices.ContainsKey(LatitudeColumnName)) { buffer.SetDecimal(_columnIndices[LatitudeColumnName], coordinates.Latitude); modified = true; } if (_columnIndices.ContainsKey(LongitudeColumnName)) { buffer.SetDecimal(_columnIndices[LongitudeColumnName], coordinates.Longitude); modified = true; } if (_columnIndices.ContainsKey(LocationColumnName)) { var pointTaggedText = new SqlChars(string.Format("POINT({0} {1})", coordinates.Longitude, coordinates.Latitude)); var sqlGeography = SqlGeography.STPointFromText(pointTaggedText, 4326); _tmpMemoryStream.SetLength(0); sqlGeography.Write(_tmpBinaryWriter); _tmpBinaryWriter.Flush(); buffer.AddBlobData(_columnIndices[LocationColumnName], _tmpMemoryStream.GetBuffer(), (int)_tmpMemoryStream.Length); modified = true; } } } if (modified) { // send buffered row to output buffer.DirectRow(output.ID); } } }
/// <summary> /// Extends Read so that buffer offset of 0 and call to Array.Length are not needed. /// <example> /// sqlchars.Read(offset, buffer); /// </example> /// </summary> public static Int64 Read(this SqlChars sqlchars, Int64 offset, Char[] buffer) { if (sqlchars == null) { throw new ArgumentNullException("sqlchars"); } if (buffer == null) { throw new ArgumentNullException("buffer"); } return(sqlchars.Read(offset, buffer, 0, buffer.Length)); }
public void getValuesWithReader(SqlDataReader reader) { int columnNumber = reader.GetOrdinal("date"); date = reader.GetDateTime(columnNumber); columnNumber = reader.GetOrdinal("type"); SqlChars typeChar = reader.GetSqlChars(columnNumber); type = typeChar.Value[0]; columnNumber = reader.GetOrdinal("amount"); amount = Convert.ToDouble(reader.GetDecimal(columnNumber)); }
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) { if (value == null) { return(null); } if ((string)value == "") { return(new SqlGeometry()); } SqlChars wkt = new SqlChars(((string)value).ToCharArray()); return(SqlGeometry.STGeomFromText(wkt, 32631).MakeValid()); }
public static SqlBoolean RegexMatch(SqlChars input, SqlString pattern) { SqlBoolean result; try { var regex = new Regex(pattern.Value, Options); result = new SqlBoolean(regex.IsMatch(new string(input.Value))); } catch { result = new SqlBoolean(false); } return(result); }
public static SqlBoolean RegexMatch(SqlChars input, SqlString pattern, SqlInt32 timeout) { SqlBoolean result; try { var regex = new Regex(pattern.Value, Options, new TimeSpan(0, 0, 0, 0, timeout.Value)); result = regex.IsMatch(new string(input.Value)); } catch { result = new SqlBoolean(false); } return(result); }
private static void AddHeader(SqlChars H, WebClient client) { if (!H.IsNull) { var header = H.ToSqlString().Value; var allHeaders = header.Split('~'); foreach (var h in allHeaders) { if (!string.IsNullOrWhiteSpace(h)) { client.Headers.Add(h); } } } }
public void SqlCharsSetNull() { char [] b1 = new char [10]; SqlChars chars = new SqlChars(b1); Assert.AreEqual(chars.Length, 10, "#1 Should be same"); chars.SetNull(); try { Assert.AreEqual(chars.Length, 10, "#1 Should not be same"); Assert.Fail("Should throw SqlNullValueException"); } catch (Exception ex) { Assert.AreEqual(typeof(SqlNullValueException), ex.GetType(), "Should throw SqlNullValueException"); } Assert.AreEqual(true, chars.IsNull, "#2 Should be same"); }
/// <summary> /// Индикатор ошибок по имени поля /// </summary> /// <param name="columnName">Наименование проверяемого свойства</param> /// <returns>null - при осутствии ошибок, в противном случае описание ошибки</returns> public string this[string columnName] { get { if (columnName == nameof(EditShape)) { //Защита от дурака if (EditShape == "" || EditShape == null) { return("Геометрия не может быть пустой"); } SqlGeometry shape; //Проверка на возможность конвертации в геометрию try { //Конвертация строки в SqlGeometry SqlChars wkt = new SqlChars(EditShape.ToCharArray()); shape = SqlGeometry.STGeomFromText(wkt, 32631).MakeValid(); } catch (Exception ex) { return(String.Format("Ошибка геометрии: {0}", ex.Message)); } //Расположен ли полигон в пределах границ Республики Бенин DbGeometry newDbGeometry = shape.ToDbGeometry(); using (var context = ContextFactory.Create()) { context.CadastraleSecteurs_v.Load(); var cadSect = context.CadastraleSecteurs_v.Local; bool IsBeninWithin = cadSect.Where(s => s.Shape.Intersects(newDbGeometry)).Any(); if (!IsBeninWithin) { return("Границы расположены за пределами государственной границы Республики Бенин"); } } //Ошибок не найдено return(null); } else { return(null); } } }
public static SqlBoolean regex_ismatch(SqlChars input, SqlString pattern) { if (pattern.IsNull || input.IsNull) { return(SqlBoolean.Null); } else { var regex = new Regex(pattern.Value); var ismatch = regex.IsMatch(new string(input.Value)); return(new SqlBoolean(ismatch)); } }
public static IEnumerable SqlArray(SqlChars input, SqlString delimiter, SqlBoolean isRemoveEmptyEntries) { if (input.IsNull) { return(new string[] { }); } if (delimiter.IsNull) { return(new string[1] { input.ToStr() }); } var isNeedRemoveEmpty = isRemoveEmptyEntries ? StringSplitOptions.RemoveEmptyEntries : StringSplitOptions.None; return(input.ToStr().Split(new string[] { delimiter.Value }, isNeedRemoveEmpty)); }
public void SqlCharsItem() { SqlChars chars = new SqlChars(); Assert.Throws <SqlNullValueException>(() => chars[0]); char[] b = null; chars = new SqlChars(b); Assert.Throws <SqlNullValueException>(() => chars[0]); b = new char[10]; chars = new SqlChars(b); Assert.Equal(0, chars[0]); Assert.Throws <ArgumentOutOfRangeException>(() => chars[-1]); Assert.Throws <ArgumentOutOfRangeException>(() => chars[10]); }
public static SqlString xfnHexToBinary(SqlChars value) { if (value.IsNull) { return(SqlString.Null); } char[] hexString = value.Value; #if DOTNET45 string binarystring = String.Join(String.Empty, hexString.Select(c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0'))); #else string binarystring = String.Join(String.Empty, hexString.Select(c => Convert.ToString(Convert.ToInt32(c.ToString(), 16), 2).PadLeft(4, '0')).ToArray()); #endif return(new SqlString(binarystring)); }
/// <summary> /// Сохраняет изменения геометрии /// </summary> protected void SaveChanges() { if (this[nameof(EditShape)] != null) { return; } //Конвертация строки в SqlGeometry SqlGeometry shape; SqlChars wkt = new SqlChars(EditShape.ToCharArray()); shape = SqlGeometry.STGeomFromText(wkt, 32631).MakeValid(); FeatureObjet.Shape = shape.ToDbGeometry(); IsEndEditing = true; }
/// <summary> /// Agregamos valores separados por "/" de forma que si primerValor == true, el valor que entra se debe imprimir el primero en el resultado final /// </summary> /// <param name="Value"></param> /// <param name="primerValor"></param> public void Accumulate([SqlFacet(MaxSize = 10)] SqlChars Value, SqlBoolean primerValor) { if (Value.IsNull) { return; } if (primerValor) { resultado.Insert(0, '/'); resultado.Insert(0, Value.Value); } else { resultado.Append(Value.Value).Append('/'); } }
public static SqlString RegexMatch(SqlChars input, SqlString pattern, SqlBoolean isIgnoreCase, SqlInt32 groupnum) { if (input.IsNull) { return(null); } var re = new Regex(pattern.Value, isIgnoreCase ? RegexOptions.IgnoreCase : RegexOptions.None); var match = re.Match(input.ToStr()); if (match.Success) { return(match.Groups[groupnum.Value].Value); } return(null); }
public void SqlCharsItem() { SqlChars chars = new SqlChars(); try { Assert.Equal(0, chars[0]); Assert.False(true); } catch (Exception ex) { Assert.Equal(typeof(SqlNullValueException), ex.GetType()); } char[] b = null; chars = new SqlChars(b); try { Assert.Equal(0, chars[0]); Assert.False(true); } catch (Exception ex) { Assert.Equal(typeof(SqlNullValueException), ex.GetType()); } b = new char[10]; chars = new SqlChars(b); Assert.Equal(0, chars[0]); try { Assert.Equal(0, chars[-1]); Assert.False(true); } catch (Exception ex) { Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType()); } try { Assert.Equal(0, chars[10]); Assert.False(true); } catch (Exception ex) { Assert.Equal(typeof(ArgumentOutOfRangeException), ex.GetType()); } }
public static void Post(SqlChars H, SqlChars d, SqlChars url) { var client = new WebClient(); AddHeader(H, client); if (d.IsNull) { throw new ArgumentException("You must specify data that will be sent to the endpoint", "@d"); } var response = client.UploadString( Uri.EscapeUriString(url.ToSqlString().Value), d.ToSqlString().Value ); SqlContext.Pipe.Send("Request is executed. " + response); }
public static Grid FromShapeFile(string shapeFilePath, RutenettType rutenettType, int epsgCode) { var grid = new Grid(rutenettType); Shapefile shapeFile = Shapefile.OpenFile(shapeFilePath); foreach (var feature in shapeFile.Features) { var cell = new GridCell(); cell.CellId = feature.DataRow[0].ToString(); var text = new SqlChars(feature.BasicGeometry.ToString()); cell.Geometry = SqlGeometry.STGeomFromText(text, epsgCode); grid.Cells.Add(cell); } return(grid); }
// This doesn't work as SqlChars are represented as SqlString public void SqlTypes_SqlChars () { NpgsqlParameter parameter; SqlChars value = new SqlChars (new char [] { 'X', 'A' }); parameter = new NpgsqlParameter (); parameter.NpgsqlValue = value; Assert.AreEqual (NpgsqlDbType.Text, parameter.NpgsqlDbType, "#A:NpgsqlDbType"); Assert.AreSame (value, parameter.NpgsqlValue, "#A:NpgsqlValue"); Assert.AreSame (value, parameter.Value, "#A:Value"); parameter = new NpgsqlParameter (); parameter.NpgsqlValue = SqlChars.Null; Assert.AreEqual (NpgsqlDbType.Text, parameter.NpgsqlDbType, "#B:NpgsqlDbType"); Assert.IsNotNull (parameter.NpgsqlValue, "#B:SqlValue1"); Assert.AreEqual (typeof (SqlChars), parameter.NpgsqlValue.GetType (), "#B:SqlValue2"); Assert.IsTrue (((SqlChars) parameter.NpgsqlValue).IsNull, "#B:SqlValue3"); Assert.IsNotNull (parameter.Value, "#B:Value1"); Assert.AreEqual (typeof (SqlChars), parameter.Value.GetType (), "#B:Value2"); Assert.IsTrue (((SqlChars) parameter.Value).IsNull, "#B:Value3"); parameter = new NpgsqlParameter (); parameter.Value = value; Assert.AreEqual (NpgsqlDbType.Text, parameter.NpgsqlDbType, "#C:NpgsqlDbType"); Assert.AreSame (value, parameter.NpgsqlValue, "#C:NpgsqlValue"); Assert.AreSame (value, parameter.Value, "#C:Value"); }