Exemplo n.º 1
0
        private static void DeserializeSource(StreamReader reader, GallerySource source)
        {
            string objectPrefix;

            string[] deserializedObject = ObjectSerializer.Deserialize(reader.ReadLine(), out objectPrefix);
            if (objectPrefix != "GS")
            {
                throw new Exception("Failed to deserialize source database; gallery source missing");
            }
            string rootFolderID = source.LoadFromDeserialized(deserializedObject);

            IDictionary <string, FileSystemEntry> fileSystemEntries = new Dictionary <string, FileSystemEntry>();
            string serializedObject = reader.ReadLine();

            while (serializedObject != null)
            {
                try
                {
                    deserializedObject = ObjectSerializer.Deserialize(serializedObject, out objectPrefix);
                    switch (objectPrefix)
                    {
                    case "MC":
                        MediaCodec mediaCodec = new MediaCodec();
                        mediaCodec.LoadFromDeserialized(deserializedObject);
                        source.Codecs.Add(mediaCodec);
                        break;

                    default:
                        DeserializeSubFolders(fileSystemEntries, objectPrefix, deserializedObject, source);
                        break;
                    }
                }
                catch { }
                if (fileSystemEntries.Count % 100 == 0)
                {
                    RaiseStatusUpdatedEvent("Loading source (" + source.Path + ")... " + (100 * (double)fileSystemEntries.Count / (source.ImageCount + source.VideoCount)).ToString("0.0") + "%");
                }
                serializedObject = reader.ReadLine();
            }
            if (!fileSystemEntries.ContainsKey(rootFolderID))
            {
                throw new Exception("Failed to deserialize source database; root object does not exist");
            }
            MediaFolder rootFolder = fileSystemEntries[rootFolderID] as MediaFolder;

            if (rootFolder == null)
            {
                throw new Exception("Failed to deserialize source database; parent root object is not a folder");
            }
            source.RootFolder = rootFolder;
        }