public DiscoveryClientResultCollection ReadAll(string topLevelFilename)
        {
            XmlSerializer ser                  = new XmlSerializer(typeof(DiscoveryClientResultsFile));
            Stream        file                 = File.OpenRead(topLevelFilename);
            string        topLevelPath         = Path.GetDirectoryName(topLevelFilename);
            DiscoveryClientResultsFile results = null;

            try {
                results = (DiscoveryClientResultsFile)ser.Deserialize(file);
                for (int i = 0; i < results.Results.Count; i++)
                {
                    DiscoveryReference reference = (DiscoveryReference)Activator.CreateInstance(Type.GetType(results.Results[i].ReferenceTypeName));
                    reference.ClientProtocol = this;
                    reference.Url            = results.Results[i].Url;
                    Stream docFile = File.OpenRead(Path.Combine(topLevelPath, results.Results[i].Filename));
                    try {
                        Documents[results.Results[i].Url] = reference.ReadDocument(docFile);
                        Debug.Assert(Documents[results.Results[i].Url] != null, "Couldn't deserialize file " + results.Results[i].Filename);
                    }
                    finally {
                        docFile.Close();
                    }
                    References[reference.Url] = reference;
                }
            }
            finally {
                file.Close();
            }

            return(results.Results);
        }
        public DiscoveryClientResultCollection ReadAll(string topLevelFilename)
        {
            XmlSerializer serializer        = new XmlSerializer(typeof(DiscoveryClientResultsFile));
            Stream        stream            = System.IO.File.OpenRead(topLevelFilename);
            string        directoryName     = Path.GetDirectoryName(topLevelFilename);
            DiscoveryClientResultsFile file = null;

            try
            {
                file = (DiscoveryClientResultsFile)serializer.Deserialize(stream);
                for (int i = 0; i < file.Results.Count; i++)
                {
                    if (file.Results[i] == null)
                    {
                        throw new InvalidOperationException(Res.GetString("WebNullRef"));
                    }
                    string referenceTypeName = file.Results[i].ReferenceTypeName;
                    if ((referenceTypeName == null) || (referenceTypeName.Length == 0))
                    {
                        throw new InvalidOperationException(Res.GetString("WebRefInvalidAttribute", new object[] { "referenceType" }));
                    }
                    DiscoveryReference reference = (DiscoveryReference)Activator.CreateInstance(Type.GetType(referenceTypeName));
                    reference.ClientProtocol = this;
                    string url = file.Results[i].Url;
                    if ((url == null) || (url.Length == 0))
                    {
                        throw new InvalidOperationException(Res.GetString("WebRefInvalidAttribute2", new object[] { reference.GetType().FullName, "url" }));
                    }
                    reference.Url = url;
                    string filename = file.Results[i].Filename;
                    if ((filename == null) || (filename.Length == 0))
                    {
                        throw new InvalidOperationException(Res.GetString("WebRefInvalidAttribute2", new object[] { reference.GetType().FullName, "filename" }));
                    }
                    Stream stream2 = System.IO.File.OpenRead(Path.Combine(directoryName, file.Results[i].Filename));
                    try
                    {
                        this.Documents[reference.Url] = reference.ReadDocument(stream2);
                    }
                    finally
                    {
                        stream2.Close();
                    }
                    this.References[reference.Url] = reference;
                }
                this.ResolveAll();
            }
            finally
            {
                stream.Close();
            }
            return(file.Results);
        }
Example #3
0
        public DiscoveryClientResultCollection ReadAll(string topLevelFilename)
        {
            XmlSerializer ser                  = new XmlSerializer(typeof(DiscoveryClientResultsFile));
            Stream        file                 = File.OpenRead(topLevelFilename);
            string        topLevelPath         = Path.GetDirectoryName(topLevelFilename);
            DiscoveryClientResultsFile results = null;

            try {
                results = (DiscoveryClientResultsFile)ser.Deserialize(file);
                for (int i = 0; i < results.Results.Count; i++)
                {
                    if (results.Results[i] == null)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.WebNullRef));
                    }
                    string typeName = results.Results[i].ReferenceTypeName;
                    if (typeName == null || typeName.Length == 0)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.WebRefInvalidAttribute, "referenceType"));
                    }
                    DiscoveryReference reference = (DiscoveryReference)Activator.CreateInstance(Type.GetType(typeName));
                    reference.ClientProtocol = this;

                    string url = results.Results[i].Url;
                    if (url == null || url.Length == 0)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.WebRefInvalidAttribute2, reference.GetType().FullName, "url"));
                    }
                    reference.Url = url;
                    string fileName = results.Results[i].Filename;
                    if (fileName == null || fileName.Length == 0)
                    {
                        throw new InvalidOperationException(Res.GetString(Res.WebRefInvalidAttribute2, reference.GetType().FullName, "filename"));
                    }

                    Stream docFile = File.OpenRead(Path.Combine(topLevelPath, results.Results[i].Filename));
                    try {
                        Documents[reference.Url] = reference.ReadDocument(docFile);
                        Debug.Assert(Documents[reference.Url] != null, "Couldn't deserialize file " + results.Results[i].Filename);
                    }
                    finally {
                        docFile.Close();
                    }
                    References[reference.Url] = reference;
                }
                ResolveAll();
            }
            finally {
                file.Close();
            }
            return(results.Results);
        }
Example #4
0
        public DiscoveryClientResultCollection ReadAll(string topLevelFilename)
        {
            StreamReader  sr  = new StreamReader(topLevelFilename);
            XmlSerializer ser = new XmlSerializer(typeof(DiscoveryClientResultsFile));
            DiscoveryClientResultsFile resfile = (DiscoveryClientResultsFile)ser.Deserialize(sr);

            sr.Close();

            string basePath = Path.GetDirectoryName(topLevelFilename);

            foreach (DiscoveryClientResult dcr in resfile.Results)
            {
                Type type             = Type.GetType(dcr.ReferenceTypeName);
                DiscoveryReference dr = (DiscoveryReference)Activator.CreateInstance(type);
                dr.Url = dcr.Url;
                FileStream fs = new FileStream(Path.Combine(basePath, dcr.Filename), FileMode.Open, FileAccess.Read);
                Documents.Add(dr.Url, dr.ReadDocument(fs));
                fs.Close();
                References.Add(dr.Url, dr);
            }
            return(resfile.Results);
        }