예제 #1
0
        public void AddLink(CrawlerLink link)
        {
            if (this.AddressLookup.ContainsKey(link.Address))
            {
                return;
            }

            var nextId = this.LastId + 1;

            link.UniqueId = nextId;
            this.LastId   = nextId;

            this.Links[nextId] = link;
            this.AddressLookup[link.Address] = nextId;

            this._isDirty     = true;
            this._hasPageRank = false;
        }
예제 #2
0
        public static CrawlerRegistry LoadFromFile(string fileName)
        {
            var br       = Utilities.GetReaderForFile(fileName);
            var registry = new CrawlerRegistry();

            if (br == null)
            {
                return(registry);
            }

            // Header
            var ident = br.ReadString();
            var ver   = br.ReadInt32();

            if (!ident.Equals(FileIdent) || ver != FileVersion)
            {
                throw new FileLoadException("Incorrect file format!");
            }

            var maxId      = 0;
            var entryCount = br.ReadInt32();

            for (var i = 0; i < entryCount; i++)
            {
                var key  = br.ReadInt32();
                var link = new CrawlerLink(br);

                registry.Links.Add(key, link);
                registry.AddressLookup[link.Address] = key;

                if (key > maxId)
                {
                    maxId = key;
                }
            }

            registry.LastId       = maxId;
            registry._isDirty     = true;
            registry._hasPageRank = false;

            br.Close();

            return(registry);
        }