private static List <RoutePart> GetRouteParts(string stringRoute) { try { stringRoute = stringRoute.Replace("//", "/"); stringRoute = stringRoute.Replace("\\", "/"); var stringParts = stringRoute.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); var parts = new List <RoutePart>(); for (var i = 0; i < stringParts.Length; i++) { var stringPart = stringParts[i]; var part = new RoutePart() { Index = i, PartType = (stringPart.StartsWith("{") && stringPart.EndsWith("}")) ? RoutePartType.Parameter : RoutePartType.Text, PartName = stringPart.Contains("{") ? stringPart.Replace("{", "").Replace("}", "") : stringPart }; parts.Add(part); } return(parts); } catch (Exception e) { Console.WriteLine(e); throw; } }
public void GetCompleteRouteTwoElements() { // Even with three times the same message, this should return just one route var sentence1 = new RoutePart("RT", 2, 1, new List <string>() { "A", "B" }); var sentence2 = new RoutePart("RT", 2, 2, new List <string>() { "C", "D" }); _sink.Raise(x => x.OnNewSequence += null, null, sentence1); _sink.Raise(x => x.OnNewSequence += null, null, sentence2); _sink.Raise(x => x.OnNewSequence += null, null, sentence1); _cache.Add(new Waypoint(new GeographicPosition(), "A")); _cache.Add(new Waypoint(new GeographicPosition(), "B")); _cache.Add(new Waypoint(new GeographicPosition(), "C")); _cache.Add(new Waypoint(new GeographicPosition(), "D")); _cache.TryGetCurrentRoute(out var route); Assert.Equal(4, route.Count); Assert.Equal("RT", route[0].RouteName); Assert.Equal(4, route[0].TotalPointsInRoute); Assert.Equal(0, route[0].IndexInRoute); Assert.Equal("A", route[0].WaypointName); Assert.Equal("B", route[1].WaypointName); Assert.Equal(1, route[1].IndexInRoute); }
public ItemInspector(IContent item, ContentItemMetadata metadata) { _item = item; _metadata = metadata; _common = item.Get<ICommonPart>(); _routable = item.Get<RoutePart>(); _body = item.Get<BodyPart>(); }
public void FindOlderRouteIfNewIsIncomplete() { var sentence1 = new RoutePart("RTOld", 2, 1, new List <string>() { "A", "B" }); var sentence1b = new RoutePart("RTOld", 2, 2, new List <string>() { "C" }); var sentence2 = new RoutePart("RTNew", 3, 1, new List <string>() { "C", "D" }); _sink.Raise(x => x.OnNewSequence += null, null, sentence1); _sink.Raise(x => x.OnNewSequence += null, null, sentence1b); _sink.Raise(x => x.OnNewSequence += null, null, sentence2); _cache.Add(new Waypoint(new GeographicPosition(), "A")); _cache.Add(new Waypoint(new GeographicPosition(), "B")); _cache.Add(new Waypoint(new GeographicPosition(), "C")); _cache.Add(new Waypoint(new GeographicPosition(), "D")); // Only part 1 of the new route was transmitted - use the old one until we have all messages for the new route. _cache.TryGetCurrentRoute(out var route); Assert.Equal(3, route.Count); Assert.Equal("RTOld", route[0].RouteName); }
//Finds localized route part for the specified content and culture //Returns true if localized url for content and culture exists; otherwise - false public bool TryFindLocalizedRoute(ContentItem routableContent, string cultureName, out RoutePart localizedRoute) { if (!routableContent.Parts.Any(p => p.Is<LocalizationPart>())) { localizedRoute = null; return false; } var siteCulture = _cultureManager.GetCultureByName(_cultureManager.GetSiteCulture()); var localizations = _localizationService.GetAvailableLocalizations(routableContent, VersionOptions.Published, siteCulture); var localizationPart = localizations.FirstOrDefault(l => l.Culture.Culture == cultureName); //try get localization part for default site culture if (localizationPart == null) { localizationPart = localizations.FirstOrDefault(l => l.Culture.Equals(siteCulture)); } if (localizationPart == null) { localizedRoute = null; return false; } var localizedContentItem = localizationPart.ContentItem; localizedRoute = localizedContentItem.Parts.Single(p => p is RoutePart).As<RoutePart>(); return true; }
public void GetNothingEmptyRoute() { var sentence1 = new RoutePart("RT", 1, 1, new List <string>()); _sink.Raise(x => x.OnNewSequence += null, null, sentence1); Assert.Equal(AutopilotErrorState.WaypointsWithoutPosition, _cache.TryGetCurrentRoute(out _)); }
//Finds route part for the specified URL //Returns true if specified url corresponds to some content and route exists; otherwise - false public bool TryGetRouteForUrl(string url, out RoutePart route) { //first check for route (fast, case sensitive, not precise) route = _contentManager.Query<RoutePart, RoutePartRecord>() .ForVersion(VersionOptions.Published) .Where(r => r.Path == url) .List() .FirstOrDefault(); return route != null; }
public void GetCompleteRouteOneElement2() { // Even with three times the same message, this should return just one route var sentence1 = new RoutePart("RT", 1, 1, new List <string>() { "A", "B" }); _sink.Raise(x => x.OnNewSequence += null, null, sentence1); _sink.Raise(x => x.OnNewSequence += null, null, sentence1); _sink.Raise(x => x.OnNewSequence += null, null, sentence1); var sentence2 = new Waypoint(new GeographicPosition(1, 2, 3), "A"); _sink.Raise(x => x.OnNewSequence += null, null, sentence2); var sentence3 = new Waypoint(new GeographicPosition(2, 3, 4), "B"); _sink.Raise(x => x.OnNewSequence += null, null, sentence3); Assert.Equal(AutopilotErrorState.RoutePresent, _cache.TryGetCurrentRoute(out var route)); Assert.Equal(2, route.Count); }
public void GetCompleteRouteOneElement() { var sentence1 = new RoutePart("RT", 1, 1, new List <string>() { "A", "B" }); _sink.Raise(x => x.OnNewSequence += null, null, sentence1); _cache.Add(new Waypoint(new GeographicPosition(), "A")); _cache.Add(new Waypoint(new GeographicPosition(), "B")); Assert.Equal(AutopilotErrorState.RoutePresent, _cache.TryGetCurrentRoute(out var route)); Assert.Equal(2, route.Count); Assert.Equal("RT", route[0].RouteName); Assert.Equal(2, route[0].TotalPointsInRoute); Assert.Equal(0, route[0].IndexInRoute); Assert.Equal("A", route[0].WaypointName); Assert.Equal("B", route[1].WaypointName); Assert.Equal(1, route[1].IndexInRoute); }
public void FindOlderRouteIfNewIsIncomplete1() { // The latest route is interesting var sentence1 = new RoutePart("RTOld", 1, 1, new List <string>() { "A", "B" }); var sentence2 = new RoutePart("RTNew", 1, 1, new List <string>() { "C", "D" }); _sink.Raise(x => x.OnNewSequence += null, null, sentence1); _sink.Raise(x => x.OnNewSequence += null, null, sentence2); _cache.Add(new Waypoint(new GeographicPosition(), "A")); _cache.Add(new Waypoint(new GeographicPosition(), "B")); // Not all waypoints for new route _cache.Add(new Waypoint(new GeographicPosition(), "D")); // This will skip the iteration Assert.Equal(AutopilotErrorState.WaypointsWithoutPosition, _cache.TryGetCurrentRoute(out _)); }
public void GetNewestRoute() { // The latest route is interesting var sentence1 = new RoutePart("RTOld", 1, 1, new List <string>() { "A", "B" }); var sentence2 = new RoutePart("RTNew", 1, 1, new List <string>() { "C", "D" }); _sink.Raise(x => x.OnNewSequence += null, null, sentence1); _sink.Raise(x => x.OnNewSequence += null, null, sentence2); _cache.Add(new Waypoint(new GeographicPosition(), "A")); _cache.Add(new Waypoint(new GeographicPosition(), "B")); _cache.Add(new Waypoint(new GeographicPosition(), "C")); _cache.Add(new Waypoint(new GeographicPosition(), "D")); _cache.TryGetCurrentRoute(out var route); Assert.Equal(2, route.Count); Assert.Equal("RTNew", route[0].RouteName); }
private static void SetModelProperties(BuildShapeContext context, RoutePart routable) { var item = context.Shape; item.Title = routable.Title; item.Slug = routable.Slug; item.Path = routable.Path; }
private void FinalizePath(RoutePart route, PublishContentContext context, Action<RoutePart> processSlug) { var path = route.Path; route.Path = route.GetPathWithSlug(route.Slug); if (context.PublishingItemVersionRecord != null) processSlug(route); // if the path has changed by having the slug changed on the way in (e.g. user input) or to avoid conflict // then update and publish all contained items if (path != route.Path) { _routablePathConstraint.RemovePath(path); _routableService.FixContainedPaths(route); } if (!string.IsNullOrWhiteSpace(route.Path)) _routablePathConstraint.AddPath(route.Path); }
private List <RoutePart>?FindLatestCompleteRoute(out string routeName) { List <RoutePart> routeSentences; lock (_lock) { // Newest shall be first in list routeSentences = _lastRouteSentences.ToList(); routeSentences.Reverse(); } if (routeSentences.Count == 0) { routeName = "No route"; return(null); } routeName = string.Empty; RoutePart?[]? elements = null; // This is initially never 0 here while (routeSentences.Count > 0) { // Last initial sequence, take this as the header for what we combine var head = routeSentences.FirstOrDefault(x => x.Sequence == 1); if (head == null) { routeName = "No complete route"; return(null); } int numberOfSequences = head.TotalSequences; routeName = head.RouteName; elements = new RoutePart[numberOfSequences + 1]; // Use 1-based indexing bool complete = false; foreach (var sentence in routeSentences) { if (sentence.RouteName == routeName && sentence.Sequence <= numberOfSequences) { // Iterate until we found one of each of the components of route elements[sentence.Sequence] = sentence; complete = true; for (int i = 1; i <= numberOfSequences; i++) { if (elements[i] == null) { complete = false; } } if (complete) { break; } } } if (complete) { break; } // The sentence with the first header we found was incomplete - try the next (we're possibly just changing the route) routeSentences.RemoveRange(0, routeSentences.IndexOf(head) + 1); } List <RoutePart> ret = new List <RoutePart>(); if (elements != null) { for (var index = 1; index < elements.Length; index++) { var elem = elements[index]; if (elem == null) { // List is incomplete return(null); } ret.Add(elem); } } return(ret.OrderBy(x => x.Sequence).ToList()); }