Ejemplo n.º 1
0
#pragma warning disable 1998
        public async Task <ActionResult <AnnotationsResponse> > Annotations([FromQuery] AnnotationsParameters parameters)
#pragma warning restore 1998
        {
            Dictionary <string, Annotation> annotations;

            if (!annotationsCache.TryGet(parameters.GoogleDocId, out annotations))
            {
                lock (annotationsCache)
                {
                    if (!annotationsCache.TryGet(parameters.GoogleDocId, out annotations))
                    {
                        var googleDocContent = googleDocApiClient.GetGoogleDocContentAsync(parameters.GoogleDocId).Result;
                        annotations = annotationsParser.ParseAnnotations(googleDocContent);

                        annotationsCache.Add(parameters.GoogleDocId, annotations);
                    }
                }
            }

            var annotation = annotations.GetValueOrDefault(parameters.VideoId);

            return(new AnnotationsResponse
            {
                Annotation = annotation,
            });
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <AnnotationsResponse> > Annotations([FromQuery] AnnotationsParameters parameters)
        {
            Dictionary <string, Annotation> annotations;

            if (!annotationsCache.TryGet(parameters.GoogleDocId, out annotations))
            {
                lock (annotationsCache)
                {
                    if (!annotationsCache.TryGet(parameters.GoogleDocId, out annotations))
                    {
                        var googleDocContent = googleDocApiClient.GetGoogleDocContentAsync(parameters.GoogleDocId).Result;
                        annotations = annotationsParser.ParseAnnotations(googleDocContent);

                        annotationsCache.Add(parameters.GoogleDocId, annotations);
                    }
                }
            }

            if (!annotations.TryGetValue(parameters.VideoId, out var annotation))
            {
                return(NotFound(new ErrorResponse($"Annotation for video {parameters.VideoId} not found in document {parameters.GoogleDocId}")));
            }

            return(new AnnotationsResponse
            {
                Annotation = annotation,
            });
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <AnnotationsResponse> > Annotations([FromQuery] AnnotationsParameters parameters)
        {
            if (!annotationsCache.TryGet(parameters.GoogleDocId, out var annotations))
            {
                var googleDocContent = await googleDocApiClient.GetGoogleDocContentAsync(parameters.GoogleDocId).ConfigureAwait(false);

                annotations = annotationsParser.ParseAnnotations(googleDocContent);

                annotationsCache.Add(parameters.GoogleDocId, annotations);
            }

            if (!annotations.TryGetValue(parameters.VideoId, out var annotation))
            {
                return(NotFound(new ErrorResponse($"Annotation for video {parameters.VideoId} not found in document {parameters.GoogleDocId}")));
            }

            return(new AnnotationsResponse
            {
                Annotation = annotation,
            });
        }