private LinkIndex CountUsages(params LinkIndex[] restrictions) { if (restrictions.Length == 0) { return(0); } if (restrictions.Length == 1) // Первая связь это адрес { if (restrictions[0] == Constants.Null) { return(0); } var any = Constants.Any; if (Options.UseSequenceMarker) { var elementsLink = GetSequenceElements(restrictions[0]); var sequenceLink = GetSequenceByElements(elementsLink); if (sequenceLink != Constants.Null) { return(Links.Count(any, sequenceLink) + Links.Count(any, elementsLink) - 1); } return(Links.Count(any, elementsLink)); } return(Links.Count(any, restrictions[0])); } throw new NotImplementedException(); }
/// <summary> /// Adds a link to the entity. /// </summary> /// <param name="link">The link.</param> /// <exception cref="T:System.ArgumentNullException">link</exception> public void AddLink(Link link) { if (link == null) { throw new ArgumentNullException("link"); } if (Links == null) { Links = new List <Link>(); } if (link is SelfLink) { this.HRef = link.HRef; if (this.GetType().IsGenericType&& typeof(IEnumerable).IsAssignableFrom(this.GetType()) && typeof(Resource).IsAssignableFrom(this.GetType().GetGenericArguments()[0])) { this.Rel = this.GetType().GetGenericArguments()[0].Name; } else { this.Rel = this.GetType().Name; } if (Links.Count(x => x.Rel == link.Rel) > 0) { Links.Remove(Links.First(x => x.Rel == link.Rel)); } } if (Links.Count(x => x.Rel == link.Rel && x.HRef == link.HRef) == 0) { Links.Add(link); } }
public LinkIndex Count(IList <LinkIndex> restrictions) { if (restrictions.IsNullOrEmpty()) { return(Links.Count(Constants.Any, Options.SequenceMarkerLink, Constants.Any)); } if (restrictions.Count == 1) // Первая связь это адрес { var sequenceIndex = restrictions[0]; if (sequenceIndex == Constants.Null) { return(0); } if (sequenceIndex == Constants.Any) { return(Count(null)); } if (Options.UseSequenceMarker) { return(Links.Count(Constants.Any, Options.SequenceMarkerLink, sequenceIndex)); } return(Links.Exists(sequenceIndex) ? 1UL : 0); } throw new NotImplementedException(); }
public void RepopulateHyperMedia() { CreateHypermedia(); if (Links.Count(l => l.Rel == "self") == 0) { Links.Insert(0, new Link { Rel = "self", Href = Href }); } }
public void RepopulateHyperMedia() { CreateHypermedia(); if (!string.IsNullOrEmpty(Href) && Links.Count(l => l.Rel == "self") == 0) { Links.Insert(0, new Link { Rel = "self", Href = Href }); } }
protected override void CreateHypermedia() { base.CreateHypermedia(); var search = LinkTemplates.Beers.SearchBeers; if (Links.Count(l => l.Rel == search.Rel && l.Href == search.Href) == 0) { Links.Add(LinkTemplates.Beers.SearchBeers); } }
public void RepopulateHyperMedia() { if (Links == null) { Links = new List <Link>(); // make sure resource.Links.Add() can safely be called inside the overload } CreateHypermedia(); if (!string.IsNullOrEmpty(Href) && Links.Count(l => l.Rel == "self") == 0) { Links.Insert(0, new Link { Rel = "self", Href = Href }); } if ((Links != null) && !Links.Any()) { Links = null; // prevent _links property serialisation } }
public Tweet(Status status) { Id = status.Id; CreatedAt = status.CreatedAt; UserId = status.User.Id ?? 0; ScreenName = status.User.ScreenName; UserName = status.User.Name; IsRetweetedTweet = status.RetweetedStatus != null; if (IsRetweetedTweet) { var retweetedStatus = status.RetweetedStatus; RetweetedCreatedAt = retweetedStatus.CreatedAt; RetweetedUserId = retweetedStatus.User.Id ?? 0; RetweetedUserScreenName = retweetedStatus.User.ScreenName; RetweetedUserName = retweetedStatus.User.Name; Media = retweetedStatus.ExtendedEntities?.Media.Select(m => new Media(retweetedStatus.Id, m)).ToArray(); FullText = retweetedStatus.FullText; Links = retweetedStatus.Entities?.Urls?.ToArray(); HasLinks = 0 < (Links?.Count() ?? 0); Source = retweetedStatus.Source; QuotedTweet = retweetedStatus.QuotedStatus == null ? null : new Tweet(retweetedStatus.QuotedStatus); } else { Media = status.ExtendedEntities?.Media.Select(m => new Media(Id, m)).ToArray(); FullText = status.FullText; Links = status.Entities?.Urls?.ToArray(); HasLinks = 0 < (Links?.Count() ?? 0); Source = status.Source; QuotedTweet = status.QuotedStatus == null ? null : new Tweet(status.QuotedStatus); } }
private bool IsGarbage(LinkIndex link) => link != Options.SequenceMarkerLink && !Links.Unsync.IsPartialPoint(link) && Links.Count(Constants.Any, link) == 0;
} // IsLinkExists public int GetLinksCount() => Links.Count();
public RelatedWebsites(IEnumerable <RelatedWebsiteLink> links) { Links = links.OrderBy(link => link.Title).ToArray(); Current = Links.FirstOrDefault(e => e.IsCurrent); Any = Links.Count() > 1 && Current != null; }