Exemplo n.º 1
0
        // Loads an .nzb file
        public static FileCollection loadFile(string filename)
        {
            // Loadtime measuring
            Performance.Stopwatch sw = new Performance.Stopwatch();
            sw.Start();

            XmlDocument document = new XmlDocument();
            FileStream stream = File.Open(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            // Inits xmlreader with custom resolver for instant dtd file lookup
            XmlReaderSettings settings = new XmlReaderSettings();
            settings.ProhibitDtd = false;
            settings.XmlResolver = new XmlFileResolver();

            // Create new FIleCOllection object

            FileCollection collection = new FileCollection(getPrettyFilename(filename));

            // Parse file into XmlDocument
            document.Load(XmlReader.Create(stream, settings));
            stream.Close();

            List<FileJob> files = ParseXML(document, collection);
            collection.files = files;

            // Calculate collection size
            collection.CalculateTotalSize();
            // Loadtime measuring
            sw.Stop();
            Logging.Instance.Log("Loading {0}. Took {1}ms", filename, sw.GetElapsedTimeSpan().TotalMilliseconds);
            return collection;
        }