private static SyncVersion ReadVersion(Tokenizer reader)
        {
            SyncVersion syncVersion = new SyncVersion();
            SyncVersion result;

            try
            {
                Dictionary <string, string> dictionary = ReadHeaders(reader);
                syncVersion.Language = dictionary["language"];
                syncVersion.Version  = dictionary["version"];
                syncVersion.Revision = dictionary["revision"];
                reader.NextLine();
                while (reader.Line == "----field----")
                {
                    SyncField syncField = SyncField.ReadField(reader);
                    if (syncField != null)
                    {
                        syncVersion.Fields.Add(syncField);
                    }
                }
                result = syncVersion;
            }
            catch (Exception innerException)
            {
                throw new Exception(string.Format("Failed to load version {0} for language {1}", syncVersion.Version, syncVersion.Language), innerException);
            }
            return(result);
        }
        private static SyncItem ReadItem(Tokenizer reader, bool assertVersion)
        {
            SyncItem syncItem = null;

            while (reader.Line != null && reader.Line.Length == 0)
            {
                reader.NextLine();
            }
            if (reader.Line == null || reader.Line != "----item----")
            {
                throw new Exception("Format error: serialized stream does not start with ----item----");
            }
            syncItem = new SyncItem();
            Dictionary <string, string> dictionary = ReadHeaders(reader);

            syncItem.ID = dictionary["id"];
            int num;

            if (assertVersion && !string.IsNullOrEmpty(dictionary["version"]) && int.TryParse(dictionary["version"], out num) && SyncItem.FormatVersion < num)
            {
                throw new Exception(string.Concat(new object[]
                {
                    "The file was generated using a newer version of Serialization. (",
                    SyncItem.FormatVersion,
                    " < ",
                    num,
                    ")"
                }));
            }
            syncItem.ItemPath = dictionary["path"];
            SyncItem result;

            try
            {
                syncItem.DatabaseName = dictionary["database"];
                syncItem.ParentID     = dictionary["parent"];
                syncItem.Name         = dictionary["name"];
                syncItem.BranchId     = dictionary["master"];
                syncItem.TemplateID   = dictionary["template"];
                syncItem.TemplateName = dictionary["templatekey"];
                reader.NextLine();
                while (reader.Line == "----field----")
                {
                    SyncField syncField = SyncField.ReadField(reader);
                    if (syncField != null)
                    {
                        syncItem.SharedFields.Add(syncField);
                    }
                }
                while (reader.Line == "----version----")
                {
                    SyncVersion syncVersion = ReadVersion(reader);
                    if (syncVersion != null)
                    {
                        syncItem.Versions.Add(syncVersion);
                    }
                }
                result = syncItem;
            }
            catch (Exception innerException)
            {
                throw new Exception("Error reading item: " + syncItem.ItemPath, innerException);
            }
            return(result);
        }