Esempio n. 1
0
            // note: I'm not sure this class fully complies with IPublishedContent rules especially
            // I'm not sure that _properties contains all properties including those without a value,
            // neither that GetProperty will return a property without a value vs. null... @zpqrtbnk

            public DictionaryPublishedContent(
                IDictionary <string, string> valueDictionary,
                Func <DictionaryPublishedContent, IPublishedContent> getParent,
                Func <DictionaryPublishedContent, IEnumerable <IPublishedContent> > getChildren,
                Func <DictionaryPublishedContent, string, IPublishedProperty> getProperty,
                bool fromExamine)
            {
                if (valueDictionary == null)
                {
                    throw new ArgumentNullException("valueDictionary");
                }
                if (getParent == null)
                {
                    throw new ArgumentNullException("getParent");
                }
                if (getProperty == null)
                {
                    throw new ArgumentNullException("getProperty");
                }

                _getParent   = getParent;
                _getChildren = getChildren;
                _getProperty = getProperty;

                LoadedFromExamine = fromExamine;

                ValidateAndSetProperty(valueDictionary, val => _id                = int.Parse(val), "id", "nodeId", "__NodeId");  //should validate the int!
                ValidateAndSetProperty(valueDictionary, val => _templateId        = int.Parse(val), "template", "templateId");
                ValidateAndSetProperty(valueDictionary, val => _sortOrder         = int.Parse(val), "sortOrder");
                ValidateAndSetProperty(valueDictionary, val => _name              = val, "nodeName", "__nodeName");
                ValidateAndSetProperty(valueDictionary, val => _urlName           = val, "urlName");
                ValidateAndSetProperty(valueDictionary, val => _documentTypeAlias = val, "nodeTypeAlias", UmbracoContentIndexer.NodeTypeAliasFieldName);
                ValidateAndSetProperty(valueDictionary, val => _documentTypeId    = int.Parse(val), "nodeType");
                ValidateAndSetProperty(valueDictionary, val => _writerName        = val, "writerName");
                ValidateAndSetProperty(valueDictionary, val => _creatorName       = val, "creatorName", "writerName");           //this is a bit of a hack fix for: U4-1132
                ValidateAndSetProperty(valueDictionary, val => _writerId          = int.Parse(val), "writerID");
                ValidateAndSetProperty(valueDictionary, val => _creatorId         = int.Parse(val), "creatorID", "writerID");    //this is a bit of a hack fix for: U4-1132
                ValidateAndSetProperty(valueDictionary, val => _path              = val, "path", "__Path");
                ValidateAndSetProperty(valueDictionary, val => _createDate        = ParseDateTimeValue(val), "createDate");
                ValidateAndSetProperty(valueDictionary, val => _updateDate        = ParseDateTimeValue(val), "updateDate");
                ValidateAndSetProperty(valueDictionary, val => _level             = int.Parse(val), "level");
                ValidateAndSetProperty(valueDictionary, val =>
                {
                    int pId;
                    ParentId = -1;
                    if (int.TryParse(val, out pId))
                    {
                        ParentId = pId;
                    }
                }, "parentID");

                _contentType = PublishedContentType.Get(PublishedItemType.Media, _documentTypeAlias);
                _properties  = new Collection <IPublishedProperty>();

                //loop through remaining values that haven't been applied
                foreach (var i in valueDictionary.Where(x => !_keysAdded.Contains(x.Key)))
                {
                    IPublishedProperty property;

                    // must ignore that one
                    if (i.Key == "version")
                    {
                        continue;
                    }

                    if (i.Key.InvariantStartsWith("__"))
                    {
                        // no type for tha tone, dunno how to convert
                        property = new PropertyResult(i.Key, i.Value, Guid.Empty, PropertyResultType.CustomProperty);
                    }
                    else
                    {
                        // use property type to ensure proper conversion
                        var propertyType = _contentType.GetPropertyType(i.Key);
                        property = new XmlPublishedProperty(propertyType, false, i.Value); // false :: never preview a media
                    }

                    _properties.Add(property);
                }
            }
            // note: I'm not sure this class fully complies with IPublishedContent rules especially
            // I'm not sure that _properties contains all properties including those without a value,
            // neither that GetProperty will return a property without a value vs. null... @zpqrtbnk

			public DictionaryPublishedContent(
				IDictionary<string, string> valueDictionary, 
				Func<DictionaryPublishedContent, IPublishedContent> getParent,
				Func<DictionaryPublishedContent, IEnumerable<IPublishedContent>> getChildren,
				Func<DictionaryPublishedContent, string, IPublishedProperty> getProperty,
				bool fromExamine)
			{
				if (valueDictionary == null) throw new ArgumentNullException("valueDictionary");
				if (getParent == null) throw new ArgumentNullException("getParent");
				if (getProperty == null) throw new ArgumentNullException("getProperty");

				_getParent = getParent;
				_getChildren = getChildren;
				_getProperty = getProperty;

				LoadedFromExamine = fromExamine;

				ValidateAndSetProperty(valueDictionary, val => _id = int.Parse(val), "id", "nodeId", "__NodeId"); //should validate the int!
				ValidateAndSetProperty(valueDictionary, val => _templateId = int.Parse(val), "template", "templateId");
				ValidateAndSetProperty(valueDictionary, val => _sortOrder = int.Parse(val), "sortOrder");
				ValidateAndSetProperty(valueDictionary, val => _name = val, "nodeName", "__nodeName");
				ValidateAndSetProperty(valueDictionary, val => _urlName = val, "urlName");
				ValidateAndSetProperty(valueDictionary, val => _documentTypeAlias = val, "nodeTypeAlias", UmbracoContentIndexer.NodeTypeAliasFieldName);
				ValidateAndSetProperty(valueDictionary, val => _documentTypeId = int.Parse(val), "nodeType");
				ValidateAndSetProperty(valueDictionary, val => _writerName = val, "writerName");
				ValidateAndSetProperty(valueDictionary, val => _creatorName = val, "creatorName", "writerName"); //this is a bit of a hack fix for: U4-1132
				ValidateAndSetProperty(valueDictionary, val => _writerId = int.Parse(val), "writerID");
				ValidateAndSetProperty(valueDictionary, val => _creatorId = int.Parse(val), "creatorID", "writerID"); //this is a bit of a hack fix for: U4-1132
				ValidateAndSetProperty(valueDictionary, val => _path = val, "path", "__Path");
				ValidateAndSetProperty(valueDictionary, val => _createDate = ParseDateTimeValue(val), "createDate");
				ValidateAndSetProperty(valueDictionary, val => _updateDate = ParseDateTimeValue(val), "updateDate");
				ValidateAndSetProperty(valueDictionary, val => _level = int.Parse(val), "level");
				ValidateAndSetProperty(valueDictionary, val =>
					{
						int pId;
						ParentId = -1;
						if (int.TryParse(val, out pId))
						{
							ParentId = pId;
						}						
					}, "parentID");

			    _contentType = PublishedContentType.Get(PublishedItemType.Media, _documentTypeAlias);
				_properties = new Collection<IPublishedProperty>();

				//loop through remaining values that haven't been applied
				foreach (var i in valueDictionary.Where(x => !_keysAdded.Contains(x.Key)))
				{
				    IPublishedProperty property;

                    // must ignore that one
				    if (i.Key == "version") continue;

                    if (i.Key.InvariantStartsWith("__"))
				    {
                        // no type for tha tone, dunno how to convert
				        property = new PropertyResult(i.Key, i.Value, Guid.Empty, PropertyResultType.CustomProperty);
				    }
                    else
                    {
                        // use property type to ensure proper conversion
                        var propertyType = _contentType.GetPropertyType(i.Key);
                        property = new XmlPublishedProperty(propertyType, false, i.Value); // false :: never preview a media
                    }

					_properties.Add(property);
				}
			}