Пример #1
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();
 }
Пример #2
0
 public bool Exist(Link link)
 {
     if (Links.Exists(p => p.Url == link.Url && p.TimeDuration != -1))
     {
         return(true);
     }
     return(false);
 }
Пример #3
0
        /// <summary>
        /// If Link not founded in allLinks, add the Link and return AddState.AddAsNew
        /// If Link exist in allLinks and input Link have different location it
        ///              setup the link Location.All and return AddAsAllLocation
        /// If input Link exist in allLinks and it equal, function return ExistEquals
        /// </summary>
        public async Task <AddState> AddAsync(Link link)
        {
            link.Url = LinkFilter.WWWConvert(link.Url);

            if (link.Url.EndsWith("/") == false)
            {
                link.Url = link.Url + "/";
            }

            if (Links.Exists(p => (p.Url == link.Url)) == false)
            {
                lock (this.Links)
                {
                    this.Links.Add(link);
                }
                return(AddState.AddAsNew);
            }
            else
            {
                Link foundedLink = this.Links.Find(p => (p.Url == link.Url));

                if (foundedLink.TimeDuration == -1 && link.TimeDuration == -1)
                {
                    return(AddState.ExistWithoutTime);
                }

                if (foundedLink.TimeDuration == -1)
                {
                    foundedLink.TimeDuration = link.TimeDuration;
                }

                if (foundedLink.LocationUrl != link.LocationUrl && foundedLink.LocationUrl != LocationUrl.All)
                {
                    foundedLink.LocationUrl = LocationUrl.All;
                    return(AddState.AddAsAllLocation);
                }

                return(AddState.ExistNormal);
            }
        }
Пример #4
0
        } // Vertex

        public bool IsLinkExists(Vertex v) =>
        Links.Exists(x => x.From == this) && Links.Exists(x => x.To == v) || Links.Exists(x => x.From == v) && Links.Exists(x => x.To == this);