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); }
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)); }
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); } }