Exemplo n.º 1
0
 /// <summary>
 /// Creates a custom header with a custom image
 /// </summary>
 /// <param name="cc">ClientContext of the site hosting the image</param>
 /// <param name="pageHeaderType">Type of page header</param>
 /// <param name="imageServerRelativeUrl">Server relative image url</param>
 public ClientSidePageHeader(ClientContext cc, ClientSidePageHeaderType pageHeaderType, string imageServerRelativeUrl)
 {
     this.imageServerRelativeUrl = imageServerRelativeUrl;
     this.clientContext          = cc;
     this.pageHeaderType         = pageHeaderType;
     this.TextAlignment          = ClientSidePageHeaderTitleAlignment.Center;
     this.LayoutType             = ClientSidePageHeaderLayoutType.FullWidthImage;
     this.ShowKicker             = false;
     this.Kicker          = "";
     this.Authors         = "";
     this.AlternativeText = "";
     this.ShowPublishDate = false;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a custom header with a custom image
        /// </summary>
        /// <param name="cc">ClientContext of the site hosting the image</param>
        /// <param name="pageHeaderType">Type of page header</param>
        /// <param name="imageServerRelativeUrl">Server relative image url</param>
        public ClientSidePageHeader(ClientContext cc, ClientSidePageHeaderType pageHeaderType, string imageServerRelativeUrl)
        {
            this.imageServerRelativeUrl = imageServerRelativeUrl;
            this.clientContext          = cc;
            this.pageHeaderType         = pageHeaderType;
            this.LayoutType             = ClientSidePageHeaderLayoutType.FullWidthImage;
#if !SP2019
            this.TextAlignment   = ClientSidePageHeaderTitleAlignment.Left;
            this.ShowTopicHeader = false;
            this.TopicHeader     = "";
            this.Authors         = "";
            this.AlternativeText = "";
            this.ShowPublishDate = false;
            this.AuthorByLineId  = -1;
#endif
        }
Exemplo n.º 3
0
        /// <summary>
        /// Load the PageHeader object from the given html
        /// </summary>
        /// <param name="pageHeaderHtml">Page header html</param>
        public void FromHtml(string pageHeaderHtml)
        {
            // select all control div's
            if (String.IsNullOrEmpty(pageHeaderHtml))
            {
                this.pageHeaderType = ClientSidePageHeaderType.Default;
                return;
            }

            HtmlParser parser = new HtmlParser(new HtmlParserOptions()
            {
                IsEmbedded = true
            });

            using (var document = parser.Parse(pageHeaderHtml))
            {
                var pageHeaderControl = document.All.Where(m => m.HasAttribute(CanvasControl.ControlDataAttribute)).FirstOrDefault();
                if (pageHeaderControl != null)
                {
                    var     decoded   = WebUtility.HtmlDecode(pageHeaderControl.GetAttribute(ClientSideWebPart.ControlDataAttribute));
                    JObject wpJObject = JObject.Parse(decoded);

                    // Store the server processed content as that's needed for full fidelity
                    if (wpJObject["serverProcessedContent"] != null)
                    {
                        if (wpJObject["serverProcessedContent"]["imageSources"] != null && wpJObject["serverProcessedContent"]["imageSources"]["imageSource"] != null)
                        {
                            this.imageServerRelativeUrl = wpJObject["serverProcessedContent"]["imageSources"]["imageSource"].ToString();
                        }

                        // Properties that apply to all header configurations
                        if (wpJObject["properties"]["layoutType"] != null)
                        {
                            this.LayoutType = (ClientSidePageHeaderLayoutType)Enum.Parse(typeof(ClientSidePageHeaderLayoutType), wpJObject["properties"]["layoutType"].ToString());
                        }
                        if (wpJObject["properties"]["textAlignment"] != null)
                        {
                            this.TextAlignment = (ClientSidePageHeaderTitleAlignment)Enum.Parse(typeof(ClientSidePageHeaderTitleAlignment), wpJObject["properties"]["textAlignment"].ToString());
                        }
                        if (wpJObject["properties"]["showKicker"] != null)
                        {
                            bool showKicker = false;
                            bool.TryParse(wpJObject["properties"]["showKicker"].ToString(), out showKicker);
                            this.ShowKicker = showKicker;
                        }
                        if (wpJObject["properties"]["showPublishDate"] != null)
                        {
                            bool showPublishDate = false;
                            bool.TryParse(wpJObject["properties"]["showPublishDate"].ToString(), out showPublishDate);
                            this.ShowPublishDate = showPublishDate;
                        }
                        if (wpJObject["properties"]["kicker"] != null)
                        {
                            this.Kicker = wpJObject["properties"]["kicker"].ToString();
                        }
                        if (wpJObject["properties"]["authors"] != null)
                        {
                            this.Authors = wpJObject["properties"]["authors"].ToString();
                        }

                        // Specific properties that only apply when the header has a custom image
                        if (!string.IsNullOrEmpty(this.imageServerRelativeUrl))
                        {
                            this.pageHeaderType = ClientSidePageHeaderType.Custom;
                            if (wpJObject["properties"] != null)
                            {
                                Guid result = new Guid();
                                if (Guid.TryParse(wpJObject["properties"]["siteId"].ToString(), out result))
                                {
                                    this.siteId = result;
                                }
                                if (Guid.TryParse(wpJObject["properties"]["webId"].ToString(), out result))
                                {
                                    this.webId = result;
                                }
                                if (Guid.TryParse(wpJObject["properties"]["listId"].ToString(), out result))
                                {
                                    this.listId = result;
                                }
                                if (wpJObject["properties"]["uniqueId"] != null && Guid.TryParse(wpJObject["properties"]["uniqueId"].ToString(), out result))
                                {
                                    this.uniqueId = result;
                                }

                                if (this.siteId != Guid.Empty && this.webId != Guid.Empty && this.listId != Guid.Empty && this.uniqueId != Guid.Empty)
                                {
                                    this.headerImageResolved = true;
                                }
                            }

                            System.Globalization.CultureInfo usCulture       = new System.Globalization.CultureInfo("en-US");
                            System.Globalization.CultureInfo europeanCulture = new System.Globalization.CultureInfo("nl-BE");

                            if (wpJObject["properties"]["translateX"] != null)
                            {
                                double translateX   = 0;
                                var    translateXEN = wpJObject["properties"]["translateX"].ToString();

                                System.Globalization.CultureInfo cultureToUse;
                                if (translateXEN.Contains("."))
                                {
                                    cultureToUse = usCulture;
                                }
                                else if (translateXEN.Contains(","))
                                {
                                    cultureToUse = europeanCulture;
                                }
                                else
                                {
                                    cultureToUse = usCulture;
                                }

                                Double.TryParse(translateXEN, System.Globalization.NumberStyles.Float, cultureToUse, out translateX);
                                this.TranslateX = translateX;
                            }
                            if (wpJObject["properties"]["translateY"] != null)
                            {
                                double translateY   = 0;
                                var    translateYEN = wpJObject["properties"]["translateY"].ToString();

                                System.Globalization.CultureInfo cultureToUse;
                                if (translateYEN.Contains("."))
                                {
                                    cultureToUse = usCulture;
                                }
                                else if (translateYEN.Contains(","))
                                {
                                    cultureToUse = europeanCulture;
                                }
                                else
                                {
                                    cultureToUse = usCulture;
                                }

                                Double.TryParse(translateYEN, System.Globalization.NumberStyles.Float, cultureToUse, out translateY);
                                this.TranslateY = translateY;
                            }

                            if (wpJObject["properties"]["altText"] != null)
                            {
                                this.AlternativeText = wpJObject["properties"]["altText"].ToString();
                            }
                        }
                        else
                        {
                            if (this.LayoutType == ClientSidePageHeaderLayoutType.NoImage)
                            {
                                this.pageHeaderType = ClientSidePageHeaderType.None;
                            }
                            else
                            {
                                this.pageHeaderType = ClientSidePageHeaderType.Default;
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a custom header with a custom image + custom image offset
 /// </summary>
 /// <param name="cc">ClientContext of the site hosting the image</param>
 /// <param name="pageHeaderType">Type of page header</param>
 /// <param name="imageServerRelativeUrl">Server relative image url</param>
 /// <param name="translateX">X offset coordinate</param>
 /// <param name="translateY">Y offset coordinate</param>
 public ClientSidePageHeader(ClientContext cc, ClientSidePageHeaderType pageHeaderType, string imageServerRelativeUrl, double translateX, double translateY) : this(cc, pageHeaderType, imageServerRelativeUrl)
 {
     TranslateX = translateX;
     TranslateY = translateY;
 }
 /// <summary>
 /// Creates a custom header with a custom image
 /// </summary>
 /// <param name="cc">ClientContext of the site hosting the image</param>
 /// <param name="pageHeaderType">Type of page header</param>
 /// <param name="imageServerRelativeUrl">Server relative image url</param>
 public ClientSidePageHeader(ClientContext cc, ClientSidePageHeaderType pageHeaderType, string imageServerRelativeUrl)
 {
     this.imageServerRelativeUrl = imageServerRelativeUrl;
     this.clientContext          = cc;
     this.pageHeaderType         = pageHeaderType;
 }
        /// <summary>
        /// Load the PageHeader object from the given html
        /// </summary>
        /// <param name="pageHeaderHtml">Page header html</param>
        public void FromHtml(string pageHeaderHtml)
        {
            // select all control div's
            if (String.IsNullOrEmpty(pageHeaderHtml))
            {
                this.pageHeaderType = ClientSidePageHeaderType.Default;
                return;
            }

            HtmlParser parser = new HtmlParser(new HtmlParserOptions()
            {
                IsEmbedded = true
            });

            using (var document = parser.Parse(pageHeaderHtml))
            {
                var pageHeaderControl = document.All.Where(m => m.HasAttribute(CanvasControl.ControlDataAttribute)).FirstOrDefault();
                if (pageHeaderControl != null)
                {
                    var     decoded   = WebUtility.HtmlDecode(pageHeaderControl.GetAttribute(ClientSideWebPart.ControlDataAttribute));
                    JObject wpJObject = JObject.Parse(decoded);

                    // Store the server processed content as that's needed for full fidelity
                    if (wpJObject["serverProcessedContent"] != null)
                    {
                        if (wpJObject["serverProcessedContent"]["imageSources"] != null && wpJObject["serverProcessedContent"]["imageSources"]["imageSource"] != null)
                        {
                            this.imageServerRelativeUrl = wpJObject["serverProcessedContent"]["imageSources"]["imageSource"].ToString();
                        }

                        if (!string.IsNullOrEmpty(this.imageServerRelativeUrl))
                        {
                            this.pageHeaderType = ClientSidePageHeaderType.Custom;
                            if (wpJObject["properties"] != null)
                            {
                                Guid result = new Guid();
                                if (Guid.TryParse(wpJObject["properties"]["siteId"].ToString(), out result))
                                {
                                    this.siteId = result;
                                }
                                if (Guid.TryParse(wpJObject["properties"]["webId"].ToString(), out result))
                                {
                                    this.webId = result;
                                }
                                if (Guid.TryParse(wpJObject["properties"]["listId"].ToString(), out result))
                                {
                                    this.listId = result;
                                }
                                if (wpJObject["properties"]["uniqueId"] != null && Guid.TryParse(wpJObject["properties"]["uniqueId"].ToString(), out result))
                                {
                                    this.uniqueId = result;
                                }

                                if (this.siteId != Guid.Empty && this.webId != Guid.Empty && this.listId != Guid.Empty && this.uniqueId != Guid.Empty)
                                {
                                    this.headerImageResolved = true;
                                }
                            }

                            System.Globalization.CultureInfo englishCulture = new System.Globalization.CultureInfo("en-EN");

                            if (wpJObject["properties"]["translateX"] != null)
                            {
                                double translateX   = 0;
                                var    translateXEN = wpJObject["properties"]["translateX"].ToString();
                                Double.TryParse(translateXEN, System.Globalization.NumberStyles.Float, englishCulture, out translateX);
                                this.TranslateX = translateX;
                            }
                            if (wpJObject["properties"]["translateY"] != null)
                            {
                                double translateY   = 0;
                                var    translateYEN = wpJObject["properties"]["translateY"].ToString();
                                Double.TryParse(translateYEN, System.Globalization.NumberStyles.Float, englishCulture, out translateY);
                                this.TranslateY = translateY;
                            }
                        }
                        else
                        {
                            if (wpJObject["properties"] != null)
                            {
                                if (wpJObject["properties"]["imageSourceType"] != null)
                                {
                                    int imageSourceType = -1;
                                    if (int.TryParse(wpJObject["properties"]["imageSourceType"].ToString(), out imageSourceType))
                                    {
                                        if (imageSourceType == 0)
                                        {
                                            this.pageHeaderType = ClientSidePageHeaderType.None;
                                        }
                                        else if (imageSourceType == 4)
                                        {
                                            this.pageHeaderType = ClientSidePageHeaderType.Default;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }