Exemplo n.º 1
0
        public void DigitalAnnotation_CanSerializeAsJsonLD()
        {
            // Arrange: Given expected result
            var expected = @"{
                ""@context"": ""http://www.w3.org/ns/anno.jsonld"",
                ""id"": ""http://MyTestUri.com"",
                ""type"": ""Annotation"",
                ""target"": {
                        ""id"": ""http://MyImageSource.com#xywh=1,2,100,200"",
                        ""type"": ""image"",
                        ""format"": ""image/jpeg""
                    },
                ""body"": {
                    ""type"": ""TextualBody"",
                    ""value"": ""My Test Value"",
                    ""format"": ""text/plain""
                }
            }";

            // Arrange: Given a valid Digital Annotation Object
            var annotation = new WebAnnotation
            {
                Body = new TextualBody
                {
                    Value = "My Test Value"
                },
                Id     = "http://MyTestUri.com",
                Target = new WebAnnotationTarget
                {
                    Source      = "http://MyImageSource.com",
                    CoordinateX = 1,
                    CoordinateY = 2,
                    Width       = 100,
                    Height      = 200
                }
            };

            // Act: When serializing...
            var actual = JsonConvert.SerializeObject(annotation, _jSettings);
            var x      = expected.Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", String.Empty).Replace(" ", string.Empty);

            // Assert: the serialized string should meet json+ld specifications
            Assert.AreEqual(x, actual.Replace(" ", string.Empty));
        }
Exemplo n.º 2
0
        public static WebAnnotation ConvertAnnotationToWebAnnotation(Annotation annotation, string baseUrl)
        {
            WebAnnotation rt = null;

            if (annotation != null)
            {
                var source      = !annotation.ParentId.HasValue ? annotation.Target.Source.SourceUrl : null;
                var coordinateX = !annotation.ParentId.HasValue ? annotation.Target.CoordinateX : (decimal?)null;
                var coordinateY = !annotation.ParentId.HasValue ? annotation.Target.CoordinateY : (decimal?)null;
                var height      = !annotation.ParentId.HasValue ? annotation.Target.Height : (decimal?)null;
                var width       = !annotation.ParentId.HasValue ? annotation.Target.Width : (decimal?)null;
                var id          = !annotation.ParentId.HasValue ? new Uri($"{source}#xywh={coordinateX},{coordinateY},{width},{height}") :
                                  new Uri($"{baseUrl}/api/WebAnnotations/{annotation.ParentId}");
                var type   = !annotation.ParentId.HasValue ? Constants.ImageType : Constants.AnnotationType;
                var format = !annotation.ParentId.HasValue ? Constants.MediaTypes.JPegImage : null;

                rt = new WebAnnotation
                {
                    Id   = $"{_apiBaseUrl}/api/WebAnnotations/{annotation.AnnotationId}",
                    Body = CreateAnnotationBody(annotation),

                    Target = new WebAnnotationTarget
                    {
                        Id           = id,
                        TypeString   = type,
                        FormatString = format,
                        Source       = source,
                        CoordinateX  = coordinateX,
                        CoordinateY  = coordinateY,
                        Height       = height,
                        Width        = width
                    },
                    LicenseUrl = annotation.License?.LicenseUrl,
                    CanvasId   = annotation.Target.AnnotationSourceId,
                    On         = !annotation.ParentId.HasValue ? $"{baseUrl}/api/Canvases/{annotation.Target.Source.AnnotationSourceId}" : null,
                    Motivation = ConvertTypeToMotivation(annotation.AnnotationType)
                };
            }

            return(rt);
        }
Exemplo n.º 3
0
 public Task <Uri> CreateWebAnnotation(WebAnnotation model)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Return true if the passed point falls within our location
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        public bool Contains(WebAnnotation.ViewModel.SectionLocationsViewModel sectionAnnotations, GridVector2 pos)
        {
            GridVector2 locPosition = this.VolumePosition;

            switch (modelObj.TypeCode)
            {
                case LocationType.POINT: //A point
                    //HACK, assume label size is 256 pixels across
                    Vector2 offset = GetLabelSize();
                    offset.X *= AnnotationOverlay.LocationTextScaleFactor;
                    offset.Y *= AnnotationOverlay.LocationTextScaleFactor;

                    GridRectangle _Bounds = new GridRectangle(new GridVector2(locPosition.X - (offset.X / 2), locPosition.Y - (offset.Y / 2)),
                                                        offset.X,
                                                        offset.Y);
                    return _Bounds.Contains(pos);
                case LocationType.CIRCLE: //A circle
                    double distance = GridVector2.Distance(locPosition, pos);
                    return distance <= Radius;

                default:
                    Trace.WriteLine("Calling LocationObj::Contains on an unknown type of location", "WebAnnotation");
                    return false;
            }
        }