Exemple #1
0
        //ConvertJSONtoImageCollection
        public EPiImageGalleryImageCollection ConvertJsoNtoImageCollection(string json)
        {
            var colllection = new EPiImageGalleryImageCollection();
            var slides      = json.Split('|');

            foreach (var slide in slides)
            {
                if (String.IsNullOrEmpty(slide))
                {
                    continue;
                }
                try
                {
                    var attr = JsonSerialize(slide);
                    colllection.Add(new EPiImageGalleryImage(attr[0], attr[1], attr[2], attr[3], attr[4]));
                }
                catch (Exception e)
                {
                    //Log
                    var log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                    log.Error("ConvertJSONtoImageCollection Failed: value = " + json + " Exception: " + e.Message);
                }
            }


            return(colllection);
        }
Exemple #2
0
        //ConvertImageGalleryToJSON
        public string ConvertImageGalleryToJson(EPiImageGalleryImageCollection collection)
        {
            string json = "";

            if (collection != null)
            {
                foreach (EPiImageGalleryImage image in collection)
                {
                    json += "{\"id\":\"" + image.ImageId + "\",\"url\":\"" + image.ImageUrl + "\",\"alt\":\"" + image.Description + "\",\"link\":\"" + image.LinkUrl + "\",\"title\":\"" + image.Title + "\"}|";
                }
            }

            return(json);
        }
Exemple #3
0
        //ConvertXHTMLtoImageCollection
        public EPiImageGalleryImageCollection ConvertXhtmLtoImageCollection(string xhtml)
        {
            var collection = new EPiImageGalleryImageCollection();

            if (!String.IsNullOrEmpty(xhtml))
            {
                try
                {
                    //Extract images from XHTML
                    var xDoc = new XmlDocument();
                    xDoc.LoadXml(xhtml);
                    var images = xDoc.SelectNodes("/p/a");
                    foreach (XmlNode image in images)
                    {
                        if (image.FirstChild.Attributes == null)
                        {
                            continue;
                        }
                        var src   = HttpUtility.UrlDecode(image.FirstChild.Attributes["src"].Value);
                        var id    = image.FirstChild.Attributes["id"].Value;
                        var alt   = image.FirstChild.Attributes["alt"].Value.Replace("\"", """);
                        var title = image.FirstChild.Attributes["title"].Value.Replace("\"", """);
                        if (image.Attributes == null)
                        {
                            continue;
                        }
                        var link = image.Attributes["href"].Value;
                        collection.Add(new EPiImageGalleryImage(id, src, alt, link, title));
                    }
                }
                catch (Exception e)
                {
                    //Log
                    log4net.ILog _log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                    _log.Error("ConvertXHTMLtoImageCollection Failed: value = " + xhtml + " Exception: " + e.Message);
                }
            }

            return(collection);
        }
Exemple #4
0
        //ConvertToXHTML
        public string ConvertImageCollectionToXhtml(EPiImageGalleryImageCollection collection)
        {
            var xml = new XmlDocument();
            var p   = xml.CreateElement("p");

            xml.AppendChild(p);

            foreach (EPiImageGalleryImage image in collection)
            {
                var a = xml.CreateElement("a");
                a.SetAttribute("href", image.LinkUrl);
                var img = xml.CreateElement("img");
                img.SetAttribute("src", image.ImageUrl);
                img.SetAttribute("id", image.ImageId);
                img.SetAttribute("alt", image.Description);
                img.SetAttribute("title", image.Title);
                p.AppendChild(a);
                a.AppendChild(img);
            }

            return(xml.OuterXml);
        }
        //ConvertImageGalleryToJSON
        public string ConvertImageGalleryToJson(EPiImageGalleryImageCollection collection)
        {
            string json = "";

            if (collection != null)
            {
                foreach (EPiImageGalleryImage image in collection)
                    json += "{\"id\":\"" + image.ImageId + "\",\"url\":\"" + image.ImageUrl + "\",\"alt\":\"" + image.Description + "\",\"link\":\"" + image.LinkUrl + "\",\"title\":\"" + image.Title + "\"}|";
            }

            return json;
        }
        //ConvertJSONtoImageCollection
        public EPiImageGalleryImageCollection ConvertJsoNtoImageCollection(string json)
        {
            var colllection = new EPiImageGalleryImageCollection();
            var slides = json.Split('|');
            foreach (var slide in slides)
            {
                if (String.IsNullOrEmpty(slide)) continue;
                try
                {
                    var attr = JsonSerialize(slide);
                    colllection.Add(new EPiImageGalleryImage(attr[0], attr[1], attr[2], attr[3],attr[4]));
                }
                catch (Exception e)
                {
                    //Log
                    var log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                    log.Error("ConvertJSONtoImageCollection Failed: value = " + json + " Exception: " + e.Message);
                }
            }


            return colllection;
        }
        //ConvertToXHTML
        public string ConvertImageCollectionToXhtml(EPiImageGalleryImageCollection collection)
        {
            var xml = new XmlDocument();
            var p = xml.CreateElement("p");
            xml.AppendChild(p);

            foreach (EPiImageGalleryImage image in collection)
            {
                var a = xml.CreateElement("a");
                a.SetAttribute("href", image.LinkUrl);
                var img = xml.CreateElement("img");
                img.SetAttribute("src", image.ImageUrl);
                img.SetAttribute("id", image.ImageId);
                img.SetAttribute("alt", image.Description);
                img.SetAttribute("title", image.Title);
                p.AppendChild(a);
                a.AppendChild(img);
            }

            return xml.OuterXml;
        }
        //ConvertXHTMLtoImageCollection
        public EPiImageGalleryImageCollection ConvertXhtmLtoImageCollection(string xhtml)
        {
            var collection = new EPiImageGalleryImageCollection();

            if (!String.IsNullOrEmpty(xhtml))
            {
                try
                {
                    //Extract images from XHTML
                    var xDoc = new XmlDocument();
                    xDoc.LoadXml(xhtml);
                    var images = xDoc.SelectNodes("/p/a");
                    foreach (XmlNode image in images)
                    {
                        if (image.FirstChild.Attributes == null) continue;
                        var src = HttpUtility.UrlDecode(image.FirstChild.Attributes["src"].Value);
                        var id = image.FirstChild.Attributes["id"].Value;
                        var alt = image.FirstChild.Attributes["alt"].Value.Replace("\"", """);
                        var title = image.FirstChild.Attributes["title"].Value.Replace("\"", """);
                        if (image.Attributes == null) continue;
                        var link = image.Attributes["href"].Value;
                        collection.Add(new EPiImageGalleryImage(id, src, alt, link,title));
                    }
                }
                catch (Exception e)
                {
                    //Log
                    log4net.ILog _log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                    _log.Error("ConvertXHTMLtoImageCollection Failed: value = " + xhtml + " Exception: " + e.Message);
                }
            }

            return collection;
        }