Exemplo n.º 1
0
        public static CrawlerQueue LoadFromFile(string fileName)
        {
            var br    = Utilities.GetReaderForFile(fileName);
            var queue = new CrawlerQueue();

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

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

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

            // Entries
            var entryCount = br.ReadInt32();

            for (var i = 0; i < entryCount; i++)
            {
                queue.AddLink(br.ReadString());
            }

            br.Close();

            return(queue);
        }
Exemplo n.º 2
0
        public static void SaveToFile(string fileName, CrawlerQueue queue)
        {
            var bw = Utilities.GetWriterForFile(fileName);

            // Header
            bw.Write(FileIdent);
            bw.Write(FileVersion);

            // Entries
            var entries = queue._backlog.ToArray();

            bw.Write(entries.Length);
            foreach (var entry in entries)
            {
                bw.Write(entry);
            }

            bw.Close();
        }