Beispiel #1
0
        internal ContentDetail ReadMultipleValue(XPathNavigator navigator, ContentItem item, ReadingJournal journal, string name)
        {
            var multiDetail = ContentDetail.Multi(name);

            foreach (XPathNavigator valueElement in EnumerateChildren(navigator))
            {
                switch (valueElement.GetAttribute("key", ""))
                {
                case ContentDetail.TypeKeys.BoolType:
                    multiDetail.BoolValue = (bool)Parse(valueElement.Value, typeof(bool));
                    break;

                case ContentDetail.TypeKeys.DateTimeType:
                    multiDetail.DateTimeValue = (DateTime)Parse(valueElement.Value, typeof(DateTime));
                    break;

                case ContentDetail.TypeKeys.DoubleType:
                    multiDetail.DoubleValue = (double)Parse(valueElement.Value, typeof(double));
                    break;

                case ContentDetail.TypeKeys.IntType:
                    multiDetail.IntValue = (int)Parse(valueElement.Value, typeof(int));
                    break;

                case ContentDetail.TypeKeys.LinkType:
                    SetLinkedItem(valueElement.Value, journal, (referencedItem) => multiDetail.LinkedItem = referencedItem, valueElement.GetAttribute("versionKey", ""));
                    break;

                case ContentDetail.TypeKeys.MultiType:
                    journal.Error(new InvalidOperationException("Nested multi types not supported"));
                    break;

                case ContentDetail.TypeKeys.ObjectType:
                    multiDetail.ObjectValue = Parse(valueElement.Value, typeof(object));
                    break;

                case ContentDetail.TypeKeys.EnumType:     /* TODO: May need special treatment here as well (see other TODO). */
                case ContentDetail.TypeKeys.StringType:
                    Dictionary <string, string> attributes = GetAttributes(navigator);
                    multiDetail.StringValue = PrepareStringDetail(item, name, valueElement.Value, attributes.ContainsKey("encoded") && Convert.ToBoolean(attributes["encoded"]));
                    break;

                default:
                    throw new Exception("Failed to read MultipleValue");
                }
            }
            return(multiDetail);
        }
Beispiel #2
0
        internal ContentDetail ReadMultipleValue(XPathNavigator navigator, ContentItem item, ReadingJournal journal, string name)
        {
            var multiDetail = ContentDetail.Multi(name);

            foreach (XPathNavigator valueElement in EnumerateChildren(navigator))
            {
                switch (valueElement.GetAttribute("key", ""))
                {
                case ContentDetail.TypeKeys.BoolType:
                    multiDetail.BoolValue = (bool)Parse(valueElement.Value, typeof(bool));
                    break;

                case ContentDetail.TypeKeys.DateTimeType:
                    multiDetail.DateTimeValue = (DateTime)Parse(valueElement.Value, typeof(DateTime));
                    break;

                case ContentDetail.TypeKeys.DoubleType:
                    multiDetail.DoubleValue = (double)Parse(valueElement.Value, typeof(double));
                    break;

                case ContentDetail.TypeKeys.IntType:
                    multiDetail.IntValue = (int)Parse(valueElement.Value, typeof(int));
                    break;

                case ContentDetail.TypeKeys.LinkType:
                    SetLinkedItem(valueElement.Value, journal, (referencedItem) => multiDetail.LinkedItem = referencedItem);
                    break;

                case ContentDetail.TypeKeys.MultiType:
                    journal.Error(new InvalidOperationException("Nested multi types not supported"));
                    break;

                case ContentDetail.TypeKeys.ObjectType:
                    multiDetail.ObjectValue = Parse(valueElement.Value, typeof(object));
                    break;

                case ContentDetail.TypeKeys.StringType:
                    multiDetail.StringValue = (string)PrepareStringDetail(item, name, valueElement.Value);
                    break;
                }
            }
            return(multiDetail);
        }
Beispiel #3
0
        /// <summary>Finds links in a html string using regular expressions.</summary>
        /// <param name="html">The html to search for links.</param>
        /// <returns>A list of link (a) href attributes in the supplied html string.</returns>
        public virtual IList <ContentDetail> FindLinks(string html)
        {
            List <ContentDetail> links   = new List <ContentDetail>();
            MatchCollection      matches = linkExpression.Matches(html);

            foreach (Match m in matches)
            {
                var g = m.Groups["link"];
                if (g.Success)
                {
                    links.Add(ContentDetail.Multi(LinkDetailName, true, g.Index, null, null, g.Value, null, null));
                }
            }
            if (links.Count == 0 && !html.Contains(Environment.NewLine) && (html.StartsWith("/") || Regex.IsMatch(html, "^\\w+://", RegexOptions.Compiled | RegexOptions.IgnoreCase)))
            {
                links.Add(ContentDetail.Multi(LinkDetailName, false, 0, null, null, html, null, null));
            }
            return(links);
        }
Beispiel #4
0
        public override IList <ContentDetail> FindLinks(string html)
        {
            //Looks like when a page is SAVED, this gets called - database records are deleted to track links
            //These records are scanned when a page is being deleted to detect conflicts
            //Obviously a more effecient way of doing things as opposed to scanning the whole site for dependencies at once!
            List <ContentDetail> links = base.FindLinks(html).ToList();

            if (links.Count == 0)
            {
                //No links found - might be dealing with a LinkItemCollection in which case we have a JSON string
                if (LinkItemCollection.TryParse(html, out LinkItemCollection linkCollection))
                {
                    links = links.Concat(linkCollection.OfType <LinkItem>().Select(x => ContentDetail.Multi(LinkDetailName, false, 0, null, null, x.Url))).ToList();
                }
            }

            return(links);
        }