Exemplo n.º 1
0
        public ObjectFormatVersion GetMergedObjectFormatVersion(int[] ids, int parentId, bool pageOrTemplate)
        {
            if (ids == null)
            {
                throw new ArgumentNullException(nameof(ids));
            }

            if (ids.Length != 2)
            {
                throw new ArgumentException("Wrong ids length");
            }

            var result   = GetOrderedIds(ids);
            var version1 = PageTemplateRepository.ReadFormatVersion(result.Item1);

            if (version1 == null)
            {
                throw new Exception(string.Format(TemplateStrings.FormatVersionNotFoundForFormat, result.Item1, parentId));
            }

            ObjectFormatVersion version2;

            if (result.Item2 == ObjectFormatVersion.CurrentVersionId)
            {
                var parent = ObjectFormatRepository.ReadObjectFormat(parentId, pageOrTemplate);
                if (parent == null)
                {
                    throw new Exception(string.Format(TemplateStrings.FormatNotFound, parentId));
                }

                version2 = new ObjectFormatVersion
                {
                    Name               = parent.Name,
                    NetFormatName      = parent.NetFormatName,
                    Description        = parent.Description,
                    NetLanguage        = parent.NetLanguageId.HasValue ? PageTemplateRepository.GetNetLanguageById(parent.NetLanguageId.Value) : null,
                    FormatBody         = parent.FormatBody,
                    CodeBehind         = parent.CodeBehind,
                    LastModifiedByUser = parent.LastModifiedByUser,
                    Modified           = parent.Modified
                };
            }
            else
            {
                version2 = PageTemplateRepository.ReadFormatVersion(result.Item2);
                if (version2 == null)
                {
                    throw new Exception(string.Format(TemplateStrings.FormatVersionNotFoundForFormat, result.Item2, parentId));
                }
            }

            version1.MergeToVersion(version2);
            return(version1);
        }