public void PropertiesArePreserved() { var projection = new SqlProjection(new[] { new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]) }); var sut = SutFactory("identifier", projection); Assert.That(sut.Identifier, Is.EqualTo("identifier")); Assert.That(sut.Projection, Is.SameAs(projection)); }
/// <summary> /// Initializes a new instance of the <see cref="SqlProjectionDescriptorBuilder"/> class. /// </summary> /// <param name="identifier">The projection identifier.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="identifier"/> or <paramref name="version"/> is <c>null</c>.</exception> public SqlProjectionDescriptorBuilder([CallerMemberName] string identifier = null) { if (identifier == null) { throw new ArgumentNullException("identifier"); } _identifier = identifier; _projection = SqlProjection.Empty; }
/// <summary> /// Convert an input geometry instance to a valid geography instance. /// This function requires that the WKT coordinate values are longitude/latitude values, /// in that order and that a valid geography SRID value is supplied. /// </summary> /// <param name="geometry">Input Sql Geometry</param> /// <returns></returns> public static SqlGeography MakeValidGeographyFromGeometry(SqlGeometry geometry) { if (geometry.IsNull) { return(SqlGeography.Null); } if (geometry.STIsEmpty().Value) { return(CreateEmptyGeography(geometry.STSrid.Value)); } // Extract vertices from our input to be able to compute geography EnvelopeCenter var pointSetBuilder = new SqlGeographyBuilder(); geometry.Populate(new GeometryToPointGeographySink(pointSetBuilder)); SqlGeography center; try { center = pointSetBuilder.ConstructedGeography.EnvelopeCenter(); } catch (ArgumentException) { // Input is larger than a hemisphere. return(SqlGeography.Null); } // Construct Gnomonic projection centered on input geography var gnomonicProjection = SqlProjection.Gnomonic(center.Long.Value, center.Lat.Value); // Project, run geometry MakeValid and unproject var geometryBuilder = new SqlGeometryBuilder(); geometry.Populate(new VacuousGeometryToGeographySink(geometry.STSrid.Value, new Projector(gnomonicProjection, geometryBuilder))); var outGeometry = Geometry.MakeValidForGeography(geometryBuilder.ConstructedGeometry); try { return(gnomonicProjection.Unproject(outGeometry)); } catch (ArgumentException) { // Try iteratively to reduce the object to remove very close vertices. for (var tolerance = 1e-4; tolerance <= 1e6; tolerance *= 2) { try { return(gnomonicProjection.Unproject(outGeometry.Reduce(tolerance))); } catch (ArgumentException) { // keep trying } } return(SqlGeography.Null); } }
/// <summary> /// Initializes a new instance of the <see cref="SqlProjectionDescriptorBuilder"/> class. /// </summary> /// <param name="descriptor">The projection descriptor.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="descriptor"/> is <c>null</c>.</exception> public SqlProjectionDescriptorBuilder(SqlProjectionDescriptor descriptor) { if (descriptor == null) { throw new ArgumentNullException("descriptor"); } _identifier = descriptor.Identifier; _projection = descriptor.Projection; }
public void ToBuilderReturnsExpectedResult() { var handler = new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]); var projection = new SqlProjection(new[] { handler }); var sut = SutFactory("identifier", projection); var result = sut.ToBuilder().Build(); Assert.That(result.Identifier, Is.EqualTo("identifier")); Assert.That(result.Projection.Handlers, Is.EquivalentTo(new[] { handler })); }
/// <summary> /// Initializes a new instance of the <see cref="SqlProjectionDescriptor"/> class. /// </summary> /// <param name="identifier">The projection identifier.</param> /// <param name="projection">The projection.</param> /// <exception cref="System.ArgumentNullException">Thrown when <paramref name="identifier"/>, <paramref name="version"/> or <paramref name="projection"/> is <c>null</c>.</exception> public SqlProjectionDescriptor(string identifier, SqlProjection projection) { if (identifier == null) { throw new ArgumentNullException("identifier"); } if (projection == null) { throw new ArgumentNullException("projection"); } _identifier = identifier; _projection = projection; }
/// <summary> /// Computes ConvexHull of input geography and returns a polygon (unless all input points are collinear). /// </summary> /// <param name="geography">Input Sql Geography</param> /// <returns></returns> public static SqlGeography ConvexHullGeography(SqlGeography geography) { if (geography.IsNull || geography.STIsEmpty().Value) { return(geography); } var center = geography.EnvelopeCenter(); var gnomonicProjection = SqlProjection.Gnomonic(center.Long.Value, center.Lat.Value); var geometry = gnomonicProjection.Project(geography); return(gnomonicProjection.Unproject(geometry.MakeValid().STConvexHull())); }
public void ConcatHandlerReturnsExpectedResult() { var handler1 = new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]); var handler2 = new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]); var handler3 = new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]); var sut = new SqlProjection(new[] { handler1, handler2 }); var result = sut.Concat(handler3); Assert.That(result.Handlers, Is.EquivalentTo(new[] { handler1, handler2, handler3 })); }
public void ProjectionIsPreserved() { var sut = SutFactory(); var projection = new SqlProjection( new[] { new SqlProjectionHandler( typeof(object), _ => new SqlNonQueryCommand[0]) }); sut.Projection = projection; var result = sut.Projection; Assert.That(result, Is.SameAs(projection)); }
public void ExplicitConversionToSqlProjectionHandlerArray() { var handler1 = new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]); var handler2 = new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]); var handlers = new[] { handler1, handler2 }; var sut = new SqlProjection(handlers); var result = (SqlProjectionHandler[])sut; Assert.That(result, Is.EquivalentTo(handlers)); }
public void HandlersArePreservedAsProperty() { var handler1 = new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]); var handler2 = new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]); var handlers = new[] { handler1, handler2 }; var sut = new SqlProjection(handlers); var result = sut.Handlers; Assert.That(result, Is.EquivalentTo(handlers)); }
public void DecoratedProjectionHandlersAreCopiedOnConstruction() { var handler1 = new SqlProjectionHandler(typeof(object), o => new SqlNonQueryCommand[0]); var handler2 = new SqlProjectionHandler(typeof(object), o => new SqlNonQueryCommand[0]); var projection = new SqlProjection(new[] { handler1, handler2 }); var sut = new SqlProjectionBuilder(projection); var result = sut.Build(); Assert.That(result.Handlers, Is.EquivalentTo(new [] { handler1, handler2 })); }
public void ToBuilderReturnsExpectedResult() { var handler1 = new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]); var handler2 = new SqlProjectionHandler(typeof(object), _ => new SqlNonQueryCommand[0]); var sut = new SqlProjection(new[] { handler1, handler2 }); var result = sut.ToBuilder().Build().Handlers; Assert.That(result, Is.EquivalentTo(new[] { handler1, handler2 })); }
public void BuildReturnsExpectedResult() { var projection = new SqlProjection( new[] { new SqlProjectionHandler( typeof(object), _ => new SqlNonQueryCommand[0]) }); var sut = new SqlProjectionDescriptorBuilder("identifier") { Projection = projection }; var result = sut.Build(); Assert.That(result, Is.InstanceOf <SqlProjectionDescriptor>()); Assert.That(result.Identifier, Is.EqualTo("identifier")); Assert.That(result.Projection, Is.SameAs(projection)); }
public ProjacApprovalProcessorEventHandler(ConnectionStringSettings settings, IServiceBus bus) { _settings = settings; _bus = bus; _queryExecutor = new SqlCommandExecutor(settings); _projection = ApprovalProcessorProjection.Instance.Concat(StoreCheckpointProjection.Instance); var connection = new SqlConnection(settings.ConnectionString); connection.Open(); var projectionExecutor = new ConnectedSqlCommandExecutor(connection); _catchupDisposeCallback = new DisposeCallback(() => { connection.Close(); connection.Dispose(); }); _projector = new AsyncSqlProjector(_projection, projectionExecutor); }
public void SetUp() { _sut = new Any(); }
public NpgsqlProjectionScenario(SqlProjection projection) : this(Resolve.WhenEqualToHandlerMessageType(projection)) { }
public Projector(SqlProjection projection, IGeometrySink110 sink) { _projection = projection; _sink = sink; }
private static SqlProjectionDescriptor SutFactory(string identifier, SqlProjection projection) { return(new SqlProjectionDescriptor(identifier, projection)); }
private static SqlProjectionDescriptor SutProjectionFactory(SqlProjection projection) { return(SutFactory(Identifier, projection)); }
public void SetUp() { _sut = new WithoutHandlers(); }
public UnProjector(SqlProjection projection, IGeographySink110 sink, int newSrid) { _projection = projection; _sink = sink; _sink.SetSrid(newSrid); }