Ejemplo n.º 1
0
        private bool IsValidParent(SegmentContext segmentContext, ISanityDocument document)
        {
            if (document.Parent == null)
            {
                return(true);
            }

            var indexOfParent = segmentContext.ConsumedDocuments.IndexOf(document.Parent.Id);

            return(indexOfParent > -1 && indexOfParent == segmentContext.ConsumedDocuments.Count - 2);
        }
Ejemplo n.º 2
0
        public Task <bool> IsMatch(SegmentContext segmentContext)
        {
            var next = segmentContext.GetNextValue(segmentContext.RemainingPath);

            if (CultureInfo.CurrentUICulture.Name.Equals(next.Next, StringComparison.CurrentCultureIgnoreCase))
            {
                segmentContext.RemainingPath = next.Remaining;
            }

            return(Task.FromResult(true));
        }
Ejemplo n.º 3
0
        public virtual async Task <bool> IsMatch(SegmentContext segmentContext)
        {
            while (true)
            {
                var segment      = segmentContext.GetNextValue(segmentContext.RemainingPath);
                var segmentValue = segment.Next;
                var document     = await _sanityClient.GetBySlug <ISanityDocument>(segmentValue, segmentContext.Language);

                if (document == null)
                {
                    var isValidRoute = segmentContext.RoutedDocument != null &&
                                       segmentContext.RemainingPath.IndexOf('/') == -1;

                    if (!isValidRoute)
                    {
                        segmentContext.RoutedDocumentId = Guid.Empty;
                        segmentContext.RoutedDocument   = null;
                    }

                    return(isValidRoute);
                }

                if (!segmentContext.ConsumedDocuments.Contains(document.Id))
                {
                    segmentContext.ConsumedDocuments.Add(document.Id);
                }

                if (!IsValidParent(segmentContext, document))
                {
                    segmentContext.RoutedDocument = null;
                    return(false);
                }

                segmentContext.RoutedDocument   = document;
                segmentContext.RoutedDocumentId = document.Id;
                segmentContext.RemainingPath    = segment.Remaining;

                if (!string.IsNullOrEmpty(segmentContext.RemainingPath))
                {
                    continue;
                }

                return(true);
            }
        }