Exemple #1
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);
                }
            }
        }
Exemple #2
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);
            }
        }