protected string GetWithClause(IEnumerable <ProviderPropertyExpression> properties) { bool withNoLock = GetProviderPropertyValue <WithNoLockExpression, bool>(properties, false); IEnumerable <string> indexNames = GetProviderPropertyValue <IndexNamesExpression, IEnumerable <string> >( properties, new string[] { }); bool forceIndex = Enumerable.Count(indexNames) > 0 && GetProviderPropertyValue <ForceIndexExpression, bool>(properties, false); if (!withNoLock && !forceIndex) { return(String.Empty); } if (withNoLock && !forceIndex) { return(" WITH(NOLOCK) "); } if (forceIndex && !withNoLock) { return(string.Format(" WITH(INDEX({0})) ", string.Join(",", Enumerable.ToArray(indexNames)))); } return(string.Format(" WITH(NOLOCK,INDEX({0})) ", string.Join(",", Enumerable.ToArray(indexNames)))); }
public static void WriterAsReadOnlyCollection() { using var writer = new PooledArrayBufferWriter <int>(); IReadOnlyList <int> collection = writer; Empty(collection); writer.Add(42); Equal(1, writer.WrittenCount); Equal(1, collection.Count); Equal(42, collection[0]); Throws <IndexOutOfRangeException>(() => collection[1]); Equal(42, Enumerable.First(collection)); Equal(1, Enumerable.Count(collection)); writer.AddAll(new[] { 43, 44 }); Equal(3, writer.WrittenCount); Equal(3, collection.Count); Equal(42, collection[0]); Equal(43, collection[1]); Equal(44, collection[2]); Throws <IndexOutOfRangeException>(() => collection[3]); Equal(3, Enumerable.Count(collection)); Equal(new[] { 42, 43, 44 }, Enumerable.ToArray(collection)); }
public ReturnShortModelAttribute(Type model, params Type[] models) { if (models != null && models.Any()) { Models = Enumerable.ToArray(Enumerable.Concat(models, new[] { model, })); } else { Models = new[] { model, }; } }
private int HashProjection(IProjection proj) { int h = proj.ProjectionClassName.GetHashCode(); ProjectionParameter[] arr = Enumerable.ToArray(proj); Array.Sort(arr, new Comparison <ProjectionParameter>( delegate(ProjectionParameter a, ProjectionParameter b) { return(string.Compare(a.Name, b.Name)); })); foreach (ProjectionParameter v in arr) { h ^= v.Value.GetHashCode(); } return(h); }
protected override string GenerateSelectSql(IList <ProviderPropertyExpression> properties, ExpressionTreeToSqlCompilerBase <TOid> compiler, int pageSize, int pageNumber) { //string orderByCols = String.Join(",", // Enumerable.ToArray(Processor.Select( // GetProviderPropertyValue // <OrderByCollectionExpression, // CollectionExpression<OrderByExpression>>( // properties, // new CollectionExpression<OrderByExpression>( // new OrderByExpression[] {})), // delegate(OrderByExpression o) { return o.ToString("\"{0}\""); }))); string orderByCols = string.IsNullOrEmpty(compiler.OrderByClause) ? QualifyColumnName(OidColumn) : compiler.OrderByClause; Int64 startRecord = (pageNumber * pageSize) + 1; string mainQueryColumns = string.Join(",", Enumerable.ToArray( FormatColumnNames(true, true, compiler.ProjectedColumns.Count > 0 ? compiler.ProjectedColumns : SelectAllColumnNames()))); string sqlWhereClause = String.Format(@" WHERE (nextval('sharpmap') > {0})", compiler.CreateParameter(startRecord).ParameterName); //, if (!String.IsNullOrEmpty(compiler.SqlWhereClause)) { sqlWhereClause += " AND " + compiler.SqlWhereClause; } return(string.Format( @" DROP SEQUENCE IF EXISTS ""sharpmap""; CREATE TEMPORARY SEQUENCE ""sharpmap"" INCREMENT BY 1; SELECT {0} FROM {1} {2} {3} ORDER BY {4} LIMIT {5};", mainQueryColumns, QualifiedTableName, compiler.SqlJoinClauses, sqlWhereClause, orderByCols, compiler.CreateParameter(pageSize).ParameterName)); }
protected override string GenerateSelectSql(IList <ProviderPropertyExpression> properties, ExpressionTreeToSqlCompilerBase <TOid> compiler) { int pageNumber = GetProviderPropertyValue <DataPageNumberExpression, int>(properties, -1); int pageSize = GetProviderPropertyValue <DataPageSizeExpression, int>(properties, 0); if (pageSize > 0 && pageNumber > -1) { return(GenerateSelectSql(properties, compiler, pageSize, pageNumber)); } //string orderByCols = String.Join(",", // Enumerable.ToArray(Processor.Select( // GetProviderPropertyValue // <OrderByCollectionExpression, // CollectionExpression<OrderByExpression>>( // properties, // new CollectionExpression<OrderByExpression>( // new OrderByExpression[] { })), // delegate(OrderByExpression o) // { // return "[" + // o.PropertyNameExpression.PropertyName + // "] " + // (o.Direction == SortOrder.Ascending // ? "ASC" // : "DESC"); // }))); string orderByClause = string.IsNullOrEmpty(compiler.OrderByClause) ? String.Empty : " ORDER BY " + compiler.OrderByClause; string mainQueryColumns = string.Join(",", Enumerable.ToArray( FormatColumnNames(true, true, compiler.ProjectedColumns.Count > 0 ? compiler.ProjectedColumns : SelectAllColumnNames() ))); return(string.Format(" {0} SELECT {1} FROM {2}{6} {3} {4} {5} {7}", compiler.SqlParamDeclarations, mainQueryColumns, QualifiedTableName, compiler.SqlJoinClauses, string.IsNullOrEmpty(compiler.SqlWhereClause) ? String.Empty : " WHERE ", compiler.SqlWhereClause, GetWithClause(properties), orderByClause)); }
protected virtual void VisitCollectionExpression(StringBuilder builder, CollectionExpression exp) { if (exp == null) { return; } StringBuilder sb = new StringBuilder(); sb.Append(string.Join(", ", Enumerable.ToArray(EnumerableToParameterConverter(exp.Collection)))); if (sb.Length > 0) { builder.AppendFormat("({0})", sb); } }
protected virtual string GenerateSelectSql(IList <ProviderPropertyExpression> properties, ExpressionTreeToSqlCompilerBase <TOid> compiler) { int pageNumber = GetProviderPropertyValue <DataPageNumberExpression, int>(properties, -1); int pageSize = GetProviderPropertyValue <DataPageSizeExpression, int>(properties, 0); if (pageSize > 0 && pageNumber > -1) { return(GenerateSelectSql(properties, compiler, pageSize, pageNumber)); } //string orderByCols = String.Join(",", // Enumerable.ToArray(Processor.Select( // GetProviderPropertyValue // <OrderByCollectionExpression, // CollectionExpression<OrderByExpression>>( // properties, // new CollectionExpression<OrderByExpression>( // new OrderByExpression[] { })), // delegate(OrderByExpression o) { return o.ToString(); }))); string orderByClause = string.IsNullOrEmpty(compiler.OrderByClause) ? "" : " ORDER BY " + compiler.OrderByClause; string mainQueryColumns = string.Join(",", Enumerable.ToArray( FormatColumnNames(true, true, compiler.ProjectedColumns.Count > 0 ? compiler.ProjectedColumns : SelectAllColumnNames() ))); return(String.Format(" {0} SELECT {1} FROM {2} {3} {4} {5} {6}", compiler.SqlParamDeclarations, mainQueryColumns, QualifiedTableName, compiler.SqlJoinClauses, String.IsNullOrEmpty(compiler.SqlWhereClause) ? "" : " WHERE ", compiler.SqlWhereClause, orderByClause)); }
public virtual void Delete(IEnumerable <FeatureDataRow <TOid> > features) { List <TOid> featureIds = new List <TOid>(); foreach (FeatureDataRow <TOid> fdr in features) { featureIds.Add(fdr.Id); } ExpressionTreeToSqlCompilerBase <TOid> compiler = CreateSqlCompiler(null); using (IDbConnection conn = DbUtility.CreateConnection(ConnectionString)) { using (IDbCommand cmd = DbUtility.CreateCommand()) { cmd.Connection = conn; cmd.CommandText = String.Format( "DELETE FROM {0} WHERE {1} in ({2})", QualifiedTableName, OidColumn, String.Join(",", Enumerable.ToArray( Processor.Select(featureIds, delegate(TOid o) { return (compiler.CreateParameter(o).ParameterName); }))) ); conn.Open(); foreach (IDataParameter p in compiler.ParameterCache.Values) { cmd.Parameters.Add(p); } cmd.ExecuteNonQuery(); } } }
protected internal void CreateIndex(IDbConnection conn, string indexName, IEnumerable <string> columnNames) { StringBuilder sb = new StringBuilder(); sb.AppendFormat( @"IF EXISTS (SELECT * FROM sys.indexes WHERE name = '{0}' and object_id = object_id('{1}')) BEGIN DROP INDEX [{0}] on {1} END ", indexName, QualifiedTableName); sb.AppendFormat( @"CREATE INDEX [{0}] ON {1}({2})", indexName, QualifiedTableName, string.Join(",", Enumerable.ToArray(columnNames))); using (IDbCommand cmd = conn.CreateCommand()) { cmd.CommandText = sb.ToString(); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } }
public static System.Reflection.MemberInfo[] GetCachedFields(this System.Type type, System.Reflection.BindingFlags flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic) { if (ReflectionHelper.fieldInfoCache.TryGetValue(type, out var fieldInfos) == false) { var fieldInfosArr = Enumerable.Cast <System.Reflection.MemberInfo>(Enumerable.Where(type.GetAllFields(flags), f => f.IsPublic == true || Enumerable.Any(f.CustomAttributes, a => a.AttributeType == typeof(ME.ECS.Serializer.SerializeFieldAttribute)) == true)); fieldInfosArr = Enumerable.Union(fieldInfosArr, Enumerable.Where(type.GetAllProperties(flags), f => f.CanRead == true && f.CanWrite == true && Enumerable.Any(f.CustomAttributes, a => a.AttributeType == typeof(ME.ECS.Serializer.SerializeFieldAttribute)) ) ); fieldInfos = Enumerable.ToArray(Enumerable.OrderBy(fieldInfosArr, x => x.Name)); ReflectionHelper.fieldInfoCache.Add(type, fieldInfos); } return(fieldInfos); }
protected override DataTable BuildSchemaTable(Boolean withGeometryColumn) { DataTable dt = null; using (NpgsqlConnection conn = new NpgsqlConnection(ConnectionString)) { conn.Open(); CollectionExpression <PropertyNameExpression> attributes = null; if (DefaultProviderProperties != null) { attributes = GetProviderPropertyValue <AttributesCollectionExpression, CollectionExpression <PropertyNameExpression> >( DefaultProviderProperties.ProviderProperties, null); } string columns = attributes == null ? "*" : string.Join(",", Enumerable.ToArray(Processor.Select(attributes, delegate( PropertyNameExpression o) { return (QualifyColumnName ( o. PropertyName)); }))); if (columns != "*") { if (!columns.Contains(QualifyColumnName(GeometryColumn))) { columns = string.Format("{0},{1}", QualifyColumnName(GeometryColumn), columns); } if (!columns.Contains(QualifyColumnName(OidColumn))) { columns = string.Format("{0},{1}", QualifyColumnName(OidColumn), columns); } } using ( NpgsqlCommand cmd = new NpgsqlCommand(string.Format("SELECT {0} FROM {1} LIMIT 1;", columns, QualifiedTableName), conn)) { NpgsqlDataAdapter da = new NpgsqlDataAdapter(cmd); DataSet ds = new DataSet(); da.FillSchema(ds, SchemaType.Source); dt = ds.Tables["Table"]; } conn.Close(); } if (!dt.Columns.Contains("oid") && HasOids) { dt.Columns.Add(new DataColumn("oid", typeof(Int64))); DataColumn dc = dt.Columns["oid"]; dc.SetOrdinal(0); if (dt.Constraints.Count == 0) { dt.Constraints.Add("PK", dt.Columns[0], true); } } for (int i = 0; i < dt.Columns.Count; i++) { if (dt.Columns[i].ColumnName == GeometryColumn) { dt.Columns[i].DataType = typeof(Byte[]); } } if (!withGeometryColumn) { dt.Columns.Remove(GeometryColumn); } //remove Primary Key to avoid possibliy mismatched PrimaryKey of FeatureDataTable dt.PrimaryKey = null; return(dt); }
public override Expression Clone() { return(new CollectionExpression(Enumerable.ToArray(Caster.Cast <object>(_collection)))); }
protected override string GenerateSelectSql(IList <ProviderPropertyExpression> properties, ExpressionTreeToSqlCompilerBase <TOid> compiler, int pageSize, int pageNumber) { //string orderByCols = String.Join(",", // Enumerable.ToArray(Processor.Select( // GetProviderPropertyValue // <OrderByCollectionExpression, // CollectionExpression<OrderByExpression>>( // properties, // new CollectionExpression<OrderByExpression>( // new OrderByExpression[] { })), // delegate(OrderByExpression o) // { // return "[" + // o.PropertyNameExpression.PropertyName + // "] " + // (o.Direction == SortOrder.Ascending // ? "ASC" // : "DESC"); // }))); string orderByCols = string.IsNullOrEmpty(compiler.OrderByClause) ? OidColumn : compiler.OrderByClause; int startRecord = (pageNumber * pageSize) + 1; int endRecord = (pageNumber + 1) * pageSize; string mainQueryColumns = string.Join(",", Enumerable.ToArray( FormatColumnNames(true, true, compiler.ProjectedColumns.Count > 0 ? compiler.ProjectedColumns : SelectAllColumnNames() ))); string subQueryColumns = string.Join(",", Enumerable.ToArray( FormatColumnNames(false, false, compiler.ProjectedColumns.Count > 0 ? compiler.ProjectedColumns : SelectAllColumnNames() ))); return(string.Format( @" {0}; WITH CTE(rownumber, {8}) AS ( SELECT ROW_NUMBER() OVER(ORDER BY {7}) AS rownumber, {1} FROM {2}{6} {3} {4} {5} ) SELECT {8} FROM CTE WHERE rownumber BETWEEN {9} AND {10} ", compiler.SqlParamDeclarations, mainQueryColumns, QualifiedTableName, compiler.SqlJoinClauses, string.IsNullOrEmpty(compiler.SqlWhereClause) ? String.Empty : " WHERE ", compiler.SqlWhereClause, GetWithClause(properties), orderByCols, subQueryColumns, compiler.CreateParameter(startRecord).ParameterName, compiler.CreateParameter(endRecord).ParameterName)); }
public override Expression Clone() { IEnumerable <TValue> values = Collection; return(new CollectionExpression(Enumerable.ToArray(values))); }
public override Expression Clone() { IEnumerable <String> values = Collection; return(new StringCollectionExpression(Enumerable.ToArray(values), _comparison, Comparer)); }
protected override string GenerateSelectSql(IList <ProviderPropertyExpression> properties, ExpressionTreeToSqlCompilerBase <TOid> compiler) { _dataPageNumber = GetProviderPropertyValue <DataPageNumberExpression, int>(properties, -1); _dataPageSize = GetProviderPropertyValue <DataPageSizeExpression, int>(properties, 0); string sql = ""; //string orderByCols = String.Join(",", // Enumerable.ToArray(Processor.Select( // GetProviderPropertyValue // <OrderByCollectionExpression, // CollectionExpression<OrderByExpression>>( // properties, // new CollectionExpression<OrderByExpression>( // new OrderByExpression[] {})), // delegate(OrderByExpression o) { return o.ToString("\"{0}\""); }))); string orderByClause = string.IsNullOrEmpty(compiler.OrderByClause) ? "" : " ORDER BY " + compiler.OrderByClause; string mainQueryColumns = string.Join(",", Enumerable.ToArray( FormatColumnNames(true, true, compiler.ProjectedColumns.Count > 0 ? compiler.ProjectedColumns : SelectAllColumnNames()))); sql = String.Format("\nSELECT {0}\nFROM {1}\n{2}\n{3} {4}\n{5};", mainQueryColumns, QualifiedTableName + " AS \"" + Table + "\"", compiler.SqlJoinClauses, string.IsNullOrEmpty(compiler.SqlWhereClause) ? "" : " WHERE ", compiler.SqlWhereClause, orderByClause); //} #if DEBUG && EXPLAIN if (sql.StartsWith("SELECT")) { using (DB2Connection cn = new DB2Connection(ConnectionString)) { cn.Open(); DB2Command cm = new DB2Command(String.Format("EXPLAIN ANALYZE {0}", sql), cn); foreach (IDataParameter par in compiler.ParameterCache.Values) { cm.Parameters.Add(par); } Debug.WriteLine(""); DB2DataReader dr = cm.ExecuteReader(); if (dr.HasRows) { while (dr.Read()) { Debug.WriteLine(dr.GetString(0)); } } Debug.WriteLine(""); } } #endif return(sql); }
private void SetStyle( GeometryStyle style, string stroke, string strokeWidth, string strokeOpacity, string strokeLinejoin, string strokeLineCap, string strokeDasharray, string strokeDashOffset, string fill, string fillOpacity, string pointSymbolPath ) { if (!String.IsNullOrEmpty(stroke)) { Color color = ColorTranslator.FromHtml(stroke); int opacity = 255; double width = 1; if (!String.IsNullOrEmpty(strokeOpacity)) { opacity = Convert.ToInt32(Math.Round(Convert.ToDouble(strokeOpacity) / 0.0039215, 0)); if (opacity > 255) { opacity = 255; } } if (!String.IsNullOrEmpty(strokeWidth)) { width = Convert.ToDouble(strokeWidth); } StyleBrush brush = new SolidStyleBrush(new StyleColor(Convert.ToInt32(color.B), Convert.ToInt32(color.G), Convert.ToInt32(color.R), opacity)); StylePen pen = new StylePen(brush, width); if (!String.IsNullOrEmpty(strokeLinejoin)) { switch (strokeLinejoin.ToLower()) { case "mitre": pen.LineJoin = StyleLineJoin.Miter; break; case "round": pen.LineJoin = StyleLineJoin.Round; break; case "bevel": pen.LineJoin = StyleLineJoin.Bevel; break; //case "miterclipped": // Not in SLD // pen.LineJoin = StyleLineJoin.MiterClipped; // break; } } if (!String.IsNullOrEmpty(strokeLineCap)) { switch (strokeLineCap.ToLower()) { case "butt": pen.StartCap = StyleLineCap.Flat; pen.EndCap = StyleLineCap.Flat; break; case "round": pen.StartCap = StyleLineCap.Round; pen.EndCap = StyleLineCap.Round; break; case "square": pen.StartCap = StyleLineCap.Square; pen.EndCap = StyleLineCap.Square; break; // N.B. Loads of others not used in SLD } } if (!String.IsNullOrEmpty(strokeDasharray)) { string[] Numbers = strokeDasharray.Split(Char.Parse(" ")); IEnumerable <float> dbls = Processor.Select(Numbers, delegate(string o) { return(float.Parse(o)); }); pen.DashPattern = Enumerable.ToArray(dbls); } if (!String.IsNullOrEmpty(strokeDashOffset)) { float dashOffset; bool success; success = float.TryParse(strokeDashOffset, out dashOffset); if (success) { pen.DashOffset = dashOffset; } } // Set pen style.Line = pen; } if (!String.IsNullOrEmpty(fill)) { Color color = ColorTranslator.FromHtml(fill); int opacity = 255; if (!String.IsNullOrEmpty(fillOpacity)) { opacity = Convert.ToInt32(Math.Round(Convert.ToDouble(fillOpacity) / 0.0039215, 0)); if (opacity > 255) { opacity = 255; } } StyleBrush brush = new SolidStyleBrush(new StyleColor(Convert.ToInt32(color.B), Convert.ToInt32(color.G), Convert.ToInt32(color.R), opacity)); style.Fill = brush; } if (!String.IsNullOrEmpty(pointSymbolPath)) { Uri source = new Uri(pointSymbolPath); if (source.IsFile && File.Exists(source.AbsolutePath)) { Bitmap b = new Bitmap(source.AbsolutePath); MemoryStream ms = new MemoryStream(); b.Save(ms, ImageFormat.Png); ms.Seek(0, SeekOrigin.Begin); style.Symbol = new Symbol2D(ms, new Size2D(12, 10)); } else if (source.IsAbsoluteUri) { ///TODO } } style.Enabled = true; style.EnableOutline = true; }