Ejemplo n.º 1
0
        public virtual bool ReadYaml(YamlReader reader)
        {
            var version = reader.PeekMap();

            if (!version.HasValue || !version.Value.Key.Equals("Version", StringComparison.Ordinal))
            {
                return(false);
            }

            VersionNumber = int.Parse(reader.ReadExpectedMap("Version"));

            var fields = reader.PeekMap();

            if (fields.HasValue && fields.Value.Key.Equals("Fields", StringComparison.Ordinal))
            {
                reader.ReadMap();
                while (true)
                {
                    var field = new YamlFieldValue();
                    if (field.ReadYaml(reader))
                    {
                        Fields.Add(field);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 2
0
        public virtual void LoadFrom(IItemData itemData, IFieldFormatter[] fieldFormatters)
        {
            Id           = itemData.Id;
            DatabaseName = itemData.DatabaseName;
            ParentId     = itemData.ParentId;
            TemplateId   = itemData.TemplateId;
            Path         = itemData.Path;

            BranchId = itemData.BranchId;

            foreach (var field in itemData.SharedFields)
            {
                var fieldObject = new YamlFieldValue();
                fieldObject.LoadFrom(field, fieldFormatters);

                SharedFields.Add(fieldObject);
            }

            var languages = itemData.Versions.GroupBy(x => x.Language.Name);

            foreach (var language in languages)
            {
                var languageObject = new YamlLanguage();
                languageObject.LoadFrom(language, fieldFormatters);

                if (languageObject.Versions.Count > 0)
                {
                    Languages.Add(languageObject);
                }
            }

            foreach (var unversionedFieldLanguage in itemData.UnversionedFields)
            {
                var existing = Languages.FirstOrDefault(language => language.Language == unversionedFieldLanguage.Language.Name);

                if (existing == null)
                {
                    existing = new YamlLanguage {
                        Language = unversionedFieldLanguage.Language.Name
                    };
                    Languages.Add(existing);
                }

                foreach (var unversionedField in unversionedFieldLanguage.Fields)
                {
                    var field = new YamlFieldValue();
                    field.LoadFrom(unversionedField, fieldFormatters);

                    existing.UnversionedFields.Add(field);
                }
            }
        }
Ejemplo n.º 3
0
        public void LoadFrom(IItemVersion version, IFieldFormatter[] fieldFormatters)
        {
            VersionNumber = version.VersionNumber;

            foreach (var field in version.Fields)
            {
                var fieldObject = new YamlFieldValue();

                fieldObject.LoadFrom(field, fieldFormatters);

                Fields.Add(fieldObject);
            }
        }
Ejemplo n.º 4
0
        public bool ReadYaml(YamlReader reader)
        {
            var language = reader.PeekMap();

            if (!language.HasValue || !language.Value.Key.Equals("Language", StringComparison.Ordinal))
            {
                return(false);
            }

            Language = reader.ReadExpectedMap("Language");

            var fields = reader.PeekMap();

            if (fields.HasValue && fields.Value.Key.Equals("Fields", StringComparison.OrdinalIgnoreCase))
            {
                reader.ReadExpectedMap("Fields");
                while (true)
                {
                    var field = new YamlFieldValue();
                    if (field.ReadYaml(reader))
                    {
                        UnversionedFields.Add(field);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            reader.ReadExpectedMap("Versions");

            while (true)
            {
                var version = new YamlVersion();
                if (version.ReadYaml(reader))
                {
                    Versions.Add(version);
                }
                else
                {
                    break;
                }
            }

            return(true);
        }
Ejemplo n.º 5
0
        public virtual void ReadYaml(YamlReader reader)
        {
            Id         = reader.ReadExpectedGuidMap("ID");
            ParentId   = reader.ReadExpectedGuidMap("Parent");
            TemplateId = reader.ReadExpectedGuidMap("Template");
            Path       = reader.ReadExpectedMap("Path");

            var dbName = reader.PeekMap();

            if (dbName.HasValue && dbName.Value.Key.Equals("DB"))             //could be missing if serialized with 1.0.x
            {
                reader.ReadMap();
                DatabaseName = dbName.Value.Value;
            }

            var branch = reader.PeekMap();

            if (branch.HasValue && branch.Value.Key.Equals("BranchID"))
            {
                reader.ReadMap();
                BranchId = Guid.Parse(branch.Value.Value);
            }

            var sharedFields = reader.PeekMap();

            if (sharedFields.HasValue && sharedFields.Value.Key.Equals("SharedFields"))
            {
                reader.ReadMap();
                while (true)
                {
                    var field = new YamlFieldValue();
                    if (field.ReadYaml(reader))
                    {
                        SharedFields.Add(field);
                    }
                    else
                    {
                        break;
                    }
                }
            }

            var languages = reader.PeekMap();

            if (languages.HasValue && languages.Value.Key.Equals("Languages"))
            {
                reader.ReadMap();
                while (true)
                {
                    var language = new YamlLanguage();
                    if (language.ReadYaml(reader))
                    {
                        Languages.Add(language);
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }