示例#1
0
 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();
 }
示例#2
0
 /// <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);
     }
 }
示例#3
0
 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();
 }
示例#4
0
 public void RepopulateHyperMedia()
 {
     CreateHypermedia();
     if (Links.Count(l => l.Rel == "self") == 0)
     {
         Links.Insert(0, new Link {
             Rel = "self", Href = Href
         });
     }
 }
示例#5
0
 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);
            }
        }
示例#7
0
        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
            }
        }
示例#8
0
        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);
            }
        }
示例#9
0
 private bool IsGarbage(LinkIndex link) => link != Options.SequenceMarkerLink && !Links.Unsync.IsPartialPoint(link) && Links.Count(Constants.Any, link) == 0;
示例#10
0
文件: Vertex.cs 项目: MilkyFayde/WPF
        } // IsLinkExists

        public int GetLinksCount() => Links.Count();
示例#11
0
 public RelatedWebsites(IEnumerable <RelatedWebsiteLink> links)
 {
     Links   = links.OrderBy(link => link.Title).ToArray();
     Current = Links.FirstOrDefault(e => e.IsCurrent);
     Any     = Links.Count() > 1 && Current != null;
 }