Exemplo n.º 1
0
        private void SaveContent(XElement node, IContent content, Content newContent, ZipFile zip)
        {
            var dataTypes = new Config().GetSpecialDataTypes();

            content.ParentId = GetContentParentId(newContent);
            content.SortOrder = newContent.SortOrder;
            content.Name = newContent.Name;
            content.CreatorId = User.GetCurrent().Id;
            content.WriterId = User.GetCurrent().Id;

            if (content.Template != null)
            {
                content.Template.Id = newContent.TemplateId;
            }

            if (newContent.ReleaseDate != DateTime.MinValue)
            {
                content.ReleaseDate = newContent.ReleaseDate;
            }

            if (newContent.ExpireDate != DateTime.MinValue)
            {
                content.ExpireDate = newContent.ExpireDate;
            }

            foreach (var propertyTag in node.Elements())
            {
                var dataTypeGuid = new Guid(propertyTag.Attribute("dataTypeGuid").Value);

                var value = propertyTag.Value;

                // The null check here is necessary. Blank content exports into the xml, which is fine, since on
                // import the blank value gets mapped across. However, for upload datatypes, this blank value
                // causes an exception here - unless we perform the null check.
                if (dataTypeGuid == new Guid(Constants.UploadDataTypeGuid) && propertyTag.Attribute("fileName") != null)
                {
                    var fileName = propertyTag.Attribute("fileName").Value;
                    var umbracoFile = propertyTag.Attribute("umbracoFile").Value;

                    if (!string.IsNullOrWhiteSpace(umbracoFile))
                    {
                        content.SetValue(propertyTag.Name.ToString(), fileName, GetFileStream(umbracoFile, zip));
                    }
                    else
                    {
                        content.SetValue(propertyTag.Name.ToString(), string.Empty);
                    }
                }
                else if (!dataTypes.ContainsKey(dataTypeGuid))
                {
                    content.SetValue(propertyTag.Name.ToString(), value);
                }
            }

            SaveContent(content, bool.Parse(node.Attribute("published").Value));
        }
 protected BaseContentManagement()
 {
     SpecialDataTypes = new Config().GetSpecialDataTypes();
     Services = ApplicationContext.Current.Services;
 }