LoadJsonData() private method

private LoadJsonData ( TextReader jsonReader ) : void
jsonReader System.IO.TextReader
return void
Esempio n. 1
0
        public static SynthData LoadFromZipFile(string path)
        {
            SynthData synthData = new SynthData();

            try
            {
                using (ZipFile zipFile = new ZipFile(path))
                {
                    using (MemoryStream stream = new MemoryStream())
                    {
                        zipFile["0.json"].Extract(stream);

                        stream.Seek(0, SeekOrigin.Begin);

                        synthData.LoadJsonData(new StreamReader(stream));
                    }

                    foreach (ZipEntry zipEntry in zipFile)
                    {
                        string name = zipEntry.FileName.ToLower();

                        if (!name.StartsWith("points_") || !name.EndsWith(".bin"))
                            continue;

                        int i = name.IndexOf('_', 7);

                        if (i < 0)
                            continue;

                        int coordSystem;

                        if (!int.TryParse(name.Substring(7, i - 7), out coordSystem))
                            continue;

                        int index;

                        if (!int.TryParse(name.Substring(i + 1, name.Length - i - 5), out index))
                            continue;

                        using (MemoryStream stream = new MemoryStream())
                        {
                            zipEntry.Extract(stream);

                            stream.Seek(0, SeekOrigin.Begin);

                            synthData.CoordinateSystems[coordSystem].PointCloud.LoadBinFile(stream);
                        }
                    }
                }
            }
            catch (ZipException e)
            {
                throw new SynthDataLoadException("Could not extract synth data and point clouds from zip archive. The file seems to be corrupted.", e);
            }

            return synthData;
        }
Esempio n. 2
0
        public static SynthData Load(string collectionID)
        {
            SynthData synthData = new SynthData();

            synthData.CollectionID = collectionID;

            string jsonUrl;

            try
            {
                using (PhotosynthServiceSoapClient soapClient = new PhotosynthServiceSoapClient("PhotosynthServiceSoap"))
                {
                    CollectionResult collectionResult = soapClient.GetCollectionData(new Guid(collectionID), false);

                    if (collectionResult.Result != Result.OK)
                        throw new SynthDataLoadException(string.Format("The Photosynth web service returned an error (Error code: {0}). Make sure the URL you entered is correct and the synth exists.", collectionResult.Result));

                    if (collectionResult.CollectionType != CollectionType.Synth)
                        throw new SynthDataLoadException("The URL you have entered belongs to a panorama hosted on photosynth.net. SynthExport is compatible with photosynths only.");

                    synthData.CollectionRoot = collectionResult.CollectionRoot;
                    jsonUrl = collectionResult.JsonUrl;
                }
            }
            catch (CommunicationException e)
            {
                throw new SynthDataLoadException("An error occurred while trying to contact the Photosynth web service.", e);
            }

            string jsonString;

            try
            {
                using (WebClient webClient = new WebClient())
                    jsonString = webClient.DownloadString(jsonUrl);
            }
            catch (WebException e)
            {
                throw new SynthDataLoadException("An error occured while downloading synth data.", e);
            }

            synthData.LoadJsonData(new StringReader(jsonString));

            return synthData;
        }