Exemplo n.º 1
0
        public DiscoveryClientResultCollection WriteAll(string directory, string topLevelFilename)
        {
            DiscoveryClientResultsFile results = new DiscoveryClientResultsFile();
            Hashtable filenames        = new Hashtable();
            string    topLevelFullPath = Path.Combine(directory, topLevelFilename);

            // write out each of the documents
            DictionaryEntry[] entries = new DictionaryEntry[Documents.Count + InlinedSchemas.Keys.Count];
            int i = 0;

            foreach (DictionaryEntry entry in Documents)
            {
                entries[i++] = entry;
            }
            foreach (DictionaryEntry entry in InlinedSchemas)
            {
                entries[i++] = entry;
            }
            foreach (DictionaryEntry entry in entries)
            {
                string url      = (string)entry.Key;
                object document = entry.Value;
                if (document == null)
                {
                    continue;
                }
                DiscoveryReference reference = References[url];
                string             filename  = reference == null?DiscoveryReference.FilenameFromUrl(Url) : reference.DefaultFilename;

                filename = GetUniqueFilename(filenames, Path.GetFullPath(Path.Combine(directory, filename)));
                results.Results.Add(new DiscoveryClientResult(reference == null ? null : reference.GetType(), url, GetRelativePath(filename, topLevelFullPath)));
                Stream file = File.Create(filename);
                try {
                    reference.WriteDocument(document, file);
                }
                finally {
                    file.Close();
                }
            }

            // write out the file that points to all those documents.
            XmlSerializer ser          = new XmlSerializer(typeof(DiscoveryClientResultsFile));
            Stream        topLevelFile = File.Create(topLevelFullPath);

            try {
                ser.Serialize(new StreamWriter(topLevelFile, new UTF8Encoding(false)), results);
            }
            finally {
                topLevelFile.Close();
            }

            return(results.Results);
        }
        public DiscoveryClientResultCollection WriteAll(string directory, string topLevelFilename)
        {
            DiscoveryClientResultsFile o = new DiscoveryClientResultsFile();
            Hashtable filenames          = new Hashtable();
            string    relativeTo         = Path.Combine(directory, topLevelFilename);

            DictionaryEntry[] entryArray = new DictionaryEntry[this.Documents.Count + this.InlinedSchemas.Keys.Count];
            int num = 0;

            foreach (DictionaryEntry entry in this.Documents)
            {
                entryArray[num++] = entry;
            }
            foreach (DictionaryEntry entry2 in this.InlinedSchemas)
            {
                entryArray[num++] = entry2;
            }
            foreach (DictionaryEntry entry3 in entryArray)
            {
                string key      = (string)entry3.Key;
                object document = entry3.Value;
                if (document != null)
                {
                    DiscoveryReference reference      = this.References[key];
                    string             uniqueFilename = (reference == null) ? DiscoveryReference.FilenameFromUrl(base.Url) : reference.DefaultFilename;
                    uniqueFilename = GetUniqueFilename(filenames, Path.GetFullPath(Path.Combine(directory, uniqueFilename)));
                    o.Results.Add(new DiscoveryClientResult((reference == null) ? null : reference.GetType(), key, GetRelativePath(uniqueFilename, relativeTo)));
                    Stream stream = System.IO.File.Create(uniqueFilename);
                    try
                    {
                        reference.WriteDocument(document, stream);
                    }
                    finally
                    {
                        stream.Close();
                    }
                }
            }
            XmlSerializer serializer = new XmlSerializer(typeof(DiscoveryClientResultsFile));
            Stream        stream2    = System.IO.File.Create(relativeTo);

            try
            {
                serializer.Serialize((TextWriter) new StreamWriter(stream2, new UTF8Encoding(false)), o);
            }
            finally
            {
                stream2.Close();
            }
            return(o.Results);
        }