Beispiel #1
0
        public static IPublishedContent Create(
            IMember member,
            IPublishedContentType contentType,
            bool previewing,
            IPublishedSnapshotAccessor publishedSnapshotAccessor,
            IVariationContextAccessor variationContextAccessor,
            IPublishedModelFactory publishedModelFactory)
        {
            var d = new ContentData
            {
                Name        = member.Name,
                Published   = previewing,
                TemplateId  = -1,
                VersionDate = member.UpdateDate,
                WriterId    = member.CreatorId, // what else?
                Properties  = GetPropertyValues(contentType, member)
            };
            var n = new ContentNode(
                member.Id,
                member.Key,
                contentType,
                member.Level,
                member.Path,
                member.SortOrder,
                member.ParentId,
                member.CreateDate,
                member.CreatorId);

            return(new PublishedMember(member, n, d, publishedSnapshotAccessor, variationContextAccessor, publishedModelFactory)
                   .CreateModel(publishedModelFactory));
        }
        /// <summary>
        /// Setup mocks for IPublishedSnapshotAccessor
        /// </summary>
        private IPublishedSnapshotAccessor GetPublishedSnapshotAccessor()
        {
            IPublishedContentType test1ContentType = Mock.Of <IPublishedContentType>(x =>
                                                                                     x.IsElement == true &&
                                                                                     x.Key == _contentKey1 &&
                                                                                     x.Alias == ContentAlias1);
            IPublishedContentType test2ContentType = Mock.Of <IPublishedContentType>(x =>
                                                                                     x.IsElement == true &&
                                                                                     x.Key == _contentKey2 &&
                                                                                     x.Alias == ContentAlias2);
            IPublishedContentType test3ContentType = Mock.Of <IPublishedContentType>(x =>
                                                                                     x.IsElement == true &&
                                                                                     x.Key == _settingKey1 &&
                                                                                     x.Alias == SettingAlias1);
            IPublishedContentType test4ContentType = Mock.Of <IPublishedContentType>(x =>
                                                                                     x.IsElement == true &&
                                                                                     x.Key == _settingKey2 &&
                                                                                     x.Alias == SettingAlias2);
            var contentCache = new Mock <IPublishedContentCache>();

            contentCache.Setup(x => x.GetContentType(_contentKey1)).Returns(test1ContentType);
            contentCache.Setup(x => x.GetContentType(_contentKey2)).Returns(test2ContentType);
            contentCache.Setup(x => x.GetContentType(_settingKey1)).Returns(test3ContentType);
            contentCache.Setup(x => x.GetContentType(_settingKey2)).Returns(test4ContentType);
            IPublishedSnapshot         publishedSnapshot         = Mock.Of <IPublishedSnapshot>(x => x.Content == contentCache.Object);
            IPublishedSnapshotAccessor publishedSnapshotAccessor = Mock.Of <IPublishedSnapshotAccessor>(x => x.TryGetPublishedSnapshot(out publishedSnapshot));

            return(publishedSnapshotAccessor);
        }
Beispiel #3
0
        // initializes a new instance of the PublishedElement class
        // within the context of a published snapshot service (eg a published content property value)
        public PublishedElement(IPublishedContentType contentType, Guid key, Dictionary <string, object> values, bool previewing,
                                PropertyCacheLevel referenceCacheLevel, IPublishedSnapshotAccessor publishedSnapshotAccessor)
        {
            if (key == Guid.Empty)
            {
                throw new ArgumentException("Empty guid.");
            }
            if (values == null)
            {
                throw new ArgumentNullException(nameof(values));
            }
            if (referenceCacheLevel != PropertyCacheLevel.None && publishedSnapshotAccessor == null)
            {
                throw new ArgumentNullException("A published snapshot accessor is required when referenceCacheLevel != None.", nameof(publishedSnapshotAccessor));
            }

            ContentType = contentType ?? throw new ArgumentNullException(nameof(contentType));
            Key         = key;

            values = GetCaseInsensitiveValueDictionary(values);

            _propertiesArray = contentType
                               .PropertyTypes
                               .Select(propertyType =>
            {
                values.TryGetValue(propertyType.Alias, out var value);
                return((IPublishedProperty) new PublishedElementPropertyBase(propertyType, this, previewing, referenceCacheLevel, value, publishedSnapshotAccessor));
            })
                               .ToArray();
        }
        public void CacheUnknownTest()
        {
            var converter = new CacheConverter1(PropertyCacheLevel.Unknown);

            var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[]
            {
                converter,
            });

            var dataTypeServiceMock = new Mock <IDataTypeService>();
            var dataType            = new DataType(
                new VoidEditor(
                    Mock.Of <IDataValueEditorFactory>()), new ConfigurationEditorJsonSerializer())
            {
                Id = 1
            };

            dataTypeServiceMock.Setup(x => x.GetAll()).Returns(dataType.Yield);

            var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of <IPublishedModelFactory>(), converters, dataTypeServiceMock.Object);

            IEnumerable <IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
            {
                yield return(publishedContentTypeFactory.CreatePropertyType(contentType, "prop1", 1));
            }

            IPublishedContentType setType1 = publishedContentTypeFactory.CreateContentType(Guid.NewGuid(), 1000, "set1", CreatePropertyTypes);

            Assert.Throws <Exception>(() =>
            {
                var unused = new PublishedElement(setType1, Guid.NewGuid(), new Dictionary <string, object> {
                    { "prop1", "1234" }
                }, false);
            });
        }
Beispiel #5
0
        public PublishedMember(
            IMember member,
            IPublishedContentType publishedMemberType,
            IVariationContextAccessor variationContextAccessor) : base(variationContextAccessor)
        {
            _member              = member ?? throw new ArgumentNullException(nameof(member));
            _membershipUser      = member;
            _publishedMemberType = publishedMemberType ?? throw new ArgumentNullException(nameof(publishedMemberType));

            // RawValueProperty is used for two things here
            // - for the 'map properties' thing that we should really get rid of
            // - for populating properties that every member should always have, and that we force-create
            //   if they are not part of the member type properties - in which case they are created as
            //   simple raw properties - which are completely invariant

            var properties = new List <IPublishedProperty>();

            foreach (var propertyType in _publishedMemberType.PropertyTypes)
            {
                var property = _member.Properties[propertyType.Alias];
                if (property == null)
                {
                    continue;
                }

                properties.Add(new RawValueProperty(propertyType, this, property.GetValue()));
            }
            EnsureMemberProperties(properties);
            _properties = properties.ToArray();
        }
        public static IPublishedPropertyType?GetModelPropertyType <TModel, TValue>(IPublishedContentType contentType, Expression <Func <TModel, TValue> > selector)
        //where TModel : PublishedContentModel // fixme PublishedContentModel _or_ PublishedElementModel
        {
            // fixme therefore, missing a check on TModel here

            var expr = selector.Body as MemberExpression;

            if (expr == null)
            {
                throw new ArgumentException("Not a property expression.", nameof(selector));
            }

            // there _is_ a risk that contentType and T do not match
            // see note above : accepted risk...

            var attr = expr.Member
                       .GetCustomAttributes(typeof(ImplementPropertyTypeAttribute), false)
                       .OfType <ImplementPropertyTypeAttribute>()
                       .SingleOrDefault();

            if (string.IsNullOrWhiteSpace(attr?.Alias))
            {
                throw new InvalidOperationException($"Could not figure out property alias for property \"{expr.Member.Name}\".");
            }

            return(contentType.GetPropertyType(attr.Alias));
        }
 public virtual IEnumerable <IPublishedContent> GetByContentType(IPublishedContentType contentType)
 {
     // this is probably not super-efficient, but works
     // some cache implementation may want to override it, though
     return(GetAtRoot()
            .SelectMany(x => x.DescendantsOrSelf())
            .Where(x => x.ContentType.Id == contentType.Id));
 }
Beispiel #8
0
        public DetachedPublishedElement(Guid key, IPublishedContentType contentType, IEnumerable <IPublishedProperty> properties)
        {
            Key         = key;
            ContentType = contentType;
            Properties  = properties;

            _propertyLookup = properties.ToDictionary(x => x.Alias, StringComparer.OrdinalIgnoreCase);
        }
Beispiel #9
0
 public SkybrudPublishedElement(IPublishedElement parent, Guid key, string name, IPublishedContentType contentType, IEnumerable <IPublishedProperty> properties)
 {
     Parent      = parent;
     Key         = key;
     Name        = name;
     ContentType = contentType;
     Properties  = properties;
 }
Beispiel #10
0
        public static string GetIcon(this IPublishedContentType contentType, IContentTypeService contentTypeService = null)
        {
            if (contentType != null && ContentTypeCacheHelper.TryGetIcon(contentType.Alias, out var icon, contentTypeService) == true)
            {
                return(icon);
            }

            return(UmbConstants.Icons.DefaultIcon);
        }
Beispiel #11
0
        public InternalPublishedContent(IPublishedContentType contentType)
        {
            // initialize boring stuff
            TemplateId = 0;
            WriterId   = CreatorId = 0;
            CreateDate = UpdateDate = DateTime.Now;
            Version    = Guid.Empty;

            ContentType = contentType;
        }
Beispiel #12
0
 /// <summary>
 /// Get the GUID key from an <see cref="IPublishedContentType"/>
 /// </summary>
 /// <param name="publishedContentType"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 public static bool TryGetKey(this IPublishedContentType publishedContentType, out Guid key)
 {
     if (publishedContentType is IPublishedContentType2 contentTypeWithKey)
     {
         key = contentTypeWithKey.Key;
         return(true);
     }
     key = Guid.Empty;
     return(false);
 }
        public void CacheLevelTest(PropertyCacheLevel cacheLevel, int interConverts)
        {
            var converter = new CacheConverter1(cacheLevel);

            var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[]
            {
                converter,
            });

            var configurationEditorJsonSerializer = new ConfigurationEditorJsonSerializer();
            var dataTypeServiceMock = new Mock <IDataTypeService>();
            var dataType            = new DataType(
                new VoidEditor(
                    Mock.Of <IDataValueEditorFactory>()), configurationEditorJsonSerializer)
            {
                Id = 1
            };

            dataTypeServiceMock.Setup(x => x.GetAll()).Returns(dataType.Yield);

            var publishedContentTypeFactory = new PublishedContentTypeFactory(Mock.Of <IPublishedModelFactory>(), converters, dataTypeServiceMock.Object);

            IEnumerable <IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
            {
                yield return(publishedContentTypeFactory.CreatePropertyType(contentType, "prop1", dataType.Id));
            }

            IPublishedContentType setType1 = publishedContentTypeFactory.CreateContentType(Guid.NewGuid(), 1000, "set1", CreatePropertyTypes);

            // PublishedElementPropertyBase.GetCacheLevels:
            //
            //   if property level is > reference level, or both are None
            //     use None for property & new reference
            //   else
            //     use Content for property, & keep reference
            //
            // PublishedElement creates properties with reference being None
            // if converter specifies None, keep using None
            // anything else is not > None, use Content
            //
            // for standalone elements, it's only None or Content
            var set1 = new PublishedElement(setType1, Guid.NewGuid(), new Dictionary <string, object> {
                { "prop1", "1234" }
            }, false);

            Assert.AreEqual(1234, set1.Value(Mock.Of <IPublishedValueFallback>(), "prop1"));
            Assert.AreEqual(1, converter.SourceConverts);
            Assert.AreEqual(1, converter.InterConverts);

            // source is always converted once and cached per content
            // inter conversion depends on the specified cache level
            Assert.AreEqual(1234, set1.Value(Mock.Of <IPublishedValueFallback>(), "prop1"));
            Assert.AreEqual(1, converter.SourceConverts);
            Assert.AreEqual(interConverts, converter.InterConverts);
        }
Beispiel #14
0
 public ContentNode(int id, Guid uid, IPublishedContentType contentType,
                    int level, string path, int sortOrder,
                    int parentContentId,
                    DateTime createDate, int creatorId,
                    ContentData draftData, ContentData publishedData,
                    IPublishedSnapshotAccessor publishedSnapshotAccessor,
                    IVariationContextAccessor variationContextAccessor)
     : this(id, uid, level, path, sortOrder, parentContentId, createDate, creatorId)
 {
     SetContentTypeAndData(contentType, draftData, publishedData, publishedSnapshotAccessor, variationContextAccessor);
 }
Beispiel #15
0
 public InternalPublishedContent(IPublishedContentType contentType)
 {
     // initialize boring stuff
     TemplateId  = 0;
     WriterId    = CreatorId = 0;
     CreateDate  = UpdateDate = DateTime.Now;
     Version     = Guid.Empty;
     Path        = string.Empty;
     ContentType = contentType;
     Properties  = Enumerable.Empty <IPublishedProperty>();
 }
Beispiel #16
0
        public void SimpleConverter2Test()
        {
            var cacheMock    = new Mock <IPublishedContentCache>();
            var cacheContent = new Dictionary <int, IPublishedContent>();

            cacheMock.Setup(x => x.GetById(It.IsAny <int>())).Returns <int>(id => cacheContent.TryGetValue(id, out IPublishedContent content) ? content : null);
            var publishedSnapshotMock = new Mock <IPublishedSnapshot>();

            publishedSnapshotMock.Setup(x => x.Content).Returns(cacheMock.Object);
            var publishedSnapshotAccessorMock = new Mock <IPublishedSnapshotAccessor>();
            var localPublishedSnapshot        = publishedSnapshotMock.Object;

            publishedSnapshotAccessorMock.Setup(x => x.TryGetPublishedSnapshot(out localPublishedSnapshot)).Returns(true);
            IPublishedSnapshotAccessor publishedSnapshotAccessor = publishedSnapshotAccessorMock.Object;

            var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[]
            {
                new SimpleConverter2(publishedSnapshotAccessor),
            });

            var serializer          = new ConfigurationEditorJsonSerializer();
            var dataTypeServiceMock = new Mock <IDataTypeService>();
            var dataType            = new DataType(
                new VoidEditor(
                    Mock.Of <IDataValueEditorFactory>()), serializer)
            {
                Id = 1
            };

            dataTypeServiceMock.Setup(x => x.GetAll()).Returns(dataType.Yield);

            var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of <IPublishedModelFactory>(), converters, dataTypeServiceMock.Object);

            IEnumerable <IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
            {
                yield return(contentTypeFactory.CreatePropertyType(contentType, "prop1", 1));
            }

            IPublishedContentType elementType1 = contentTypeFactory.CreateContentType(Guid.NewGuid(), 1000, "element1", CreatePropertyTypes);

            var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> {
                { "prop1", "1234" }
            }, false);

            IPublishedContentType cntType1 = contentTypeFactory.CreateContentType(Guid.NewGuid(), 1001, "cnt1", t => Enumerable.Empty <PublishedPropertyType>());
            var cnt1 = new InternalPublishedContent(cntType1)
            {
                Id = 1234
            };

            cacheContent[cnt1.Id] = cnt1;

            Assert.AreSame(cnt1, element1.Value(Mock.Of <IPublishedValueFallback>(), "prop1"));
        }
 public DetachedPublishedElement(
     Guid key,
     IPublishedContentType contentType,
     IEnumerable <IPublishedProperty> properties,
     bool isPreviewing = false)
 {
     _key          = key;
     _contentType  = contentType;
     _properties   = properties;
     _isPreviewing = isPreviewing;
 }
Beispiel #18
0
        private static void AddIf(IPublishedContentType contentType, IDictionary <string, PropertyData[]> properties, string alias, object value)
        {
            var propertyType = contentType.GetPropertyType(alias);

            if (propertyType == null || propertyType.IsUserProperty)
            {
                return;
            }
            properties[alias] = new[] { new PropertyData {
                                            Value = value, Culture = string.Empty, Segment = string.Empty
                                        } };
        }
Beispiel #19
0
 private NavigableContentType EnsureInitialized(IPublishedContentType contentType)
 {
     lock (_locko)
     {
         if (Name == null)
         {
             Name       = contentType.Alias;
             FieldTypes = BuiltinProperties
                          .Union(contentType.PropertyTypes.Select(propertyType => new NavigablePropertyType(propertyType.Alias)))
                          .ToArray();
         }
     }
     return(this);
 }
        /// <summary>
        ///     Get published property type of the wrapped data type.
        /// </summary>
        /// <param name="dataTypeKey"></param>
        /// <param name="contentType"></param>
        /// <returns></returns>
        private IPublishedPropertyType GetPublishedPropertyType(Guid dataTypeKey, IPublishedContentType contentType)
        {
            var dataType = _dataTypeService.GetDataType(dataTypeKey);

            if ((dataType == null) || (contentType == null))
            {
                return(null);
            }

            var propertyType = new PropertyType(dataType);

            var publishedPropertyType = Current.PublishedContentTypeFactory.CreatePropertyType(contentType, propertyType);

            return(publishedPropertyType);
        }
Beispiel #21
0
        // two-phase ctor, phase 2
        public void SetContentTypeAndData(IPublishedContentType contentType, ContentData draftData, ContentData publishedData, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor)
        {
            ContentType = contentType;

            if (draftData == null && publishedData == null)
            {
                throw new ArgumentException("Both draftData and publishedData cannot be null at the same time.");
            }

            _publishedSnapshotAccessor = publishedSnapshotAccessor;
            _variationContextAccessor  = variationContextAccessor;

            _draftData     = draftData;
            _publishedData = publishedData;
        }
Beispiel #22
0
 // special ctor with no content data - for members
 public ContentNode(int id, Guid uid, IPublishedContentType contentType,
                    int level, string path, int sortOrder,
                    int parentContentId,
                    DateTime createDate, int creatorId)
     : this()
 {
     Id              = id;
     Uid             = uid;
     ContentType     = contentType;
     Level           = level;
     Path            = path;
     SortOrder       = sortOrder;
     ParentContentId = parentContentId;
     CreateDate      = createDate;
     CreatorId       = creatorId;
 }
Beispiel #23
0
        public void SimpleConverter1Test()
        {
            var converters = new PropertyValueConverterCollection(() => new IPropertyValueConverter[]
            {
                new SimpleConverter1(),
            });

            var serializer          = new ConfigurationEditorJsonSerializer();
            var dataTypeServiceMock = new Mock <IDataTypeService>();
            var dataType            = new DataType(
                new VoidEditor(
                    Mock.Of <IDataValueEditorFactory>()), serializer)
            {
                Id = 1
            };

            dataTypeServiceMock.Setup(x => x.GetAll()).Returns(dataType.Yield);

            var contentTypeFactory = new PublishedContentTypeFactory(Mock.Of <IPublishedModelFactory>(), converters, dataTypeServiceMock.Object);

            IEnumerable <IPublishedPropertyType> CreatePropertyTypes(IPublishedContentType contentType)
            {
                yield return(contentTypeFactory.CreatePropertyType(contentType, "prop1", 1));
            }

            IPublishedContentType elementType1 = contentTypeFactory.CreateContentType(Guid.NewGuid(), 1000, "element1", CreatePropertyTypes);

            var element1 = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> {
                { "prop1", "1234" }
            }, false);

            Assert.AreEqual(1234, element1.Value(Mock.Of <IPublishedValueFallback>(), "prop1"));

            // 'null' would be considered a 'missing' value by the default, magic logic
            var e = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> {
                { "prop1", null }
            }, false);

            Assert.IsFalse(e.HasValue("prop1"));

            // '0' would not - it's a valid integer - but the converter knows better
            e = new PublishedElement(elementType1, Guid.NewGuid(), new Dictionary <string, object> {
                { "prop1", "0" }
            }, false);
            Assert.IsFalse(e.HasValue("prop1"));
        }
Beispiel #24
0
        public void Build(
            IPublishedContentType contentType,
            IPublishedSnapshotAccessor publishedSnapshotAccessor,
            IVariationContextAccessor variationContextAccessor,
            bool canBePublished)
        {
            var draftData = DraftData;

            // no published data if it cannot be published (eg is masked)
            var publishedData = canBePublished ? PublishedData : null;

            // we *must* have either published or draft data
            // if it cannot be published, published data is going to be null
            // therefore, ensure that draft data is not
            if (draftData == null && !canBePublished)
            {
                draftData = PublishedData;
            }

            Node.SetContentTypeAndData(contentType, draftData, publishedData, publishedSnapshotAccessor, variationContextAccessor);
        }
Beispiel #25
0
        // clone
        public ContentNode(ContentNode origin, IPublishedContentType contentType = null)
        {
            Id                       = origin.Id;
            Uid                      = origin.Uid;
            ContentType              = contentType ?? origin.ContentType;
            Level                    = origin.Level;
            Path                     = origin.Path;
            SortOrder                = origin.SortOrder;
            ParentContentId          = origin.ParentContentId;
            FirstChildContentId      = origin.FirstChildContentId;
            LastChildContentId       = origin.LastChildContentId;
            NextSiblingContentId     = origin.NextSiblingContentId;
            PreviousSiblingContentId = origin.PreviousSiblingContentId;
            CreateDate               = origin.CreateDate;
            CreatorId                = origin.CreatorId;

            _draftData                 = origin._draftData;
            _publishedData             = origin._publishedData;
            _publishedSnapshotAccessor = origin._publishedSnapshotAccessor;
            _variationContextAccessor  = origin._variationContextAccessor;
        }
Beispiel #26
0
        private static Dictionary <string, PropertyData[]> GetPropertyValues(IPublishedContentType contentType, IMember member)
        {
            // see node in PublishedSnapshotService
            // we do not (want to) support ConvertDbToXml/String

            //var propertyEditorResolver = PropertyEditorResolver.Current;

            // see note in MemberType.Variations
            // we don't want to support variations on members

            var properties = member
                             .Properties
                             //.Select(property =>
                             //{
                             //    var e = propertyEditorResolver.GetByAlias(property.PropertyType.PropertyEditorAlias);
                             //    var v = e == null
                             //        ? property.Value
                             //        : e.ValueEditor.ConvertDbToString(property, property.PropertyType, ApplicationContext.Current.Services.DataTypeService);
                             //    return new KeyValuePair<string, object>(property.Alias, v);
                             //})
                             //.ToDictionary(x => x.Key, x => x.Value);
                             .ToDictionary(x => x.Alias, x => new[] { new PropertyData {
                                                                          Value = x.GetValue(), Culture = string.Empty, Segment = string.Empty
                                                                      } }, StringComparer.OrdinalIgnoreCase);

            // see also PublishedContentType
            AddIf(contentType, properties, "Email", member.Email);
            AddIf(contentType, properties, "Username", member.Username);
            AddIf(contentType, properties, "PasswordQuestion", member.PasswordQuestion);
            AddIf(contentType, properties, "Comments", member.Comments);
            AddIf(contentType, properties, "IsApproved", member.IsApproved);
            AddIf(contentType, properties, "IsLockedOut", member.IsLockedOut);
            AddIf(contentType, properties, "LastLockoutDate", member.LastLockoutDate);
            AddIf(contentType, properties, "CreateDate", member.CreateDate);
            AddIf(contentType, properties, "LastLoginDate", member.LastLoginDate);
            AddIf(contentType, properties, "LastPasswordChangeDate", member.LastPasswordChangeDate);

            return(properties);
        }
Beispiel #27
0
        public static IPublishedContent?Create(
            IMember member,
            IPublishedContentType contentType,
            bool previewing,
            IPublishedSnapshotAccessor publishedSnapshotAccessor,
            IVariationContextAccessor variationContextAccessor,
            IPublishedModelFactory publishedModelFactory)
        {
            var d = new ContentData(member.Name, null, 0, member.UpdateDate, member.CreatorId, -1, previewing, GetPropertyValues(contentType, member), null);

            var n = new ContentNode(
                member.Id,
                member.Key,
                contentType,
                member.Level,
                member.Path,
                member.SortOrder,
                member.ParentId,
                member.CreateDate,
                member.CreatorId);

            return(new PublishedMember(member, n, d, publishedSnapshotAccessor, variationContextAccessor, publishedModelFactory)
                   .CreateModel(publishedModelFactory));
        }
        // internal for some benchmarks
        internal static void InitializeNode(XmlPublishedContent node, XmlNode xmlNode, bool isPreviewing,
                                            out int id, out Guid key, out int template, out int sortOrder, out string name, out string writerName, out string urlName,
                                            out string creatorName, out int creatorId, out int writerId, out string docTypeAlias, out int docTypeId, out string path,
                                            out DateTime createDate, out DateTime updateDate, out int level, out bool isDraft,
                                            out IPublishedContentType contentType, out Dictionary <string, IPublishedProperty> properties,
                                            Func <PublishedItemType, string, IPublishedContentType> getPublishedContentType)
        {
            //initialize the out params with defaults:
            writerName   = null;
            docTypeAlias = null;
            id           = template = sortOrder = template = creatorId = writerId = docTypeId = level = default(int);
            key          = default(Guid);
            name         = writerName = urlName = creatorName = docTypeAlias = path = null;
            createDate   = updateDate = default(DateTime);
            isDraft      = false;
            contentType  = null;
            properties   = null;

            if (xmlNode == null)
            {
                return;
            }

            if (xmlNode.Attributes != null)
            {
                id = int.Parse(xmlNode.Attributes.GetNamedItem("id").Value);
                if (xmlNode.Attributes.GetNamedItem("key") != null) // because, migration
                {
                    key = Guid.Parse(xmlNode.Attributes.GetNamedItem("key").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("template") != null)
                {
                    template = int.Parse(xmlNode.Attributes.GetNamedItem("template").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("sortOrder") != null)
                {
                    sortOrder = int.Parse(xmlNode.Attributes.GetNamedItem("sortOrder").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("nodeName") != null)
                {
                    name = xmlNode.Attributes.GetNamedItem("nodeName").Value;
                }
                if (xmlNode.Attributes.GetNamedItem("writerName") != null)
                {
                    writerName = xmlNode.Attributes.GetNamedItem("writerName").Value;
                }
                if (xmlNode.Attributes.GetNamedItem("urlName") != null)
                {
                    urlName = xmlNode.Attributes.GetNamedItem("urlName").Value;
                }
                if (xmlNode.Attributes.GetNamedItem("creatorName") != null)
                {
                    creatorName = xmlNode.Attributes.GetNamedItem("creatorName").Value;
                }

                //Added the actual userID, as a user cannot be looked up via full name only...
                if (xmlNode.Attributes.GetNamedItem("creatorID") != null)
                {
                    creatorId = int.Parse(xmlNode.Attributes.GetNamedItem("creatorID").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("writerID") != null)
                {
                    writerId = int.Parse(xmlNode.Attributes.GetNamedItem("writerID").Value);
                }

                docTypeAlias = xmlNode.Name;

                if (xmlNode.Attributes.GetNamedItem("nodeType") != null)
                {
                    docTypeId = int.Parse(xmlNode.Attributes.GetNamedItem("nodeType").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("path") != null)
                {
                    path = xmlNode.Attributes.GetNamedItem("path").Value;
                }
                if (xmlNode.Attributes.GetNamedItem("createDate") != null)
                {
                    createDate = DateTime.Parse(xmlNode.Attributes.GetNamedItem("createDate").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("updateDate") != null)
                {
                    updateDate = DateTime.Parse(xmlNode.Attributes.GetNamedItem("updateDate").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("level") != null)
                {
                    level = int.Parse(xmlNode.Attributes.GetNamedItem("level").Value);
                }

                isDraft = xmlNode.Attributes.GetNamedItem("isDraft") != null;
            }

            //dictionary to store the property node data
            var propertyNodes = new Dictionary <string, XmlNode>();

            foreach (XmlNode n in xmlNode.ChildNodes)
            {
                var e = n as XmlElement;
                if (e == null)
                {
                    continue;
                }
                if (e.HasAttribute("isDoc") == false)
                {
                    PopulatePropertyNodes(propertyNodes, e, false);
                }
                else
                {
                    break;  //we are not longer on property elements
                }
            }

            //lookup the content type and create the properties collection
            try
            {
                contentType = getPublishedContentType(PublishedItemType.Content, docTypeAlias);
            }
            catch (InvalidOperationException e)
            {
                // TODO: enable!
                //content.Instance.RefreshContentFromDatabase();
                throw new InvalidOperationException($"{e.Message}. This usually indicates that the content cache is corrupt; the content cache has been rebuilt in an attempt to self-fix the issue.");
            }

            //fill in the property collection
            properties = new Dictionary <string, IPublishedProperty>(StringComparer.OrdinalIgnoreCase);
            foreach (var propertyType in contentType.PropertyTypes)
            {
                var val = propertyNodes.TryGetValue(propertyType.Alias.ToLowerInvariant(), out XmlNode n)
                    ? new XmlPublishedProperty(propertyType, node, isPreviewing, n)
                    : new XmlPublishedProperty(propertyType, node, isPreviewing);

                properties[propertyType.Alias] = val;
            }
        }
 public ImageWithLegendModel(IPublishedContentType contentType, Guid fragmentKey, Dictionary <string, object> values, bool previewing)
     : base(contentType, fragmentKey, values, previewing)
 {
 }
Beispiel #30
0
 public override IEnumerable <IPublishedContent> GetByContentType(IPublishedContentType contentType) => throw new NotImplementedException();