public LineSegment Reduce(EndpointKind kind) { if (!IsReducable()) { throw new ArgumentException("cannot reduce line of length 1"); } switch (kind) { case EndpointKind.From: switch (Direction) { case LineDirection.North: return(new LineSegment(Id, Origin, From.Move(Vector.DeltaNorth), To, Type, Direction)); case LineDirection.South: return(new LineSegment(Id, Origin, From.Move(Vector.DeltaSouth), To, Type, Direction)); case LineDirection.East: return(new LineSegment(Id, Origin, From.Move(Vector.DeltaEast), To, Type, Direction)); case LineDirection.West: return(new LineSegment(Id, Origin, From.Move(Vector.DeltaWest), To, Type, Direction)); default: throw new ArgumentOutOfRangeException(); } case EndpointKind.To: switch (Direction) { case LineDirection.North: return(new LineSegment(Id, Origin, From, To.Move(Vector.DeltaSouth), Type, Direction)); case LineDirection.South: return(new LineSegment(Id, Origin, From, To.Move(Vector.DeltaNorth), Type, Direction)); case LineDirection.East: return(new LineSegment(Id, Origin, From, To.Move(Vector.DeltaWest), Type, Direction)); case LineDirection.West: return(new LineSegment(Id, Origin, From, To.Move(Vector.DeltaEast), Type, Direction)); default: throw new ArgumentOutOfRangeException(); } default: throw new ArgumentOutOfRangeException(nameof(kind), kind, null); } }
static string GetReceivingPath(EndpointKind endpointKind) { string path; switch (endpointKind) { case EndpointKind.Feedback: path = "/messages/serviceBound/feedback"; break; default: throw new ArgumentException("Invalid endpoint kind to receive messages from Service endpoints", "endpointKind"); } return(path); }
public LineSegment ExtendEndpoint(int x, int y, EndpointKind kind) { Coord newTo, newFrom; switch (kind) { case EndpointKind.From: newFrom = new Coord(From.X + x, From.Y + y); newTo = To; break; case EndpointKind.To: newFrom = From; newTo = new Coord(To.X + x, To.Y + y); break; default: throw new ArgumentOutOfRangeException(nameof(kind), kind, null); } return(new LineSegment(Id, Origin, newFrom, newTo, Type)); }
internal static string GetReceivingPath(EndpointKind endpointKind) { string path; switch (endpointKind) { case EndpointKind.Feedback: path = "/messages/serviceBound/feedback"; break; case EndpointKind.FileNotification: path = "/messages/serviceBound/filenotifications"; break; default: throw new ArgumentException("Invalid endpoint kind to receive messages from Service endpoints", nameof(endpointKind)); } Logging.Info(endpointKind, path, nameof(GetReceivingPath)); return(path); }
public static LineDirection GetDirectionFromBend(LineDirection direction, EndpointKind kind, int dragx, int dragy) { switch (kind) { case EndpointKind.From: switch (direction) { case LineDirection.North: case LineDirection.South: if (dragx > 0) { return(LineDirection.West); } if (dragx < 0) { return(LineDirection.East); } return(direction); case LineDirection.East: case LineDirection.West: if (dragy > 0) { return(LineDirection.North); } if (dragy < 0) { return(LineDirection.South); } return(direction); default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } case EndpointKind.To: switch (direction) { case LineDirection.North: case LineDirection.South: if (dragx > 0) { return(LineDirection.East); } if (dragx < 0) { return(LineDirection.West); } return(direction); case LineDirection.East: case LineDirection.West: if (dragy > 0) { return(LineDirection.South); } if (dragy < 0) { return(LineDirection.North); } return(direction); default: throw new ArgumentOutOfRangeException(nameof(direction), direction, null); } default: throw new ArgumentOutOfRangeException(nameof(kind), kind, null); } }
public static LineDirection GetDirectionFromBend2(LineDirection direction, EndpointKind kind, int dragx, int dragy) { var resultingDirection = GetDirectionDragginFromPart(direction, dragx, dragy); return(kind == EndpointKind.From ? resultingDirection : Vector.GetOppositeDirection(resultingDirection)); }
public async Task Sets_request_properties_correctly(string requestMethod, string requestPath, bool expectIsCollection, EndpointKind expectKind, bool expectIsReadOnly) { // Arrange var options = new JsonApiOptions { UseRelativeLinks = true }; var graphBuilder = new ResourceGraphBuilder(options, NullLoggerFactory.Instance); graphBuilder.Add <Article>(); graphBuilder.Add <Author>(); var resourceGraph = graphBuilder.Build(); var controllerResourceMappingMock = new Mock <IControllerResourceMapping>(); controllerResourceMappingMock .Setup(x => x.GetResourceTypeForController(It.IsAny <string>())) .Returns(typeof(Article)); var httpContext = new DefaultHttpContext(); SetupRoutes(httpContext, requestMethod, requestPath); var request = new JsonApiRequest(); var middleware = new JsonApiMiddleware(_ => Task.CompletedTask); // Act await middleware.Invoke(httpContext, controllerResourceMappingMock.Object, options, request, resourceGraph); // Assert request.IsCollection.Should().Be(expectIsCollection); request.Kind.Should().Be(expectKind); request.IsReadOnly.Should().Be(expectIsReadOnly); request.BasePath.Should().BeEmpty(); request.PrimaryResource.Should().NotBeNull(); request.PrimaryResource.PublicName.Should().Be("articles"); }