Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.Spatial
{
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
/// <summary>
/// A data contract serializable representation of a <see cref="DbGeography" /> value.
/// </summary>
[DataContract]
public sealed class DbGeographyWellKnownValue
{
/// <summary>
/// Gets or sets the coordinate system identifier (SRID) of this value.
/// </summary>
[DataMember(Order = 1, IsRequired = false, EmitDefaultValue = false)]
public int CoordinateSystemId { get; set; }
/// <summary>
/// Gets or sets the well known text representation of this value.
/// </summary>
[DataMember(Order = 2, IsRequired = false, EmitDefaultValue = false)]
public string WellKnownText { get; set; }
/// <summary>
/// Gets or sets the well known binary representation of this value.
/// </summary>
[DataMember(Order = 3, IsRequired = false, EmitDefaultValue = false)]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Required for this feature")]
public byte[] WellKnownBinary { get; set; }
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.Spatial
{
using System.Diagnostics.CodeAnalysis;
using System.Runtime.Serialization;
/// <summary>
/// A data contract serializable representation of a <see cref="DbGeometry" /> value.
/// </summary>
[DataContract]
public sealed class DbGeometryWellKnownValue
{
/// <summary>
/// Gets or sets the coordinate system identifier (SRID) of this value.
/// </summary>
[DataMember(Order = 1, IsRequired = false, EmitDefaultValue = false)]
public int CoordinateSystemId { get; set; }
/// <summary>
/// Gets or sets the well known text representation of this value.
/// </summary>
[DataMember(Order = 2, IsRequired = false, EmitDefaultValue = false)]
public string WellKnownText { get; set; }
/// <summary>
/// Gets or sets the well known binary representation of this value.
/// </summary>
[DataMember(Order = 3, IsRequired = false, EmitDefaultValue = false)]
[SuppressMessage("Microsoft.Performance", "CA1819:PropertiesShouldNotReturnArrays", Justification = "Required for this feature")]
public byte[] WellKnownBinary { get; set; }
}
}

View File

@ -0,0 +1,143 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.Spatial
{
using System.Data.Entity.Utilities;
using System.Diagnostics.CodeAnalysis;
using System.Threading;
using System.Threading.Tasks;
/// <summary>
/// A provider-independent service API for geospatial (Geometry/Geography) type support.
/// </summary>
public abstract class DbSpatialDataReader
{
/// <summary>
/// Reads an instance of <see cref="DbGeography" /> from the column at the specified column ordinal.
/// </summary>
/// <param name="ordinal"> The ordinal of the column that contains the geography value. </param>
/// <returns> The instance of DbGeography at the specified column value. </returns>
public abstract DbGeography GetGeography(int ordinal);
#if !NET40
/// <summary>
/// An asynchronous version of <see cref="GetGeography"/>, which
/// reads an instance of <see cref="DbGeography" /> from the column at the specified column ordinal.
/// </summary>
/// <param name="ordinal"> The ordinal of the column that contains the geography value. </param>
/// <param name="cancellationToken"> The token to monitor for cancellation requests. </param>
/// <returns> A <see cref="Task"/> containing the instance of <see cref="DbGeography" /> at the specified column value. </returns>
public Task<DbGeography> GetGeographyAsync(int ordinal)
{
return GetGeographyAsync(ordinal, CancellationToken.None);
}
/// <summary>
/// An asynchronous version of <see cref="GetGeography"/>, which
/// reads an instance of <see cref="DbGeography" /> from the column at the specified column ordinal.
/// </summary>
/// <remarks>
/// Providers should override with an appropriate implementation.
/// The default implementation invokes the synchronous <see cref="GetGeography"/> method and returns
/// a completed task, blocking the calling thread.
/// </remarks>
/// <param name="ordinal"> The ordinal of the column that contains the geography value. </param>
/// <param name="cancellationToken"> The token to monitor for cancellation requests. </param>
/// <returns> A <see cref="Task"/> containing the instance of <see cref="DbGeography" /> at the specified column value. </returns>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
Justification = "Exception provided in the returned task.")]
public virtual Task<DbGeography> GetGeographyAsync(int ordinal, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return TaskHelper.FromCancellation<DbGeography>();
}
try
{
return Task.FromResult(GetGeography(ordinal));
}
catch (Exception e)
{
return TaskHelper.FromException<DbGeography>(e);
}
}
#endif
/// <summary>
/// Reads an instance of <see cref="DbGeometry" /> from the column at the specified column ordinal.
/// </summary>
/// <param name="ordinal"> The ordinal of the data record column that contains the provider-specific geometry data. </param>
/// <returns> The instance of DbGeometry at the specified column value. </returns>
public abstract DbGeometry GetGeometry(int ordinal);
#if !NET40
/// <summary>
/// An asynchronous version of <see cref="GetGeometry"/>, which
/// reads an instance of <see cref="DbGeometry" /> from the column at the specified column ordinal.
/// </summary>
/// <param name="ordinal"> The ordinal of the data record column that contains the provider-specific geometry data. </param>
/// <param name="cancellationToken"> The token to monitor for cancellation requests. </param>
/// <returns> A <see cref="Task"/> containing the instance of <see cref="DbGeometry" /> at the specified column value. </returns>
public Task<DbGeometry> GetGeometryAsync(int ordinal)
{
return GetGeometryAsync(ordinal, CancellationToken.None);
}
/// <summary>
/// An asynchronous version of <see cref="GetGeometry"/>, which
/// reads an instance of <see cref="DbGeometry" /> from the column at the specified column ordinal.
/// </summary>
/// <remarks>
/// Providers should override with an appropriate implementation.
/// The default implementation invokes the synchronous <see cref="GetGeometry"/> method and returns
/// a completed task, blocking the calling thread.
/// </remarks>
/// <param name="ordinal"> The ordinal of the data record column that contains the provider-specific geometry data. </param>
/// <param name="cancellationToken"> The token to monitor for cancellation requests. </param>
/// <returns> A <see cref="Task"/> containing the instance of <see cref="DbGeometry" /> at the specified column value. </returns>
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes",
Justification = "Exception provided in the returned task.")]
public virtual Task<DbGeometry> GetGeometryAsync(int ordinal, CancellationToken cancellationToken)
{
if (cancellationToken.IsCancellationRequested)
{
return TaskHelper.FromCancellation<DbGeometry>();
}
try
{
return Task.FromResult(GetGeometry(ordinal));
}
catch (Exception e)
{
return TaskHelper.FromException<DbGeometry>(e);
}
}
#endif
/// <summary>
/// Returns whether the column at the specified column ordinal is of geography type
/// </summary>
/// <param name="ordinal"></param>
/// <returns>
/// <c>true</c> if the column at the specified column ordinal is of geography type;
/// <c>false</c> otherwise.
/// </returns>
public abstract bool IsGeographyColumn(int ordinal);
/// <summary>
/// Returns whether the column at the specified column ordinal is of geometry type
/// </summary>
/// <param name="ordinal"></param>
/// <returns>
/// <c>true</c> if the column at the specified column ordinal is of geometry type;
/// <c>false</c> otherwise.
/// </returns>
public abstract bool IsGeometryColumn(int ordinal);
}
}

View File

@ -0,0 +1 @@
59214ec986a0cd569170fdf22a17f1416ef18ed6

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,63 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.Spatial
{
using System.Data.Common;
using System.Data.Entity.Core.Metadata.Edm;
using System.Data.Entity.Utilities;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
internal static class SpatialHelpers
{
internal static object GetSpatialValue(MetadataWorkspace workspace, DbDataReader reader, TypeUsage columnType, int columnOrdinal)
{
Debug.Assert(Helper.IsSpatialType(columnType));
var spatialReader = CreateSpatialDataReader(workspace, reader);
if (Helper.IsGeographicType((PrimitiveType)columnType.EdmType))
{
return spatialReader.GetGeography(columnOrdinal);
}
else
{
return spatialReader.GetGeometry(columnOrdinal);
}
}
#if !NET40
internal static async Task<object> GetSpatialValueAsync(
MetadataWorkspace workspace, DbDataReader reader,
TypeUsage columnType, int columnOrdinal, CancellationToken cancellationToken)
{
Debug.Assert(Helper.IsSpatialType(columnType));
var spatialReader = CreateSpatialDataReader(workspace, reader);
if (Helper.IsGeographicType((PrimitiveType)columnType.EdmType))
{
return
await spatialReader.GetGeographyAsync(columnOrdinal, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
}
else
{
return
await spatialReader.GetGeometryAsync(columnOrdinal, cancellationToken).ConfigureAwait(continueOnCapturedContext: false);
}
}
#endif
internal static DbSpatialDataReader CreateSpatialDataReader(MetadataWorkspace workspace, DbDataReader reader)
{
var storeItemCollection = (StoreItemCollection)workspace.GetItemCollection(DataSpace.SSpace);
var providerFactory = storeItemCollection.StoreProviderFactory;
Debug.Assert(providerFactory != null, "GetProviderSpatialServices requires provider factory to have been initialized");
var providerServices = providerFactory.GetProviderServices();
var result = providerServices.GetSpatialDataReader(reader, storeItemCollection.StoreProviderManifestToken);
Debug.Assert(result != null, "DbProviderServices did not throw ProviderIncompatibleException for null IDbSpatialDataReader");
return result;
}
}
}

View File

@ -0,0 +1,50 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
namespace System.Data.Entity.Spatial
{
using System.Data.Entity.Config;
using System.Data.Entity.Core;
using System.Data.Entity.Core.Common;
using System.Diagnostics;
internal class SpatialServicesLoader
{
private readonly IDbDependencyResolver _resolver;
public SpatialServicesLoader(IDbDependencyResolver resolver)
{
_resolver = resolver;
}
/// <summary>
/// Ask for a spatial provider. If one has been registered then we will use it, otherwise we will
/// fall back on using the SQL provider and if this is not available then the default provider.
/// </summary>
public virtual DbSpatialServices LoadDefaultServices()
{
var spatialProvider = _resolver.GetService<DbSpatialServices>();
if (spatialProvider != null)
{
return spatialProvider;
}
var efProvider = _resolver.GetService<DbProviderServices>("System.Data.SqlClient");
Debug.Assert(efProvider != null);
try
{
spatialProvider = efProvider.GetSpatialServicesInternal(new Lazy<IDbDependencyResolver>(() => _resolver), "2008");
if (spatialProvider.NativeTypesAvailable)
{
return spatialProvider;
}
}
catch (ProviderIncompatibleException)
{
// Thrown if the provider doesn't support spatial, in which case we fall back to the default.
}
return DefaultSpatialServices.Instance;
}
}
}