/// <summary>
        /// Inits the specified current node id.
        /// </summary>
        /// <param name="CurrentNodeId">The current node id.</param>
        /// <param name="PropertyData">The property data.</param>
        /// <param name="instance">The instance.</param>
        /// <returns></returns>
        public bool Init(int CurrentNodeId, string PropertyData, out object instance)
        {
            if (!Settings.RazorModelBindingEnabled)
            {
            #pragma warning disable 0618
                instance = new DynamicXml(PropertyData);
            #pragma warning restore 0618
                return true;
            }

            var values = new List<string>();

            if (!string.IsNullOrEmpty(PropertyData))
            {
                var xml = new XmlDocument();
                xml.LoadXml(PropertyData);

                foreach (XmlNode node in xml.SelectNodes("/values/value"))
                {
                    values.Add(node.InnerText);
                }
            }

            instance = values;

            return true;
        }
        /// <summary>
        /// Inits the specified current node id.
        /// </summary>
        /// <param name="CurrentNodeId">The current node id.</param>
        /// <param name="PropertyData">The property data.</param>
        /// <param name="instance">The instance.</param>
        /// <returns></returns>
        public bool Init(int CurrentNodeId, string PropertyData, out object instance)
        {
            if (!Settings.RazorModelBindingEnabled)
            {
                if (Helper.Xml.CouldItBeXml(PropertyData))
                {
            #pragma warning disable 0618
                    instance = new DynamicXml(PropertyData);
            #pragma warning restore 0618
                    return true;
                }

                instance = PropertyData;
                return true;
            }

            UrlPickerState state = null;

            if (!string.IsNullOrEmpty(PropertyData))
            {
                state = UrlPickerState.Deserialize(PropertyData);
            }

            instance = state;

            return true;
        }
        private bool HandleIEnumerableXElement(IEnumerable <XElement> elements, out object result)
        {
            //Get the count now, so we don't have to call it twice
            int count = elements.Count();

            if (count > 0)
            {
                var firstElement = elements.FirstOrDefault();
                //we have a single element, does it have any children?
                if (firstElement != null && firstElement.Elements().Count() == 0 && !firstElement.HasAttributes)
                {
                    //no, return the text
                    result = firstElement.Value;
                    return(true);
                }
                else
                {
                    //We have more than one matching element, so let's return the collection
                    //elements is IEnumerable<DynamicXml>
                    //but we want to be able to re-enter this code
                    XElement root = new XElement(XName.Get("root"));
                    root.Add(elements);
                    result = new DynamicXml(root);

                    //From here, you'll either end up back here (because you have <root><node><node>)
                    //or you use [] indexing and you end up with a single element
                    return(true);
                }
            }
            result = null;
            return(false);
        }
Exemple #4
0
        public DynamicXml XPath(string expression)
        {
			var matched = _inner.BaseElement.XPathSelectElements(expression);
            var root = new DynamicXml("<results/>");
            foreach (var element in matched)
            {
                root.BaseElement.Add(element);
            }
            return root;
        }
Exemple #5
0
 public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
 {
     int index = 0;
     if (indexes.Length > 0)
     {
         index = (int)indexes[0];
         result = new DynamicXml(this.BaseElement.Elements().ToList()[index]);
         return true;
     }
     return base.TryGetIndex(binder, indexes, out result);
 }
Exemple #6
0
        public DynamicXml XPath(string expression)
        {
            var matched = _inner.BaseElement.XPathSelectElements(expression);
            var root    = new DynamicXml("<results/>");

            foreach (var element in matched)
            {
                root.BaseElement.Add(element);
            }
            return(root);
        }
Exemple #7
0
        public override bool TryGetIndex(GetIndexBinder binder, object[] indexes, out object result)
        {
            int index = 0;

            if (indexes.Length > 0)
            {
                index  = (int)indexes[0];
                result = new DynamicXml(this.BaseElement.Elements().ToList()[index]);
                return(true);
            }
            return(base.TryGetIndex(binder, indexes, out result));
        }
        /// <summary>
        /// Initializes the specified current node unique identifier.
        /// </summary>
        /// <param name="CurrentNodeId">The current node unique identifier.</param>
        /// <param name="PropertyData">The property data.</param>
        /// <param name="instance">The instance.</param>
        /// <returns></returns>
        public bool Init(int CurrentNodeId, string PropertyData, out object instance)
        {
            // if model binding is disbaled, return a DynamicXml object
            if (!Settings.RazorModelBindingEnabled)
            {
            #pragma warning disable 0618
                instance = new DynamicXml(PropertyData);
            #pragma warning restore 0618
                return true;
            }

            DataTypes.ImagePoint.ImagePoint imagePoint = new DataTypes.ImagePoint.ImagePoint();

            // use the uQuery IGetProperty interface to do the work
            ((uQuery.IGetProperty)imagePoint).LoadPropertyValue(PropertyData);

            instance = imagePoint;
            return true;
        }
        /// <summary>
        /// Inits the specified current node id.
        /// </summary>
        /// <param name="CurrentNodeId">The current node id.</param>
        /// <param name="PropertyData">The property data.</param>
        /// <param name="instance">The instance.</param>
        /// <returns></returns>
        public bool Init(int CurrentNodeId, string PropertyData, out object instance)
        {
            if (!Settings.RazorModelBindingEnabled)
            {
                if (Helper.Xml.CouldItBeXml(PropertyData))
                {
            #pragma warning disable 0618
                    instance = new DynamicXml(PropertyData);
            #pragma warning restore 0618
                    return true;
                }

                instance = PropertyData;
                return true;
            }

            var nodeIds = Helper.Xml.CouldItBeXml(PropertyData) ? umbraco.uQuery.GetXmlIds(PropertyData) : umbraco.uQuery.ConvertToIntArray(umbraco.uQuery.GetCsvIds(PropertyData));
            var library = new RazorLibraryCore(null);

            instance = (library.NodesById(nodeIds.ToList()) as DynamicNodeList);

            return true;
        }
Exemple #10
0
        public HtmlString IsDescendantOrSelf(DynamicXml other, string valueIfTrue)
        {
			return _inner.IsDescendantOrSelf(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement), valueIfTrue);   
        }
        public HtmlString IsAncestorOrSelf(DynamicXml other, string valueIfTrue, string valueIfFalse)
        {
            var descendants = this.DescendantsOrSelf();

            return(IsHelper(n => descendants.Find(descendant => descendant.BaseElement == other.BaseElement) != null, valueIfTrue, valueIfFalse));
        }
        public bool IsAncestorOrSelf(DynamicXml other)
        {
            var descendants = this.DescendantsOrSelf();

            return(IsHelper(n => descendants.Find(descendant => descendant.BaseElement == other.BaseElement) != null));
        }
        private static string ImageUrlFromMediaItem(RazorLibraryCore ctx, int mediaId, string cropProperty, string cropName)
        {
            string url = null;
            DynamicMedia media = ctx.MediaById(mediaId);
            if (media != null)
            {
                if (media.HasProperty(cropProperty))
                {
                    dynamic d = new DynamicXml(media.GetPropertyValue(cropProperty)).Find("@name", cropName);
                    url = (string)d.url;
                }

                if (string.IsNullOrWhiteSpace(url) && media.HasValue("umbracoFile"))
                {
                    url = media.GetPropertyValue("umbracoFile");
                }
            }
            return url ?? "";
        }
Exemple #14
0
        public bool IsDescendantOrSelf(DynamicXml other)
        {
			return _inner.IsDescendantOrSelf(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement));       
        }
Exemple #15
0
 public bool IsAncestorOrSelf(DynamicXml other)
 {
     return(_inner.IsAncestorOrSelf(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement)));
 }
Exemple #16
0
 public bool IsDescendant(DynamicXml other)
 {
     return(_inner.IsDescendant(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement)));
 }
        void ExamineEventsInternal_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
        {
            //need to fudge rte field so that we have internal link nodeids in the internal index
            var rteFields = RteFields;

            if (e.IndexType == IndexTypes.Content)
            {
                var d = new Document(e.NodeId);
                foreach (var rteField in rteFields)
                {
                    if (d.getProperty(rteField) != null && d.getProperty(rteField).Value != null)
                    {
                        var rteEncoded = HttpUtility.HtmlEncode(d.getProperty(rteField).Value.ToString().Replace("localLink:", "localLink: ").Replace("}", " } "));
                        e.Fields.Add("rteLink" + rteField, rteEncoded);
                    }
                }

                var treePickerFields = TreePickerFields;
                foreach (var treePickerField in treePickerFields)
                {
                    if (e.Fields.ContainsKey(treePickerField))
                    {
                        var content = e.Fields[treePickerField];

                        // if it's a csv type and there's more than one item,
                        // separate with a space so the nodes are indexed separately
                        if (content.Contains(","))
                        {
                            content = content.Replace(",", " ");
                        }
                        else
                        {
                            // if it's an XML type tree picker, get the xml and transform into a space separated list
                            var node = new Node(e.NodeId);
                            var value = node.GetProperty(treePickerField).Value;

                            if (value.Contains("<MultiNodePicker"))
                            {
                                var dynamicXml = new DynamicXml(value);
                                content = string.Join(" ", dynamicXml.Descendants().Select(de => de.InnerText));
                            }
                        }
                        e.Fields[treePickerField] = content;
                    }
                }

                e.Fields.Add("IsPublished", d.Published.ToString());
            }
        }
Exemple #18
0
        public bool IsAncestorOrSelf(DynamicXml other)
        {
			return _inner.IsAncestorOrSelf(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement));   
        }
Exemple #19
0
        private bool HandleIEnumerableXElement(IEnumerable<XElement> elements, out object result)
        {
            //Get the count now, so we don't have to call it twice
            int count = elements.Count();
            if (count > 0)
            {
                if (count > 1)
                {
                    //result = elements;
                    //We have more than one matching element, so let's return the collection
                    //elements is IEnumerable<DynamicXml>
                    //but we want to be able to re-enter this code
                    XElement root = new XElement(XName.Get("root"));
                    root.Add(elements);
                    result = new DynamicXml(root);

                    //From here, you'll either end up back here (because you have <root><node><node>)
                    //or you use [] indexing and you end up with a single element
                    return true;
                }
                else
                {
                    var firstElement = elements.FirstOrDefault();
                    //we have a single element, does it have any children?
                    if (firstElement.Elements().Count() == 0)
                    {
                        //no, return the text
                        result = firstElement.Value;
                        return true;
                    }
                    else
                    {
                        //yes return this element wrapped in DynamicXml
                        result = new DynamicXml(firstElement);
                        //There is only one matching element, so let's just return it
                        return true;
                    }
                }
                return true; //return true cuz we matched
            }
            result = null;
            return false;
        }
Exemple #20
0
        public HtmlString IsAncestorOrSelf(DynamicXml other, string valueIfTrue, string valueIfFalse)
        {
			return _inner.IsAncestorOrSelf(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement), valueIfTrue, valueIfFalse);   
        }
        private static string ImageUrlFromXml(RazorLibraryCore ctx, DynamicXml media, string cropProperty, string cropName)
        {
            string url = null;
            if (media != null)
            {
                var crop = new DynamicXml(media.DescendantsOrSelf(x => x.Name == cropProperty).FirstOrDefault().ToXml());
                try
                {
                    if (crop != null)
                    {
                        dynamic c = crop.Find("@name", cropName);
                        url = (string)c.url;
                    }
                }
                catch { }

                if (string.IsNullOrWhiteSpace(url))
                {
                    var f = media.Descendants(x => x.Name == "umbracoFile").FirstOrDefault();
                    if (f != null)
                        url = f.InnerText;
                }
            }
            return url ?? "";
        }
Exemple #22
0
 public bool IsNotEqual(DynamicXml other)
 {
     return(_inner.IsNotEqual(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement)));
 }
Exemple #23
0
        public HtmlString IsNotEqual(DynamicXml other, string valueIfTrue, string valueIfFalse)
        {
			return _inner.IsNotEqual(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement), valueIfTrue, valueIfFalse);
        }
Exemple #24
0
 public HtmlString IsNotEqual(DynamicXml other, string valueIfTrue)
 {
     return(_inner.IsNotEqual(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement), valueIfTrue));
 }
 public HtmlString IsNotEqual(DynamicXml other, string valueIfTrue, string valueIfFalse)
 {
     return(IsHelper(n => n.BaseElement != other.BaseElement, valueIfTrue, valueIfFalse));
 }
Exemple #26
0
 public HtmlString IsDescendantOrSelf(DynamicXml other, string valueIfTrue)
 {
     return(_inner.IsDescendantOrSelf(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement), valueIfTrue));
 }
        public bool IsDescendantOrSelf(DynamicXml other)
        {
            var ancestors = this.AncestorsOrSelf();

            return(IsHelper(n => ancestors.Find(ancestor => ancestor.BaseElement == other.BaseElement) != null));
        }
Exemple #28
0
 public HtmlString IsAncestorOrSelf(DynamicXml other, string valueIfTrue, string valueIfFalse)
 {
     return(_inner.IsAncestorOrSelf(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement), valueIfTrue, valueIfFalse));
 }
        public HtmlString IsDescendantOrSelf(DynamicXml other, string valueIfTrue, string valueIfFalse)
        {
            var ancestors = this.AncestorsOrSelf();

            return(IsHelper(n => ancestors.Find(ancestor => ancestor.BaseElement == other.BaseElement) != null, valueIfTrue, valueIfFalse));
        }
        /// <summary>
        /// Inits the specified current node id.
        /// </summary>
        /// <param name="CurrentNodeId">The current node id.</param>
        /// <param name="PropertyData">The property data.</param>
        /// <param name="instance">The instance.</param>
        /// <returns></returns>
        public bool Init(int CurrentNodeId, string PropertyData, out object instance)
        {
            // check if the data is XML
            if (Helper.Xml.CouldItBeXml(PropertyData))
            {
                // if model binding is disbaled, return a DynamicXml object
                if (!Settings.RazorModelBindingEnabled)
                {
            #pragma warning disable 0618
                    instance = new DynamicXml(PropertyData);
            #pragma warning restore 0618
                    return true;
                }

                // TODO [LK->HR] Discuss with Hendy whether to return a collection of AutoCompleteItem(s)?
                // ... or a collection of Content-specific objects; e.g. List<Media>, List<Member>, List<INodeFactory>?

                // parse the XML
                var xdoc = XDocument.Parse(PropertyData);
                if (xdoc != null)
                {
                    // select the Item nodes
                    var nodes = xdoc.XPathSelectElements("//Item");
                    if (nodes != null && nodes.Count() > 0)
                    {
                        // iterate over the nodes; building collection of AutoCompleteItem(s)
                        var items = new List<AutoCompleteItem>();
                        foreach (var node in nodes)
                        {
                            // check if the node has any attributes
                            if (!node.HasAttributes)
                                continue;

                            var item = new AutoCompleteItem();

                            // loop through the attributes, setting the properties accordingly
                            foreach (var attribute in node.Attributes())
                            {
                                switch (attribute.Name.LocalName)
                                {
                                    case "Text":
                                        item.Text = attribute.Value;
                                        break;

                                    case "Value":
                                        item.Value = attribute.Value;
                                        break;

                                    default:
                                        break;
                                }
                            }

                            items.Add(item);
                        }

                        instance = items;
                        return true;
                    }
                }
            }

            // all else fails, return default value
            instance = PropertyData;
            return true;
        }
Exemple #31
0
        private bool ConvertPropertyValueByDataType(ref object result, string name, Guid dataType)
        {
            //the resulting property is a string, but to support some of the nice linq stuff in .Where
            //we should really check some more types

            //boolean
            if (dataType == DATATYPE_YESNO_GUID)
            {
                bool parseResult;
                if (string.Format("{0}", result) == "")
                {
                    result = "0";
                }
                if (Boolean.TryParse(result.ToString().Replace("1", "true").Replace("0", "false"), out parseResult))
                {
                    result = parseResult;
                }
                return(true);
            }

            //integer
            int iResult = 0;

            if (int.TryParse(string.Format("{0}", result), out iResult))
            {
                result = iResult;
                return(true);
            }

            //MNTP List<int>
            if (dataType == DATATYPE_UCOMPONENTS_MNTP_GUID)
            {
                string sResult = string.Format("{0}", result);
                //csv mode
                if (!sResult.Contains("<"))
                {
                    result = sResult.Split(',').Select(id => int.Parse(id)).ToList();
                    return(true);
                }
            }

            //decimal
            decimal dResult = 0;

            if (decimal.TryParse(string.Format("{0}", result).Replace(",", "."), out dResult))
            {
                result = dResult;
                return(true);
            }

            //date
            DateTime dtResult = DateTime.MinValue;

            if (DateTime.TryParse(string.Format("{0}", result), out dtResult))
            {
                result = dtResult;
                return(true);
            }

            // Rich text editor (return IHtmlString so devs doesn't need to decode html
            if (dataType == DATATYPE_TINYMCE_GUID)
            {
                result = new HtmlString(result.ToString());
            }


            if (string.Equals("true", string.Format("{0}", result), StringComparison.CurrentCultureIgnoreCase))
            {
                result = true;
                return(true);
            }
            if (string.Equals("false", string.Format("{0}", result), StringComparison.CurrentCultureIgnoreCase))
            {
                result = false;
                return(true);
            }

            if (result != null)
            {
                string sResult = string.Format("{0}", result).Trim();
                //a really rough check to see if this may be valid xml
                if (sResult.StartsWith("<") && sResult.EndsWith(">") && sResult.Contains("/"))
                {
                    try
                    {
                        XElement e = XElement.Parse(sResult, LoadOptions.None);
                        if (e != null)
                        {
                            //check that the document element is not one of the disallowed elements
                            //allows RTE to still return as html if it's valid xhtml
                            string documentElement = e.Name.LocalName;
                            if (!UmbracoSettings.NotDynamicXmlDocumentElements.Any(tag =>
                                                                                   string.Equals(tag, documentElement, StringComparison.CurrentCultureIgnoreCase)))
                            {
                                result = new DynamicXml(e);
                                return(true);
                            }
                            else
                            {
                                //we will just return this as a string
                                return(true);
                            }
                        }
                    }
                    catch (Exception)
                    {
                        //we will just return this as a string
                        return(true);
                    }
                }
            }

            return(true);
        }
 public bool IsNotEqual(DynamicXml other)
 {
     return(IsHelper(n => n.BaseElement != other.BaseElement));
 }
Exemple #33
0
        public bool IsNotEqual(DynamicXml other)
        {
			return _inner.IsNotEqual(new Umbraco.Core.Dynamics.DynamicXml(other.BaseElement));
        }