Exemple #1
0
 public void AddImageNode(HtmlDocument htmlDoc,HtmlNode new_node,string image_source)
 {
     //<img src=\"{1}\" style=\"height:100%;width:100%;\"/>
     HtmlNode image_node = htmlDoc.CreateElement("img");
     HtmlAttribute src_attr = htmlDoc.CreateAttribute("src", image_source);
     image_node.Attributes.Append(src_attr);
     HtmlAttribute style_attr = htmlDoc.CreateAttribute("style", "height:100%;width:100%;");
     image_node.Attributes.Append(style_attr);
     new_node.AppendChild(image_node);
 }
        public static string GetFull(string html, bool removeAsccut = true)
        {
            html = html ?? string.Empty;
            try
            {
                var doc = new HtmlDocument();
                doc.LoadHtml(string.Format("<html>{0}</html>", HTMLTags.Replace(html, string.Empty)));
                if (removeAsccut)
                {
                    var nodes = doc.DocumentNode.SelectNodes("//div[translate(@class,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='asccut']");
                    if (nodes != null)
                    {
                        foreach (var node in nodes)
                        {
                            node.Attributes.Remove("class");
                            var styleAttr = doc.CreateAttribute("style");
                            styleAttr.Value = "display:inline;";
                            node.Attributes.Append(styleAttr);
                        }
                    }
                }

                ProcessCustomTags(doc);
                return HTMLTags.Replace(doc.DocumentNode.InnerHtml, string.Empty);
            }
            catch (Exception e)
            {
                return e.Message + "<br/> Please contact us: <a href='mailto:[email protected]'>[email protected]</a>";
            }
        }
Exemple #3
0
        public IHtmlAttribute AddAttribute(IHtmlElement element, string name, string value)
        {
            var attribute = _document.CreateAttribute(name, value);

            var elementNode = element.RawObject as HAP.HtmlNode;

            if (elementNode == null)
            {
                throw new ArgumentException("element");
            }

            elementNode.Attributes.Add(attribute);

            return(attribute.AsAttribute());
        }
Exemple #4
0
        public HtmlAttribute SetAttributeValue(string name, string value)
        {
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            HtmlAttribute attribute = Attributes[name];

            if (attribute == null)
            {
                return(Attributes.Append(_ownerdocument.CreateAttribute(name, value)));
            }
            attribute.Value = value;
            return(attribute);
        }
Exemple #5
0
        public static string GetFull(string html, Guid productID)
        {
            html = html ?? string.Empty;
            var doc = new HtmlDocument();
            doc.LoadHtml(string.Format("<html>{0}</html>", htmlTags.Replace(html, string.Empty)));
            var nodes = doc.DocumentNode.SelectNodes("//div[translate(@class,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz')='asccut']");
            if (nodes != null)
            {
                foreach (var node in nodes)
                {
                    node.Attributes.Remove("class");
                    var styleAttr = doc.CreateAttribute("style");
                    styleAttr.Value = "display:inline;";
                    node.Attributes.Append(styleAttr);
                }
            }

            ProcessCustomTags(doc, productID);
            return htmlTags.Replace(doc.DocumentNode.InnerHtml, string.Empty);
        }
Exemple #6
0
        private static void ProcessZoomImages(HtmlDocument doc, Guid productID)
        {
            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//img[@_zoom]");
            HtmlNode hrefNode;
            HtmlAttribute borderAttribute, hrefAttribute, srcAttribute, zoomAttribute;

            string imgSrc = string.Empty;
            if (nodes == null)
                return;
            foreach (HtmlNode node in nodes)
            {
                srcAttribute = node.Attributes["src"];
                if (srcAttribute == null || string.IsNullOrEmpty(srcAttribute.Value))
                    continue;

                zoomAttribute = node.Attributes["_zoom"];
                if (zoomAttribute == null || string.IsNullOrEmpty(zoomAttribute.Value))
                    continue;
                borderAttribute = node.Attributes["border"];

                if (borderAttribute == null)
                {
                    borderAttribute = doc.CreateAttribute("border");
                    node.Attributes.Append(borderAttribute);
                }
                borderAttribute.Value = "0";

                imgSrc = srcAttribute.Value;

                if (!rxNumeric.IsMatch(zoomAttribute.Value))
                {
                    imgSrc = zoomAttribute.Value;
                }

                if (node.ParentNode != null)
                {
                    hrefNode = doc.CreateElement("a");

                    hrefAttribute = doc.CreateAttribute("href");
                    hrefAttribute.Value = imgSrc;
                    hrefNode.Attributes.Append(hrefAttribute);

                    hrefAttribute = doc.CreateAttribute("class");
                    hrefAttribute.Value = "fancyzoom";
                    hrefNode.Attributes.Append(hrefAttribute);

                    /*
                    hrefAttribute = doc.CreateAttribute("onclick");
                                        hrefAttribute.Value = string.Format(@"javascript:if(typeof(popimgFckup) == 'function')popimgFckup('{0}');", srcAttribute.Value);
                                        hrefNode.Attributes.Append(hrefAttribute);*/


                    node.ParentNode.ReplaceChild(hrefNode, node);
                    hrefNode.AppendChild(node);
                }
            }

        }
        private static List<HelpCenterItem> ParseHelpCenterHtml(string html, string helpLinkBlock)
        {
            var helpCenterItems = new List<HelpCenterItem>();

            if (string.IsNullOrEmpty(html)) return helpCenterItems;

            var doc = new HtmlDocument();
            doc.LoadHtml(html);

            var urlHelp = CommonLinkUtility.GetHelpLink(false);
            var mainContent = doc.DocumentNode.SelectSingleNode("//div[@class='MainHelpCenter GettingStarted']");

            if (mainContent == null) return helpCenterItems;

            var blocks = (mainContent.SelectNodes(".//div[@class='gs_content']"))
                .Where(r => r.Attributes["id"] != null)
                .Select(x => x.Attributes["id"].Value).ToList();

            foreach (var block in mainContent.SelectNodes(".//div[@class='gs_content']"))
            {
                var hrefs = block.SelectNodes(".//a[@href]")
                                 .Where(r =>
                                            {
                                                var value = r.Attributes["href"].Value;
                                                return r.Attributes["href"] != null
                                                       && !string.IsNullOrEmpty(value)
                                                       && !value.StartsWith("mailto:")
                                                       && !value.StartsWith("http");
                                            });

                foreach (var href in hrefs)
                {
                    var value = href.Attributes["href"].Value;

                    if (value.IndexOf("#", StringComparison.Ordinal) != 0 && value.Length > 1)
                    {
                        href.Attributes["href"].Value = urlHelp + value.Substring(1);
                        href.SetAttributeValue("target", "_blank");
                    }
                    else
                    {
                        if (!blocks.Contains(value.Substring(1))) continue;

                        href.Attributes["href"].Value = helpLinkBlock + blocks.IndexOf(value.Substring(1)).ToString(CultureInfo.InvariantCulture);
                    }
                }

                var images = block.SelectNodes(".//img");
                if (images != null)
                {
                    foreach (var img in images.Where(img => img.Attributes["src"] != null))
                    {
                        img.Attributes["src"].Value = GetInternalLink(urlHelp + img.Attributes["src"].Value);
                    }

                    foreach (var screenPhoto in images.Where(img =>
                                                     img.Attributes["class"] != null && img.Attributes["class"].Value.Contains("screenphoto")
                                                     && img.Attributes["target"] != null && img.ParentNode != null))
                    {
                        var bigphotoScreenId = screenPhoto.Attributes["target"].Value;

                        var bigphotoScreen = images.FirstOrDefault(img =>
                                                             img.Attributes["id"] != null && img.Attributes["id"].Value == bigphotoScreenId
                                                             && img.Attributes["class"] != null && img.Attributes["class"].Value.Contains("bigphoto_screen")
                                                             && img.Attributes["src"] != null);
                        if (bigphotoScreen == null) continue;

                        var hrefNode = doc.CreateElement("a");
                        var hrefAttribute = doc.CreateAttribute("href");
                        hrefAttribute.Value = bigphotoScreen.Attributes["src"].Value;
                        hrefNode.Attributes.Append(hrefAttribute);

                        hrefAttribute = doc.CreateAttribute("class");
                        hrefAttribute.Value = "screenzoom";
                        hrefNode.Attributes.Append(hrefAttribute);

                        hrefAttribute = doc.CreateAttribute("rel");
                        hrefAttribute.Value = "imageHelpCenter";
                        hrefNode.Attributes.Append(hrefAttribute);

                        screenPhoto.ParentNode.ReplaceChild(hrefNode, screenPhoto);
                        hrefNode.AppendChild(screenPhoto);
                    }
                }

                var titles = block.SelectSingleNode(".//h2");
                var contents = block.SelectSingleNode(".//div[@class='PortalHelp']");

                if (titles != null && contents != null)
                {
                    helpCenterItems.Add(new HelpCenterItem { Title = titles.InnerText, Content = contents.InnerHtml });
                }
            }
            return helpCenterItems;
        }
        private static void ProcessZoomImages(HtmlDocument doc)
        {
            var nodes = doc.DocumentNode.SelectNodes("//img[@_zoom]");

            if (nodes == null) return;
            foreach (var node in nodes)
            {
                if (node.ParentNode != null && (node.ParentNode.Name ?? "").ToLower() == "a") continue;

                var srcAttribute = node.Attributes["src"];
                if (srcAttribute == null || string.IsNullOrEmpty(srcAttribute.Value)) continue;

                var zoomAttribute = node.Attributes["_zoom"];
                if (zoomAttribute == null || string.IsNullOrEmpty(zoomAttribute.Value)) continue;

                var borderAttribute = node.Attributes["border"];
                if (borderAttribute == null)
                {
                    borderAttribute = doc.CreateAttribute("border");
                    node.Attributes.Append(borderAttribute);
                }
                borderAttribute.Value = "0";

                var imgSrc = srcAttribute.Value;

                if (!RxNumeric.IsMatch(zoomAttribute.Value))
                {
                    imgSrc = zoomAttribute.Value;
                }

                if (node.ParentNode != null)
                {
                    var hrefNode = doc.CreateElement("a");

                    var hrefAttribute = doc.CreateAttribute("href");
                    hrefAttribute.Value = imgSrc;
                    hrefNode.Attributes.Append(hrefAttribute);

                    hrefAttribute = doc.CreateAttribute("class");
                    hrefAttribute.Value = "screenzoom";
                    hrefNode.Attributes.Append(hrefAttribute);

                    string title = null;
                    var titleAttribute = node.Attributes["title"];
                    if (titleAttribute != null)
                    {
                        title = titleAttribute.Value;
                    }
                    else
                    {
                        var altAttribute = node.Attributes["alt"];
                        if (altAttribute != null)
                        {
                            title = altAttribute.Value;
                        }
                    }
                    if (!string.IsNullOrEmpty(title))
                    {
                        hrefAttribute = doc.CreateAttribute("title");
                        hrefAttribute.Value = title;
                        hrefNode.Attributes.Append(hrefAttribute);
                    }

                    node.ParentNode.ReplaceChild(hrefNode, node);
                    hrefNode.AppendChild(node);
                }
            }
        }
Exemple #9
0
    public string GetAppPage(Hashtable State, string page_name)
    {
        try
        {
            XmlDocument xmlDoc = GetStagingAppXml(State);

            //get background image
            XmlNode configuration_node = xmlDoc.SelectSingleNode("//configuration");
            XmlNode background_node = configuration_node.SelectSingleNode("background");
            if (background_node == null)
            {
                background_node = CreateNode(xmlDoc, configuration_node, "background");
            }
            XmlNode background_image_node = background_node.SelectSingleNode("image_source");
            if (background_image_node == null)
            {
                background_image_node = CreateNode(xmlDoc, background_node, "image_source", "https://s3.amazonaws.com/MobiFlexImages/apps/images/backgrounds/standard_w_header_iphone.jpg");
            }
            string background_image = background_image_node.InnerText;
            if (background_image.Contains("s3.amazonaws.com"))
            {
                if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE)
                    background_image = background_image.Replace("_iphone.", "_android.");
                State["BackgroundImageUrl"] = background_image;
            }
            else
            {
                background_image = background_image.Substring(background_image.LastIndexOf("/") + 1);
                if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE)
                    background_image = background_image.Replace("_iphone.", "_android.");

                State["BackgroundImageUrl"] = "https://s3.amazonaws.com/MobiFlexImages/apps/images/backgrounds/" + background_image;
            }

            XmlNode page_name_node = xmlDoc.SelectSingleNode("//pages/page/name[.  ='" + page_name + "']");
            if (page_name_node == null)
                return "";

            double y_factor = 1.0D;
            Util util = new Util();
            //if (State["SelectedDeviceType"].ToString() != State["SelectedDeviceView"].ToString())
            //{
           //     y_factor = util.GetYFactor(State);
           // }

            XmlNode page_node = page_name_node.ParentNode;
            XmlNode fields_node = page_node.SelectSingleNode("fields");
            if(fields_node == null)
                return "";

            XmlNodeList field_list = page_node.SelectSingleNode("fields").ChildNodes;
            HtmlDocument htmlDoc = new HtmlDocument();
            HtmlNode root = htmlDoc.DocumentNode;
            foreach (XmlNode field in field_list)
            {
                try
                {
                    //restrict certain cross use fields
                    if (State["SelectedAppType"].ToString() == Constants.NATIVE_APP_TYPE)
                    {
                        if (field.Name == "html_panel")
                            continue;
                    }

                    HtmlNode new_node = htmlDoc.CreateElement("div");
                    Hashtable field_map = ParseXmlToHtml(field);
                    SetCommonHtmlAttributes(htmlDoc, new_node, field_map, y_factor, field.Name);
                    HtmlAttribute title_attr = htmlDoc.CreateAttribute("title");
                    switch (field.Name)
                    {
                        case "image"://"<div title=\"MobiFlex Image\" id=\"{0}\"  type=\"get\" style=\"{2}\" ><img src=\"{1}\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Image";
                            string image_url = field_map["image_source"].ToString();
                            if (!field_map.ContainsKey("width")) //the xml does not have the width and height so use the width and height of the actual image
                            {
                                Size size = util.GetImageSize(image_url);
                                if (size != null)
                                {
                                    new_node.Attributes["style"].Value += "width:" + size.Width.ToString() + "px;height:" + size.Height.ToString() + "px;";
                                }
                            }
                            AddImageNode(htmlDoc, new_node, image_url);
                            break;
                        case "audio"://<div title=\"MobiFlex Audio\" id=\"{0}\" source=\"{1}\" style=\"{2}\"  ><img src=\"images/editor_images/audio_field.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Audio";
                            HtmlAttribute audio_source_attr = htmlDoc.CreateAttribute("source", field_map["audio_source"].ToString());
                            new_node.Attributes.Append(audio_source_attr);
                            AddImageNode(htmlDoc, new_node, "images/editor_images/audio_field.png");
                            break;
                        case "label": //"<div title=\"MobiFlex Label\" id=\"{0}\" style=\"{2}\" >{1}<img class=\"spacer\" src=\"images/spacer.gif\" style=\"position:relative;top:-16px;width:100%;height:100%\" /></div>"
                            title_attr.Value = "MobiFlex Label";
                            new_node.InnerHtml = field_map["text"].ToString();

                            //<img class=\"spacer\" src=\"images/spacer.gif\" style=\"position:relative;top:-16px;width:100%;height:100%\" />
                            HtmlNode label_img_node = htmlDoc.CreateElement("img");
                            HtmlAttribute label_img_src_attr = htmlDoc.CreateAttribute("src", "images/spacer.gif");
                            label_img_node.Attributes.Append(label_img_src_attr);

                            int label_font_size = -Convert.ToInt32(field_map["font_size"].ToString());
                            HtmlAttribute label_img_style_attr = htmlDoc.CreateAttribute("style", "position:relative;top:" + label_font_size.ToString() + "px;width:100%;height:100%");
                            label_img_node.Attributes.Append(label_img_style_attr);
                            new_node.AppendChild(label_img_node);
                            break;
                        case "text_field": //"<div title=\"MobiFlex TextField\" id=\"{0}\" type=\"{1}\" alt=\"{2}\"  style=\"{3}\" ><img src=\"images/editor_images/text_field.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex TextField";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/text_field.png");
                            string alt = "keyboard:";
                            if (field_map.ContainsKey("keyboard"))
                                alt +=  field_map["keyboard"].ToString() + ";";
                            else
                                alt +=  "default;";

                            if (field_map.ContainsKey("validation"))
                                alt += "validation:" + field_map["validation"].ToString();
                            else
                                alt += "validation:none";
                            HtmlAttribute alt_attr = htmlDoc.CreateAttribute("alt", alt);
                            new_node.Attributes.Append(alt_attr);
                            HtmlAttribute type_attr = htmlDoc.CreateAttribute("type", field_map["type"].ToString());
                            new_node.Attributes.Append(type_attr);
                            if (field_map["text"] != null)
                            {
                                HtmlAttribute text_attr = htmlDoc.CreateAttribute("text", EncodeStudioHtml(UnescapeXml(field_map["text"].ToString())));
                                new_node.Attributes.Append(text_attr);
                            }
                            break;
                        case "html_panel": //"<div title=\"MobiFlex HtmlPanel\" id=\"{0}\" style=\"{2}\" ><div style=\"width:98%;height:98%;overflow:hidden;background-color:#ffffff\">{1}</div></div>"
                            title_attr.Value = "MobiFlex HtmlPanel";
                            new_node.InnerHtml = HttpUtility.HtmlDecode(field_map["html"].ToString());
                            /* HtmlNode container_node = htmlDoc.CreateElement("div");
                             HtmlAttribute panel_style_attr = htmlDoc.CreateAttribute("style", " width:98%;height:98%;overflow:hidden;background-color:#ffffff");
                             container_node.Attributes.Append(panel_style_attr);
                              container_node.InnerHtml = HttpUtility.HtmlDecode(field_map["html"].ToString());
                            new_node.AppendChild(container_node);*/
                            break;
                        case "web_view": //<div title=\"MobiFlex WebView\" alt=\"MobiFlex WebView\" id=\"{0}\" style=\"position:absolute;z-index:{2};top:44px;left:0px;height:416px;width:320px;\" url=\"{1}\" ><iframe src='" + src + "' width='99%' height='99.4%' marginheight='0' marginwidth='0' scrolling='no' style='border-width:0;' /></div>"
                            title_attr.Value = "MobiFlex WebView";
                            if (field_map["url"] == null)
                                field_map["url"] = "";
                            HtmlAttribute url_attr = htmlDoc.CreateAttribute("url", field_map["url"].ToString());
                            new_node.Attributes.Append(url_attr);
                            if (field_map["url"].ToString().Length > 0)
                            {
                                HtmlNode iframe_node = htmlDoc.CreateElement("iframe");
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("src", field_map["url"].ToString()));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("width", "99%"));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("height", "99.4%"));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("marginheight", "0"));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("marginwidth", "0"));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("scrolling", "no"));
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("style", "border-width:0;"));
                                new_node.AppendChild(iframe_node);
                            }
                            else
                            {
                                HtmlNode div_node = htmlDoc.CreateElement("div");
                                String webview_url = "images/editor_images/WebView.jpg";
                                if (State["SelectedDeviceType"].ToString() == Constants.IPAD ||
                                   State["SelectedDeviceType"].ToString() == Constants.ANDROID_TABLET)
                                    webview_url = "images/editor_images/WebView_ipad.jpg";
                                HtmlAttribute style2_attr = htmlDoc.CreateAttribute("style", "width:100%;height:100%;background-image:url('" + webview_url + "');background-repeat:no-repeat");
                                div_node.Attributes.Append(style2_attr);
                                new_node.AppendChild(div_node);
                            }
                            break;
                        case "button": //"<div title=\"MobiFlex Button\" style=\"{3}\" id=\"{0}\" align=\"center\"  submit=\"{1}\"><img src=\"https://s3.amazonaws.com/MobiFlexImages/apps/images/blank_buttons/medium_green_button.png\" style=\"width:100%;height:100%\" /><p style=\"position:relative;top:-38px;\">{2}</p></div>"
                            title_attr.Value = "MobiFlex Button";

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
                                XmlNode submit_node = field.SelectSingleNode("submit");
                                if (submit_node.ChildNodes.Count > 1)
                                {
                                    StringBuilder sb_submit = new StringBuilder();
                                    sb_submit.Append(submit_node.LastChild.Name + ":");
                                    bool is_first = true;
                                    foreach (XmlNode submit_attribute in submit_node.LastChild.ChildNodes)
                                    {
                                        if (is_first)
                                            is_first = false;
                                        else
                                            sb_submit.Append(",");
                                        sb_submit.Append(submit_attribute.Name + "~" + submit_attribute.InnerText.Replace(":", "%3A"));
                                    }
                                    submit = sb_submit.ToString() + ";";
                                }
                                else
                                {
                                    submit = field_map["submit"].ToString() + ";";
                                    //bring to forward compatibility
                                    if (submit.StartsWith("post"))
                                    {
                                        if (submit.Length >= 19)
                                            //submit = submit.Remove(0, 19).Insert(0, "post:response_page~");
                                            submit = submit.Remove(0, 19).Insert(0, "post:");
                                    }
                                    else if (submit.Contains("next_page:"))
                                        submit = submit.Replace("next_page:", "next_page:page~");
                                    else if (submit.Contains("call:"))
                                        submit = submit.Replace("call:", "call:phone_field~");
                                }
                            }

                            if (field_map.ContainsKey("compute"))
                            {
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                submit += "compute:" + decode + ";";
                            }

                            HtmlAttribute submit_attr = htmlDoc.CreateAttribute("submit", submit);
                            new_node.Attributes.Append(submit_attr);

                            //align=\"center\"
                            HtmlAttribute align_attr = htmlDoc.CreateAttribute("align", "center");
                            new_node.Attributes.Append(align_attr);

                            //<img src=\"https://s3.amazonaws.com/MobiFlexImages/apps/images/blank_buttons/medium_green_button.png\" style=\"width:100%;height:100%\" />
                            HtmlNode img_node = htmlDoc.CreateElement("img");
                            HtmlAttribute img_src_attr = null;
                            if (field_map["image_source"] != null)
                                img_src_attr = htmlDoc.CreateAttribute("src", field_map["image_source"].ToString());
                            else
                                img_src_attr = htmlDoc.CreateAttribute("src", "https://s3.amazonaws.com/MobiFlexImages/apps/images/blank_buttons/medium_green_button.png");

                            img_node.Attributes.Append(img_src_attr);

                            HtmlAttribute img_style_attr = htmlDoc.CreateAttribute("style", "width:100%;height:100%");
                            img_node.Attributes.Append(img_style_attr);
                            new_node.AppendChild(img_node);

                            //<p style=\"position:relative;top:-38px;\">{2}</p>
                            HtmlNode p_node = htmlDoc.CreateElement("p");
                            HtmlNode text_node = null;
                            if (field_map["text"] != null)
                                text_node = htmlDoc.CreateTextNode(field_map["text"].ToString());
                            else
                                text_node = htmlDoc.CreateTextNode("");

                            p_node.AppendChild(text_node);
                            //top = (-ph/2) -(3*ah/2);
                            int height = Convert.ToInt32(field_map["height"].ToString());
                            int font_size = Convert.ToInt32(field_map["font_size"].ToString());
                            int top = (-height / 2) - (3 * font_size / 2);
                            HtmlAttribute style_attr = htmlDoc.CreateAttribute("style", "position:relative;top:" + top.ToString() + "px;");
                            p_node.Attributes.Append(style_attr);
                            new_node.AppendChild(p_node);
                            break;
                        case "image_button": //"<div title=\"MobiFlex ImageButton\"  style=\"{3}\" id=\"{0}\"  submit=\"{2}\"><img src=\"{1}\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex ImageButton";
                            string image_button_url = field_map["image_source"].ToString();
                            if (!field_map.ContainsKey("width")) //the xml does not have the width and height so use the width and height of the actual image
                            {
                                Size size = util.GetImageSize(image_button_url);
                                if (size != null)
                                {
                                    new_node.Attributes["style"].Value += "width:" + size.Width.ToString() + "px;height:" + size.Height.ToString() + "px;";
                                }
                            }
                            AddImageNode(htmlDoc, new_node, image_button_url);

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string image_button_submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
                                XmlNode submit_node = field.SelectSingleNode("submit");
                                if (submit_node.ChildNodes.Count > 1)
                                {
                                    StringBuilder sb_submit = new StringBuilder();
                                    sb_submit.Append(submit_node.LastChild.Name + ":");
                                    bool is_first = true;
                                    foreach (XmlNode submit_attribute in submit_node.LastChild.ChildNodes)
                                    {
                                        if (is_first)
                                            is_first = false;
                                        else
                                            sb_submit.Append(",");
                                        sb_submit.Append(submit_attribute.Name + "~" + submit_attribute.InnerText.Replace(":", "%3A"));
                                    }
                                    image_button_submit = sb_submit.ToString() + ";";
                                }
                                else
                                {
                                    image_button_submit = field_map["submit"].ToString() + ";";
                                    //bring to forward compatibility
                                    if (image_button_submit.StartsWith("post"))
                                    {
                                        if (image_button_submit.Length >= 19)
                                           // image_button_submit = image_button_submit.Remove(0, 19).Insert(0, "post:response_page~");
                                            image_button_submit = image_button_submit.Remove(0, 19).Insert(0, "post:");
                                    }
                                    else if (image_button_submit.Contains("next_page:"))
                                        image_button_submit = image_button_submit.Replace("next_page:", "next_page:page~");
                                    else if (image_button_submit.Contains("call:"))
                                        image_button_submit = image_button_submit.Replace("call:", "call:phone_field~");
                                }
                            }
                            if (field_map.ContainsKey("compute"))
                            {
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                image_button_submit += "compute:" + decode + ";";
                              }

                            HtmlAttribute image_button_submit_attr = htmlDoc.CreateAttribute("submit", image_button_submit);
                            new_node.Attributes.Append(image_button_submit_attr);
                            break;
                        case "picker": //"<div title=\"MobiFlex Picker\" style=\"position:absolute;z-index:{3};top:44px;left:0px;width:320px; height:216px;background-image:url('images/editor_images/datepicker.jpg');background-repeat:no-repeat\" id=\"{0}\"  type=\"{1}\" options=\"\"  />"
                            title_attr.Value = "MobiFlex Picker";
                            string picker_type = field_map["picker_type"].ToString();
                            if ((State["SelectedAppType"].ToString() == Constants.WEB_APP_TYPE || State["SelectedAppType"].ToString() == Constants.HYBRID_APP_TYPE) &&
                                picker_type != "date" &&
                                picker_type != "time" &&
                                picker_type != "1_section")
                            {
                                picker_type = "1_section";
                            }
                            HtmlAttribute picker_type_attr = htmlDoc.CreateAttribute("type", picker_type);
                            new_node.Attributes.Append(picker_type_attr);
                            if ((State["SelectedDeviceType"] != null && State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE) ||
                                (State["SelectedAppType"].ToString() == Constants.WEB_APP_TYPE || State["SelectedAppType"].ToString() == Constants.HYBRID_APP_TYPE))
                            {
                                switch (picker_type)
                                {
                                    case "date":
                                    case "time":
                                    case "1_section":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/spinner.jpg');background-repeat:no-repeat;";
                                        new_node.Attributes["style"].Value = new_node.Attributes["style"].Value.Replace("height:216px", "height:40px");
                                        break;
                                    case "2_sections":
                                    case "3_sections":
                                    case "4_sections":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/2section_spinner.jpg');background-repeat:no-repeat;";
                                        break;
                                }
                            }
                            else
                            {
                                switch (picker_type)
                                {
                                    case "date":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/datepicker.jpg');background-repeat:no-repeat;";
                                        break;
                                    case "time":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/time_picker.jpg');background-repeat:no-repeat;";
                                        break;
                                    case "1_section":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/1section_picker.jpg');background-repeat:no-repeat;";
                                        break;
                                    case "2_sections":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/2section_picker.jpg');background-repeat:no-repeat;";
                                        break;
                                    case "3_sections":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/3section_picker.jpg');background-repeat:no-repeat;";
                                        break;
                                    case "4_sections":
                                        new_node.Attributes["style"].Value += "background-image:url('images/editor_images/4section_picker.jpg');background-repeat:no-repeat;";
                                        break;
                                }
                            }
                            StringBuilder name_list = new StringBuilder();

                            if (picker_type.Contains("section"))
                            {
                                XmlNodeList picker_fields = field.SelectNodes("picker_fields/picker_field");
                                StringBuilder option_list = new StringBuilder();
                                bool isFirst = true;
                                foreach (XmlNode picker_field in picker_fields)
                                {
                                    XmlNode name_node = picker_field.SelectSingleNode("name");
                                    if (isFirst)
                                        isFirst = false;
                                    else
                                    {
                                        name_list.Append(",");
                                        option_list.Append("|");
                                    }
                                    name_list.Append(name_node.InnerText);
                                    XmlNode options_node = picker_field.SelectSingleNode("options");
                                    if (options_node != null)
                                        option_list.Append(options_node.InnerText);
                                    if ((State["SelectedAppType"].ToString() == Constants.WEB_APP_TYPE) || State["SelectedAppType"].ToString() == Constants.HYBRID_APP_TYPE )
                                        break;
                                }

                                HtmlAttribute picker_options = htmlDoc.CreateAttribute("options", EncodeStudioHtml(UnescapeXml(option_list.ToString())));
                                new_node.Attributes.Append(picker_options);

                                picker_type_attr.Value += ":" + name_list.ToString();
                            }
                            break;
                        case "text_area": //"position:absolute;z-index:{0};top:44px;left:10px;width:250px;height:300px;font-family:Verdana;font-size:16px;color:#000000;font-style:normal;font-weight:normal;text-decoration:none;padding:5px;background-image:url('images/editor_images/text_area.png');background-repeat:no-repeat;background-size:100% 100%;overflow:hidden"
                            title_attr.Value = "MobiFlex TextArea";
                            new_node.Attributes["style"].Value += "background-image:url('images/editor_images/text_area.png');background-repeat:no-repeat;background-size:100% 100%;overflow:hidden;";
                            if (field_map.ContainsKey("text"))
                            {
                                HtmlAttribute text_attr = htmlDoc.CreateAttribute("text", EncodeStudioHtml(UnescapeXml(field_map["text"].ToString())));
                                new_node.Attributes.Append(text_attr);
                                new_node.InnerHtml = "<div style=\"padding:5px\">" + field_map["text"].ToString().Replace(@"\n", "<br/>") + "</div>";
                            }
                            string edit_type = "non_editable";
                            if (field_map.ContainsKey("edit_type"))
                            {
                                edit_type = field_map["edit_type"].ToString();
                            }
                            HtmlAttribute edit_type_attr = htmlDoc.CreateAttribute("type", edit_type);
                            new_node.Attributes.Append(edit_type_attr);
                            break;
                        case "switch": //"<div title=\"MobiFlex Switch\" id=\"{0}\" style=\"{4}\" type=\"{1}\" value=\"{2}\" submit=\"{3}\" ><img src=\"" + image_url + "\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Switch";
                            string switch_value = field_map["default_value"].ToString();
                            switch (switch_value)
                            {
                                case "on":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_on.png");
                                     break;
                                case "off":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_off.png");
                                    break;
                                case "yes":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_yes.png");
                                    break;
                                case "no":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_no.png");
                                    break;
                                case "true":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_true.png");
                                    break;
                                case "false":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/switch_false.png");
                                    break;
                            }

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string switch_submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
                                XmlNode submit_node = field.SelectSingleNode("submit");
                                if (submit_node.ChildNodes.Count > 1)
                                {
                                    StringBuilder sb_submit = new StringBuilder();
                                    sb_submit.Append(submit_node.LastChild.Name + ":");
                                    bool is_first = true;
                                    foreach (XmlNode submit_attribute in submit_node.LastChild.ChildNodes)
                                    {
                                        if (is_first)
                                            is_first = false;
                                        else
                                            sb_submit.Append(",");
                                        sb_submit.Append(submit_attribute.Name + "~" + submit_attribute.InnerText);
                                    }
                                    switch_submit = sb_submit.ToString() + ";";
                                }
                                else
                                {
                                    switch_submit = field_map["submit"].ToString() + ";";
                                    //bring to forward compatibility
                                    if (switch_submit.StartsWith("post"))
                                    {
                                        if (switch_submit.Length >= 19)
                                            //switch_submit = switch_submit.Remove(0, 19).Insert(0, "post:response_page~");
                                             switch_submit = switch_submit.Remove(0, 19).Insert(0, "post:");
                                    }
                                    else if (switch_submit.Contains("next_page:"))
                                        switch_submit = switch_submit.Replace("next_page:", "next_page:page~");
                                    else if (switch_submit.Contains("call:"))
                                        switch_submit = switch_submit.Replace("call:", "call:phone_field~");
                                }
                            }
                            if (field_map.ContainsKey("compute"))
                            {
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                switch_submit += "compute:" + decode + ";";
                            }

                            HtmlAttribute switch_type_attr = null;
                            if (field_map["type"] != null)
                                switch_type_attr = htmlDoc.CreateAttribute("type", field_map["type"].ToString());

                            else
                                switch_type_attr = htmlDoc.CreateAttribute("type", "on_off");

                            new_node.Attributes.Append(switch_type_attr);

                            HtmlAttribute value_attr = htmlDoc.CreateAttribute("value", field_map["default_value"].ToString());
                            new_node.Attributes.Append(value_attr);

                            HtmlAttribute switch_submit_attr = htmlDoc.CreateAttribute("submit", switch_submit);
                            new_node.Attributes.Append(switch_submit_attr);
                            break;
                        case "checkbox": //"<div title=\"MobiFlex Switch\" id=\"{0}\" style=\"{4}\" type=\"{1}\" value=\"{2}\" submit=\"{3}\" ><img src=\"" + image_url + "\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex CheckBox";
                            string checkbox_value = field_map["default_value"].ToString();
                            switch (checkbox_value)
                            {
                                case "checked":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/checkbox_on.png");
                                    break;
                                case "unchecked":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/checkbox_off.png");
                                    break;
                            }

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string checkbox_submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
                                XmlNode submit_node = field.SelectSingleNode("submit");
                                if (submit_node.ChildNodes.Count > 1)
                                {
                                    StringBuilder sb_submit = new StringBuilder();
                                    sb_submit.Append(submit_node.LastChild.Name + ":");
                                    bool is_first = true;
                                    foreach (XmlNode submit_attribute in submit_node.LastChild.ChildNodes)
                                    {
                                        if (is_first)
                                            is_first = false;
                                        else
                                            sb_submit.Append(",");
                                        sb_submit.Append(submit_attribute.Name + "~" + submit_attribute.InnerText);
                                    }
                                    checkbox_submit = sb_submit.ToString() + ";";
                                }
                                else
                                {
                                    checkbox_submit = field_map["submit"].ToString() + ";";
                                    //bring to forward compatibility
                                    if (checkbox_submit.StartsWith("post"))
                                    {
                                        if (checkbox_submit.Length >= 19)
                                            //checkbox_submit = checkbox_submit.Remove(0, 19).Insert(0, "post:response_page~");
                                            checkbox_submit = checkbox_submit.Remove(0, 19).Insert(0, "post:");
                                    }
                                    else if (checkbox_submit.Contains("next_page:"))
                                        checkbox_submit = checkbox_submit.Replace("next_page:", "next_page:page~");
                                    else if (checkbox_submit.Contains("call:"))
                                        checkbox_submit = checkbox_submit.Replace("call:", "call:phone_field~");
                                }
                            }
                            if (field_map.ContainsKey("compute"))
                            {
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                checkbox_submit += "compute:" + decode + ";";
                            }

                            HtmlAttribute checkbox_value_attr = htmlDoc.CreateAttribute("value", field_map["default_value"].ToString());
                            new_node.Attributes.Append(checkbox_value_attr);

                            HtmlAttribute checkbox_submit_attr = htmlDoc.CreateAttribute("submit", checkbox_submit);
                            new_node.Attributes.Append(checkbox_submit_attr);
                            break;
                        case "slider": //"<div title=\"MobiFlex Slider\" id=\"{0}\" value=\"{2}\" style=\"z-index:{3};top:160px;left:10px;height:57px;width:283px;\" type=\"{1}\" ><img src=\"images/editor_images/horizontal_slider.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Slider";
                            string slider_type = field_map["type"].ToString();
                            HtmlAttribute slider_type_attr = htmlDoc.CreateAttribute("type", slider_type);
                            new_node.Attributes.Append(slider_type_attr);
                            switch (slider_type)
                            {
                                case "horizontal":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/horizontal_slider.png");
                                    break;
                                case "vertical":
                                    AddImageNode(htmlDoc, new_node, "images/editor_images/vertical_slider.png");
                                    break;
                            }
                            string min_value = field_map["min_value"].ToString();
                            string max_value = field_map["max_value"].ToString();
                            HtmlAttribute slider_value_attr = htmlDoc.CreateAttribute("value", min_value + ":" + max_value);
                            new_node.Attributes.Append(slider_value_attr);
                            break;
                        case "table": //"<div title=\"MobiFlex Table\" id=\"{0}\" name=\"{1}\" alt=\"MobiFlex Table\"  style=\"position:absolute;z-index:{5};top:44px;left:0px;height:416px;width:320px;background-image:url('images/editor_images/largetableview1textfield.jpg');background-repeat:no-repeat\"  fields=\"{2}\" options=\"{4}\" submit=\"{3}\" />"
                            title_attr.Value = "MobiFlex Table";
                            string display_name = field_map["id"].ToString();
                            if (field_map["display_name"] != null)
                            {
                                display_name = field_map["display_name"].ToString();
                            }
                            HtmlAttribute table_display_name_attr = htmlDoc.CreateAttribute("name", display_name);
                            new_node.Attributes.Append(table_display_name_attr);

                            string table_type = field_map["table_type"].ToString();
                            if (table_type.Contains("image1text") || table_type.Contains("imagetext") || table_type.Contains("image1texthidden"))
                                new_node.Attributes["style"].Value += "background-image:url('images/editor_images/LargeTableView1Image1textField.jpg');background-repeat:no-repeat;";
                            else if (table_type.Contains("image2texts") || table_type.Contains("image2textshidden") )
                                new_node.Attributes["style"].Value += "background-image:url('images/editor_images/LargeTableView1Image2TextFields.jpg');background-repeat:no-repeat;";
                            else if (table_type.Contains("1text") || table_type.Contains("1texthidden"))
                                new_node.Attributes["style"].Value += "background-image:url('images/editor_images/LargeTableView1TextField.jpg');background-repeat:no-repeat;";
                            else if (table_type.Contains("2texts") || table_type.Contains("2textshidden"))
                                new_node.Attributes["style"].Value += "background-image:url('images/editor_images/LargeTableView2TextFields.jpg');background-repeat:no-repeat;";

                            XmlNodeList table_fields = field.SelectNodes("table_fields/table_field");
                            StringBuilder type_list = new StringBuilder();
                            StringBuilder field_name_list = new StringBuilder();
                            StringBuilder table_option_list = new StringBuilder();
                           bool is_first_field = true;
                            foreach (XmlNode table_field in table_fields)
                            {
                                if (is_first_field)
                                    is_first_field = false;
                                else
                                {
                                    field_name_list.Append(",");
                                    type_list.Append( ",");
                                }
                                XmlNode field_name_node = table_field.SelectSingleNode("name");
                                field_name_list.Append(field_name_node.InnerText );
                                XmlNode type_node = table_field.SelectSingleNode("type");
                                type_list.Append(type_node.InnerText );
                                XmlNode options_node = table_field.SelectSingleNode("options");
                                if (options_node != null)
                                    table_option_list.Append(options_node.InnerText + "|");
                            }
                            if (table_option_list.Length > 0)
                                table_option_list.Remove(table_option_list.Length - 1, 1);

                            string fields = table_type + "|" + type_list.ToString() + ":" + field_name_list.ToString();
                            HtmlAttribute fields_attr = htmlDoc.CreateAttribute("fields", fields);
                            new_node.Attributes.Append(fields_attr);

                            //there are 2 coding schemes here:
                            //1 css type coding
                            //2 xml type coding - the new one
                            //maintain backward comptibility
                            string table_submit = ";";
                            if (field_map.ContainsKey("submit"))
                            {
                                XmlNode submit_node = field.SelectSingleNode("submit");
                                if (submit_node.ChildNodes.Count > 1)
                                {
                                    StringBuilder sb_submit = new StringBuilder();
                                    sb_submit.Append(submit_node.LastChild.Name + ":");
                                    bool is_first = true;
                                    foreach (XmlNode submit_attribute in submit_node.LastChild.ChildNodes)
                                    {
                                        if (is_first)
                                            is_first = false;
                                        else
                                            sb_submit.Append(",");
                                        sb_submit.Append(submit_attribute.Name + "~" + submit_attribute.InnerText);
                                    }
                                    table_submit = sb_submit.ToString() + ";";
                                }
                                else
                                {
                                    table_submit = field_map["submit"].ToString() + ";";
                                    //bring to forward compatibility
                                    if (table_submit.StartsWith("post"))
                                    {
                                        if (table_submit.Length >= 19)
                                           // table_submit = table_submit.Remove(0, 19).Insert(0, "post:response_page~");
                                             table_submit = table_submit.Remove(0, 19).Insert(0, "post:");
                                    }
                                    else if (table_submit.Contains("next_page:"))
                                        table_submit = table_submit.Replace("next_page:", "next_page:page~");
                                    else if (table_submit.Contains("call:"))
                                        table_submit = table_submit.Replace("call:", "call:phone_field~");
                                }
                            }
                            if (field_map.ContainsKey("compute"))
                            {
                                string decode = DecodeComputeNode(field_map["compute"].ToString());
                                if (decode == null)
                                {
                                    return "Error: There may be an error in the compute field";
                                }
                                table_submit += "compute:" + decode + ";";
                            }

                            HtmlAttribute table_submit_attr = htmlDoc.CreateAttribute("submit", table_submit);
                            new_node.Attributes.Append(table_submit_attr);
                            if (table_option_list.Length > 0)
                            {
                                HtmlAttribute table_options = htmlDoc.CreateAttribute("options", EncodeStudioHtml(UnescapeXml(table_option_list.ToString())));
                                new_node.Attributes.Append(table_options);
                            }
                            break;
                        case "alert": //"<div title=\"MobiFlex Alert\" id=\"{0}\" style=\"z-index:{1};top:410px;left:270px;height:50px;width:50px;\"  ><img src=\"images/editor_images/alert.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Alert";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/alert.png");
                            break;
                        case "hidden_field": //"<div title=\"MobiFlex HiddenField\" id=\"{0}\" value=\"{1}\" style=\"position:absolute;z-index:{2};top:410px;left:0px;height:30px;width:30px;\"  ><img src=\"images/editor_images/hidden_field.png\" style=\"height:100%;width:100%;\"
                            title_attr.Value = "MobiFlex HiddenField";
                            if (!field_map.ContainsKey("value"))
                            {
                                HtmlAttribute hidden_value_attr = htmlDoc.CreateAttribute("value", "");
                                new_node.Attributes.Append(hidden_value_attr);
                            }
                            AddImageNode(htmlDoc, new_node, "images/editor_images/hidden_field.png");
                            break;
                        case "gps": //"<div title=\"MobiFlex GPS\" id=\"GPS\" alt=\"{0}\" style=\"z-index:{1};top:160px;left:10px;height:58px;width:56px;\"  ><img src=\"images/editor_images/gps.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex GPS";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/gps.png");
                            string latitude = field_map["latitude"].ToString();
                            string longitude = field_map["longitude"].ToString();
                            HtmlAttribute gps_attr = htmlDoc.CreateAttribute("alt", latitude + ";" + longitude);
                            new_node.Attributes.Append(gps_attr);
                            break;
                        case "map": //"<div title=\"MobiFlex Map\" alt=\"MobiFlex Map\" id=\"{0}\" style=\"position:absolute;z-index:{2};top:44px;left:0px;height:416px;width:320px;background-image:url('images/editor_images/map.jpg');background-repeat:no-repeat\"  url=\"{1}\" />"
                            title_attr.Value = "MobiFlex Map";
                            new_node.Attributes["style"].Value += "background-image:url('images/editor_images/map.jpg');background-repeat:no-repeat;";
                            break;
                        case "photo": //"<div title=\"MobiFlex Photo\" id=\"{0}\" compression=\"{1}\" icon_field=\"{2}\" style=\"z-index:{3};top:160px;left:10px;height:48px;width:48px;\"  ><img src=\"images/editor_images/picture_taker.gif\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex Photo";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/picture_taker.gif");
                            break;
                        case "audio_recorder": //"<div title=\"MobiFlex AudioRecorder\" id=\"{0}\" style=\"z-index:{1};top:160px;left:10px;height:84px;width:198px;\"  ><img src=\"images/editor_images/audio_recorder.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex AudioRecorder";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/audio_recorder.png");
                            break;
                        case "speech_recognition": // "<div title=\"MobiFlex SpeechRecognition\" alt=\"MobiFlex Speech Recognition\" id=\"{0}\" style=\"z-index:{2};top:48px;left:0px;height:412px;width:320px;\" choice_title=\"{1}\"  ><img src=\"images/editor_images/speech_recognition.png\" style=\"height:100%;width:100%;\"/></div>"
                            title_attr.Value = "MobiFlex SpeechRecognition";
                            AddImageNode(htmlDoc, new_node, "images/editor_images/speech_recognition.png");
                            break;

                    }
                    new_node.Attributes.Append(title_attr);

                    root.AppendChild(new_node);
                }
                catch (Exception ex)
                {
                    util.LogError(State, ex);
                    throw new Exception(ex.Message + ": " + ex.StackTrace);
                }
            }
            try
            {
                return htmlDoc.DocumentNode.WriteContentTo();
            }
            catch //work around bug in 3rd party package
            {
                return "";
            }
        }
        catch (Exception ex)
        {
            Util util = new Util();
            util.LogError(State, ex);
            throw new Exception(ex.Message + ": " + ex.StackTrace);
        }
    }
        private static void ProcessZoomImages(HtmlDocument doc)
        {
            var nodes = doc.DocumentNode.SelectNodes("//img[@_zoom]");

            if (nodes == null) return;
            foreach (var node in nodes)
            {
                var srcAttribute = node.Attributes["src"];
                if (srcAttribute == null || string.IsNullOrEmpty(srcAttribute.Value)) continue;

                var zoomAttribute = node.Attributes["_zoom"];
                if (zoomAttribute == null || string.IsNullOrEmpty(zoomAttribute.Value)) continue;

                var borderAttribute = node.Attributes["border"];
                if (borderAttribute == null)
                {
                    borderAttribute = doc.CreateAttribute("border");
                    node.Attributes.Append(borderAttribute);
                }
                borderAttribute.Value = "0";

                var imgSrc = srcAttribute.Value;

                if (!RxNumeric.IsMatch(zoomAttribute.Value))
                {
                    imgSrc = zoomAttribute.Value;
                }

                if (node.ParentNode != null)
                {
                    var hrefNode = doc.CreateElement("a");

                    var hrefAttribute = doc.CreateAttribute("href");
                    hrefAttribute.Value = imgSrc;
                    hrefNode.Attributes.Append(hrefAttribute);

                    hrefAttribute = doc.CreateAttribute("class");
                    hrefAttribute.Value = "screenzoom";
                    hrefNode.Attributes.Append(hrefAttribute);

                    /*
                    hrefAttribute = doc.CreateAttribute("onclick");
                                        hrefAttribute.Value = string.Format(@"javascript:if(typeof(popimgFckup) == 'function')popimgFckup('{0}');", srcAttribute.Value);
                                        hrefNode.Attributes.Append(hrefAttribute);*/


                    node.ParentNode.ReplaceChild(hrefNode, node);
                    hrefNode.AppendChild(node);
                }
            }
        }
    public void SetCommonHtmlAttributes(HtmlDocument htmlDoc, HtmlNode field_node, Hashtable field_map,  double x_size_factor ,  double y_size_factor , string field_type)
    {
        XmlUtil x_util = new XmlUtil();
        //init style
        HtmlAttribute style = htmlDoc.CreateAttribute("style", "position:absolute;");
        field_node.Attributes.Append(style);
        HtmlAttribute icon_field = null;
        int MinTextFieldHeight = 30;
        int MinButtonHeight = 30;

        //set default z-index
        if (!field_map.ContainsKey("z_index"))
            field_map["z_index"] = "50";
        if (field_type == "text_field" || field_type == "text_area" || field_type == "label" || field_type == "button")
        {
            if (!field_map.ContainsKey("font_style"))
                field_map["font_style"] = "normal";
            if (!field_map.ContainsKey("font_weight"))
                field_map["font_weight"] = "normal";
            if (!field_map.ContainsKey("text_decoration"))
                field_map["text_decoration"] = "none";
            /*if (field_type == "text_area")
            {
                //add 20 px to height and width of top node and then subtract 20 px for subnode of textarea later in SetTextHtmlAttributes
                field_map["height"] = Convert.ToInt32(field_map["height"].ToString()) + 20;
                field_map["width"] = Convert.ToInt32(field_map["width"].ToString()) + 20;
            }*/
        }
        //process buttons specially
        if (field_type == "button")
        {
            int height = Convert.ToInt32(field_map["height"].ToString());
           // int width = Convert.ToInt32(field_map["width"].ToString());
            //field_map["width"] = (width + 20).ToString();
            int top = Convert.ToInt32(field_map["top"].ToString());
            //int left = Convert.ToInt32(field_map["left"].ToString());
            //field_map["left"] = (left - 10).ToString();
            if (height < MinButtonHeight)
            {
                field_map["height"] = MinButtonHeight.ToString();
                top -= (MinButtonHeight - height) / 2;
                field_map["top"] = top.ToString();
            }
        }
        else if (field_type == "text_field")
        {
            int height = Convert.ToInt32(field_map["height"].ToString());
            int top = Convert.ToInt32(field_map["top"].ToString());
            if (height < MinTextFieldHeight)
            {
                field_map["height"] = MinTextFieldHeight.ToString();
                top -= (MinTextFieldHeight - height) / 2;
                field_map["top"] = top.ToString();
            }
        }

        foreach (string key in field_map.Keys)
        {
            switch (key)
            {
                case "icon_field":
                    if (field_node.Attributes["icon_field"] == null)
                    {
                        icon_field = htmlDoc.CreateAttribute("icon_field", "field:" + field_map[key].ToString() + ";");
                        field_node.Attributes.Append(icon_field);
                    }
                    else
                        field_node.Attributes["icon_field"].Value += "field:" + field_map[key].ToString() + ";";
                    break;
                case "icon_width":
                    if (field_node.Attributes["icon_field"] == null)
                    {
                        icon_field = htmlDoc.CreateAttribute("icon_field", "width:" + field_map[key].ToString() + ";");
                        field_node.Attributes.Append(icon_field);
                    }
                    else
                        field_node.Attributes["icon_field"].Value += "width:" + field_map[key].ToString() + ";";
                    break;
                case "icon_height":
                    if (field_node.Attributes["icon_field"] == null)
                    {
                        icon_field = htmlDoc.CreateAttribute("icon_field", "height:" + field_map[key].ToString() + ";");
                        field_node.Attributes.Append(icon_field);
                    }
                    else
                        field_node.Attributes["icon_field"].Value += "height:" + field_map[key].ToString() + ";";
                    break;
                case "url":
                case "alt":
                case "title":
                case "id":
                case "class":
                case "src":
                    HtmlAttribute attr = htmlDoc.CreateAttribute(key, field_map[key].ToString());
                    field_node.Attributes.Append(attr);
                    break;
                case "value":
                    HtmlAttribute val_attr = htmlDoc.CreateAttribute(key, HttpUtility.HtmlAttributeEncode(x_util.UnescapeXml(field_map[key].ToString())));
                    field_node.Attributes.Append(val_attr);
                    break;
                case "top":
                    int top = Convert.ToInt32(field_map[key].ToString());
                    if (y_size_factor == 1.0D)
                        field_node.Attributes["style"].Value += key + ":" + top.ToString() + "px;";
                    else
                    {
                        double y = Math.Round(Convert.ToDouble(top) * y_size_factor);
                        field_node.Attributes["style"].Value += key + ":" + y.ToString() + "px;";
                    }
                    break;
                case "left":
                    int left = Convert.ToInt32(field_map[key].ToString());
                    if (field_type == "text_field")
                    {
                        left += 5; //because there is border of 1 and padding of 4 added
                    }
                    if (x_size_factor == 1.0D)
                        field_node.Attributes["style"].Value += key + ":" + left.ToString() + "px;";
                    else
                    {
                        double x = Math.Round(Convert.ToDouble(left) * x_size_factor);
                        field_node.Attributes["style"].Value += key + ":" + x.ToString() + "px;";
                    }
                    break;
                case "height":
                    int height = Convert.ToInt32(field_map[key].ToString());
                    if (y_size_factor != 1.0D)
                    {
                        if (field_type == "image" || field_type == "image_button")
                        {
                            //maintain aspect ratios for images
                            height = Convert.ToInt32(Math.Round(Convert.ToDouble(height) * x_size_factor));
                        }
                        else
                        {
                            height = Convert.ToInt32(Math.Round(Convert.ToDouble(height) * y_size_factor));
                        }
                    }

                     field_node.Attributes["style"].Value += key + ":" + height.ToString() + "px;";
                     break;

                 case "width":
                    int width = Convert.ToInt32(field_map[key].ToString());
                    if (field_type == "text_field")
                    {
                        width -= 10; //because there is border of 1 and padding of 4 added
                    }
                    if (x_size_factor != 1.0D)
                    {
                         width = Convert.ToInt32(Math.Round(Convert.ToDouble(width) * x_size_factor));
                    }
                    if (field_type == "slider")
                    {
                        width = Math.Max(width, Convert.ToInt32(150 * x_size_factor));
                        field_node.Attributes["style"].Value += key + ":" + width.ToString() + "px;";
                    }
                    else
                        field_node.Attributes["style"].Value += key + ":" + width.ToString() + "px;";
                    break;
                 case "font_size":
                    int font_size = Convert.ToInt32(field_map[key].ToString());
                    if (y_size_factor != 1.0D)
                    {
                        font_size = Convert.ToInt32(Math.Round(Convert.ToDouble(font_size) * y_size_factor));
                    }
                    field_node.Attributes["style"].Value += key.Replace("_", "-") + ":" + font_size.ToString() + "px;";
                    break;
                 case "z_index":
                    int z_index = Math.Min(Convert.ToInt32(field_map[key].ToString()), 99);
                    field_node.Attributes["style"].Value += key.Replace("_", "-") + ":" + z_index.ToString() + ";";
                    break;
                case "color":
                case "font_style":
                case "font_weight":
                case "text_decoration":
                    field_node.Attributes["style"].Value += key.Replace("_", "-") + ":" + field_map[key].ToString() + ";";
                    break;
                case "font_family":
                    field_node.Attributes["style"].Value += key.Replace("_", "-") + ":" + field_map[key].ToString().ToLower().Replace("tahoma", "helvetica").Replace("verdana", "helvetica").Replace("calibri", "helvetica") + ";";
                    break;
            }
        }
    }
Exemple #12
0
        private HtmlNode MakeNode(HtmlDocument doc, string tag, string mainAttr, string mainValue, Dictionary<string, string> createAttributes)
        {
            // can't create a new node for a script where the value is its id
            if (mainAttr == "src" && Regex.IsMatch(mainValue.ToLower(), "^[a-z][a-z0-9_\\-]*$"))
                return null;

            HtmlNode newNode = doc.CreateElement(tag);
            if (mainValue.StartsWith("javascript:"))
                newNode.AppendChild(doc.CreateTextNode(mainValue.After("javascript:")));
            else
                newNode.Attributes.Add(doc.CreateAttribute(mainAttr, mainValue));
            foreach (KeyValuePair<string, string> kvp in createAttributes)
                newNode.Attributes.Add(doc.CreateAttribute(kvp.Key, kvp.Value));
            return newNode;
        }
Exemple #13
0
    public void SetCommonHtmlAttributes(HtmlDocument htmlDoc,  HtmlNode new_node, Hashtable field_map,double y_factor,string field_type)
    {
        //init style
        HtmlAttribute style = htmlDoc.CreateAttribute("style","position:absolute;");
        new_node.Attributes.Append(style);
        HtmlAttribute icon_field = null;

        //set default z-index
        if(!field_map.ContainsKey("z_index"))
            field_map["z_index"] = "50";
        if (field_type == "text_field" || field_type == "text_area" || field_type == "label" || field_type == "button")
        {
            if (!field_map.ContainsKey("font_style"))
                field_map["font_style"] = "normal";
            if (!field_map.ContainsKey("font_weight"))
                field_map["font_weight"] = "normal";
            if (!field_map.ContainsKey("text_decoration"))
                field_map["text_decoration"] = "none";
        }

        foreach (string key in field_map.Keys)
        {
            switch (key)
            {
                case "icon_field":
                    if (new_node.Attributes["icon_field"] == null)
                    {
                        icon_field = htmlDoc.CreateAttribute("icon_field", "field:" + field_map[key].ToString() + ";");
                        new_node.Attributes.Append(icon_field);
                    }
                    else
                        new_node.Attributes["icon_field"].Value += "field:" + field_map[key].ToString() + ";";
                    break;
                case "icon_width":
                    if (new_node.Attributes["icon_field"] == null)
                    {
                        icon_field = htmlDoc.CreateAttribute("icon_field", "width:" + field_map[key].ToString() + ";");
                        new_node.Attributes.Append(icon_field);
                    }
                    else
                         new_node.Attributes["icon_field"].Value += "width:" + field_map[key].ToString() + ";";
                    break;
                case "icon_height":
                    if (new_node.Attributes["icon_field"] == null)
                    {
                        icon_field = htmlDoc.CreateAttribute("icon_field", "height:" + field_map[key].ToString() + ";");
                        new_node.Attributes.Append(icon_field);
                    }
                    else
                         new_node.Attributes["icon_field"].Value += "height:" + field_map[key].ToString() + ";";
                    break;
                case "compression":
                case "url":
                case "alt":
                case "title":
                case "id":
                case "class":
                case "type":
                case "src":
                    HtmlAttribute attr = htmlDoc.CreateAttribute(key, field_map[key].ToString());
                    new_node.Attributes.Append(attr);
                    break;
                case "value":
                    HtmlAttribute val_attr = htmlDoc.CreateAttribute(key, EncodeStudioHtml(UnescapeXml(field_map[key].ToString())));
                    new_node.Attributes.Append(val_attr);
                    break;
                case "top":
                case "height":
                    if (y_factor == 1.0D)
                        new_node.Attributes["style"].Value += key + ":" + field_map[key].ToString() + "px;";
                    else
                    {
                        double y = Math.Round(Convert.ToDouble(field_map[key].ToString()) * y_factor);
                        new_node.Attributes["style"].Value += key + ":" + y.ToString() + "px;";
                    }
                    break;
                case "left":
                case "width":
                case "font_size":
                    new_node.Attributes["style"].Value +=  key.Replace("_", "-") + ":" + field_map[key].ToString() + "px;";
                    break;
                case "z_index":
                case "font_family":
                case "color":
                case "font_style":
                case "font_weight":
                case "text_decoration":
                case "background_color":
                case "overflow":
                    new_node.Attributes["style"].Value += key.Replace("_","-") + ":" + field_map[key].ToString() + ";";
                   break;
             }
        }
    }
Exemple #14
0
 private static void ProcessAscUserTag(HtmlDocument doc, Guid productID)
 {
     HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//div[@__ascuser]");
     HtmlAttribute styleAttr;
     if (nodes == null || nodes.Count == 0)
         return;
     foreach (HtmlNode node in nodes)
     {
         Guid userId = new Guid(node.Attributes["__ascuser"].Value);
         node.Attributes.RemoveAll();
         styleAttr = doc.CreateAttribute("style");
         styleAttr.Value = "display:inline;";
         node.Attributes.Append(styleAttr);
         node.InnerHtml = CoreContext.UserManager.GetUsers(userId).RenderProfileLinkBase(productID);
     }
 }
Exemple #15
0
        private void htmlElementToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            HtmlNode nd = ctl.node;

            Control[] control = ctl.Controls.Find("checkedListBox1", true);
            document.Load(Application.StartupPath + "/tempHtml.txt");
            CheckedListBox checkedListBox1 = (CheckedListBox)control[0];

            lock (checkedListBox1.CheckedItems)
            {
                foreach (var item in checkedListBox1.CheckedItems)
                {
                    string        displayname = item.ToString();
                    int           index       = checkedListBox1.FindStringExact(displayname);
                    string        name        = "textBox" + (index + 1).ToString();
                    Control[]     c           = checkedListBox1.Controls.Find(name, true);
                    TextBox       tb          = (TextBox)c[0];
                    HtmlAttribute attr        = document.CreateAttribute(displayname, tb.Text);
                    nd.Attributes.Add(attr);
                }
            }
            Control[] ctl1 = ctl.Controls.Find("innerHtmlTextBox", true);
            TextBox   tb1  = (TextBox)ctl1[0];

            Control[] ctl2 = ctl.Controls.Find("pathTextBox", true);
            TextBox   tb2  = (TextBox)ctl2[0];

            nd.InnerHtml = tb1.Text;
            XPathNavigator nav = document.DocumentNode.CreateRootNavigator();

            if (tb2.Text != string.Empty)
            {
                try
                {
                    var ob = (XPathNodeIterator)nav.Evaluate(tb2.Text);
                    if (ob.Count == 0)
                    {
                        MessageBox.Show("The path is not correct"); return;
                    }
                }

                catch (XPathException) { MessageBox.Show("The Path is Not Correct"); return; }
                HtmlNode node = document.DocumentNode.SelectSingleNode(tb2.Text);
                node.AppendChild(nd);
                document.Save(Application.StartupPath + "/tempHtml.txt");
            }
            else if (MessageBox.Show("Please Enter A Path") == DialogResult.OK)
            {
                tb2.Select();
            }
            richTextBox1.LoadFile(Application.StartupPath + "/tempHtml.txt", RichTextBoxStreamType.PlainText);
            toolStripStatusLabel1.Text = "Html Element <" + nd.Name + "> added";
            string filePath = Application.StartupPath;

            using (Document d = Document.FromString(richTextBox1.Text))
            {
                d.IndentBlockElements = AutoBool.Yes;
                d.IndentSpaces        = 2;
                d.AddTidyMetaElement  = false;
                d.CleanAndRepair();
                d.Save(filePath + "/tempHtml.txt");
            }
            document.LoadHtml(richTextBox1.Text);
            richTextBox1.Clear();
            richTextBox1.LoadFile(filePath + "/tempHtml.txt", RichTextBoxStreamType.PlainText);
        }
		/// <summary>
		/// Add the dimenssions of images to the Html ensuring that the images has max width of 960 pixels
		/// </summary>
		/// <param name="htmlDoc"></param>
		private void AddImageDimenssionsToHtml(HtmlDocument htmlDoc)
		{
			HtmlNodeCollection imgNodes = htmlDoc.DocumentNode.SelectNodes("//img[@src]");
			if (imgNodes == null)
			{
				return;
			}
			foreach (HtmlNode imgNode in imgNodes)
			{
				Image img;
				try
				{
					img = Image.FromFile(imgNode.Attributes["src"].Value);
				}
				catch (Exception)
				{
					Console.WriteLine("Error in AddImageDimenssionsToHtml: No image found at {0}", imgNode.Attributes["src"].Value);
					continue;
				}

				HtmlAttribute heightAttr = htmlDoc.CreateAttribute("height");
				HtmlAttribute widthAttr = htmlDoc.CreateAttribute("width");
				if (img.Width > MaxWidth)
				{
					heightAttr.Value = ((img.Height * MaxWidth) / (img.Width)).ToString(CultureInfo.CurrentCulture);
					widthAttr.Value = MaxWidth.ToString(CultureInfo.CurrentCulture);
				}
				else
				{
					heightAttr.Value = img.Height.ToString();
					widthAttr.Value = img.Width.ToString();
				}
				img.Dispose();

				imgNode.Attributes.Add(heightAttr);
				imgNode.Attributes.Add(widthAttr);
			}
		}
		/// <summary>
		/// Converts the MathML blocks to be readable by OneNote
		/// </summary>
		/// <param name="htmlDoc"></param>
		private void ConvertMathMl(HtmlDocument htmlDoc)
		{
			HtmlNodeCollection mathNodes = htmlDoc.DocumentNode.SelectNodes("//math");
			if (mathNodes == null)
			{
				return;
			}

			foreach (var mathNode in mathNodes.ToList())
			{
				mathNode.Attributes.RemoveAll();
				HtmlAttribute mathMlNamespaceAttr = htmlDoc.CreateAttribute("xmlns:mml", MathMlNameSpace);
				mathNode.Attributes.Add(mathMlNamespaceAttr);

				foreach (var node in mathNode.DescendantsAndSelf())
				{
					node.Name = "mml:" + node.Name;
				}

				string newMathMlString = String.Format(MathMlOutline, mathNode.OuterHtml);
				HtmlCommentNode newMathNode = htmlDoc.CreateComment(newMathMlString);
				mathNode.ParentNode.ReplaceChild(newMathNode, mathNode);
			}
		}
    public string GetWebApp(Hashtable State,XmlDocument xmlDoc, double x_size_factor,double y_size_factor )
    {
        try
        {
            XmlUtil x_util = new XmlUtil();
            Util util = new Util();
            DataSources DS = new DataSources();
            HtmlDocument htmlDoc = new HtmlDocument();

            //Load App Foundation
            StringBuilder NewWebAppHtml = new StringBuilder( HttpRuntime.Cache["NewWebAppHtml"].ToString());
            if (State["IsProduction"] == null)
                State["IsProduction"] = false;
            if ((bool)State["IsProduction"]== true)
            {
                string production_app_name = util.GetProductionAppName(State);
                NewWebAppHtml.Replace("CUSTOM_TITLE", production_app_name);
            }
            else
            {
                NewWebAppHtml.Replace("CUSTOM_TITLE", State["SelectedApp"].ToString());
            }

            /*if(false)
            {
                 NewWebAppHtml.Replace("ADDON_VIZIAPPS_SCRIPTS",  HttpRuntime.Cache["ShareThisScripts"].ToString());
            }
            else*/
                NewWebAppHtml.Replace("ADDON_VIZIAPPS_SCRIPTS", "");

                        //add custom header html
            NewWebAppHtml.Replace("CUSTOM_ACCOUNT_HEADER",util.GetCustomHeaderHTML(State));

            htmlDoc.LoadHtml(NewWebAppHtml.ToString());
            HtmlNode root = htmlDoc.DocumentNode;

            //Load Custom App Init
            StringBuilder customInitScript = new StringBuilder();
            string application_id = util.GetAppID(State);
            customInitScript.Append("var app_id = '" + application_id + "';\n");

            string app_time_stamp = null;
            if ((bool)State["IsProduction"] == false)
                app_time_stamp = util.GetStagingAppTimeStamp(State, application_id);
            else
                app_time_stamp = util.GetProductionAppTimeStamp(State, application_id);

            if (State["SelectedDeviceType"] == null)
                State["SelectedDeviceType"] = Constants.IPHONE;

            customInitScript.Append("\tvar app_time_stamp = '" + app_time_stamp + "';\n");
            customInitScript.Append("\tvar customer_id = '" + State["CustomerID"].ToString() + "';\n");
            customInitScript.Append("\tvar customer = '" + State["Username"].ToString() + "';\n");
            customInitScript.Append("\tvar app_name = '" + State["SelectedApp"].ToString() + "';\n");
            customInitScript.Append("\tvar design_device_type = '" + State["SelectedDeviceType"].ToString().ToLower() + "';\n");
            string viziapps_transition_type = null;
            if(State["PageTransitionType"] != null)
                viziapps_transition_type = State["PageTransitionType"].ToString();
            else
                 viziapps_transition_type ="slide";
            customInitScript.Append("\tvar viziapps_transition_type = '" + viziapps_transition_type + "';\n");

            switch (State["SelectedDeviceType"].ToString())
            {
                case Constants.IPHONE:
                case Constants.ANDROID_PHONE:
                default:
                    customInitScript.Append("\tvar ios_landscape_width_factor = " + Constants.IPHONE_LANDSCAPE_WIDTH_FACTOR + ";\n");
                    customInitScript.Append("\tvar ios_landscape_height_factor = " + Constants.IPHONE_LANDSCAPE_HEIGHT_FACTOR + ";\n");
                    customInitScript.Append("\tvar android_landscape_width_factor = " + Constants.ANDROID_PHONE_LANDSCAPE_WIDTH_FACTOR + ";\n");
                    customInitScript.Append("\tvar android_landscape_height_factor = " + Constants.ANDROID_PHONE_LANDSCAPE_HEIGHT_FACTOR + ";\n");
                    break;
                case Constants.ANDROID_TABLET:
                case Constants.IPAD:
                    customInitScript.Append("\tvar ios_landscape_width_factor = " + Constants.IPAD_LANDSCAPE_WIDTH_FACTOR + ";\n");
                    customInitScript.Append("\tvar ios_landscape_height_factor = " + Constants.IPAD_LANDSCAPE_HEIGHT_FACTOR + ";\n");
                    customInitScript.Append("\tvar android_landscape_width_factor = " + Constants.ANDROID_TABLET_LANDSCAPE_WIDTH_FACTOR + ";\n");
                    customInitScript.Append("\tvar android_landscape_height_factor = " + Constants.ANDROID_TABLET_LANDSCAPE_HEIGHT_FACTOR + ";\n");
                    break;
                }

            if((bool)State["IsProduction"])
                 customInitScript.Append("\tvar is_production = true;\n");
            else
                customInitScript.Append("\tvar is_production = false;\n");

            string device_type = x_util.GetAppDeviceType(State);
            if (device_type == Constants.IPAD || device_type == Constants.ANDROID_TABLET)
                customInitScript.Append("\tvar does_background_image_exist = false;\n");
            else
                customInitScript.Append("\tvar does_background_image_exist = true;\n");

            if (DS.DoesAppUseGoogleSpreadsheets(State))
            {
                customInitScript.Append("\tvar doesAppUseGoogleSpreadsheets = true;\n");
                customInitScript.Append("\tvar isGoogleDataLoaded = false;\n");
                customInitScript.Append("google.load('gdata', '2.x');\n");
                customInitScript.Append("google.setOnLoadCallback(onGoogleDataLoad);\n");
                customInitScript.Append("function onGoogleDataLoad() {isGoogleDataLoaded=true;}\n");
            }
            else
            {
                customInitScript.Append("\tvar doesAppUseGoogleSpreadsheets = false;\n");
                customInitScript.Append("\tvar isGoogleDataLoaded = false;\n");
            }

            customInitScript.Append("\tvar latitude;\n");
            customInitScript.Append("\tvar longitude;\n");

            //get app icon
            HtmlNode head_node = root.SelectSingleNode("//head");
            HtmlNode icon_node = htmlDoc.CreateElement("link");
            icon_node.Attributes.Append(htmlDoc.CreateAttribute("rel", "apple-touch-icon"));
            if (device_type == Constants.IPAD || device_type == Constants.ANDROID_TABLET)
            {
                if ((bool)State["IsProduction"] == false)
                {
                    icon_node.Attributes.Append(htmlDoc.CreateAttribute("href", "http://viziapps.s3-website-us-east-1.amazonaws.com/apps/viziapps_icon_ipad.png"));
                }
                else
                {
                    icon_node.Attributes.Append(htmlDoc.CreateAttribute("href", util.GetApplicationIcon(State, application_id, "72")));
                }
            }
            else
            {
                if ((bool)State["IsProduction"] == false)
                {
                    icon_node.Attributes.Append(htmlDoc.CreateAttribute("href", "http://viziapps.s3-website-us-east-1.amazonaws.com/apps/viziapps_icon.jpg"));
                }
                else
                {
                    icon_node.Attributes.Append(htmlDoc.CreateAttribute("href", util.GetApplicationIcon(State, application_id, "57")));
                }
            }

            head_node.AppendChild(icon_node);

            if (device_type == Constants.IPAD || device_type == Constants.ANDROID_TABLET)
            {
                HtmlNode ipad_splash_node = htmlDoc.CreateElement("link");
                ipad_splash_node.Attributes.Append(htmlDoc.CreateAttribute("rel", "apple-touch-startup-image"));
                ipad_splash_node.Attributes.Append(htmlDoc.CreateAttribute("media", "screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:landscape)"));
                if ((bool)State["IsProduction"] == false)
                {
                    ipad_splash_node.Attributes.Append(htmlDoc.CreateAttribute("href", "http://viziapps.s3-website-us-east-1.amazonaws.com/apps/viziapps_splash_ipad_landscape.jpg"));
                }
                else
                {
                    ipad_splash_node.Attributes.Append(htmlDoc.CreateAttribute("href", util.GetApplicationSplashImage(State, application_id)));
                }
                head_node.AppendChild(ipad_splash_node);

                HtmlNode ipad_splash_node2 = htmlDoc.CreateElement("link");
                ipad_splash_node2.Attributes.Append(htmlDoc.CreateAttribute("rel", "apple-touch-startup-image"));
                ipad_splash_node2.Attributes.Append(htmlDoc.CreateAttribute("media", "screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:portrait)"));
                if ((bool)State["IsProduction"] == false)
                {
                    ipad_splash_node2.Attributes.Append(htmlDoc.CreateAttribute("href", "http://viziapps.s3-website-us-east-1.amazonaws.com/apps/viziapps_splash_ipad_portrait.jpg"));
                }
                else
                {
                    ipad_splash_node2.Attributes.Append(htmlDoc.CreateAttribute("href", util.GetApplicationSplashImage(State, application_id)));
                }
                head_node.AppendChild(ipad_splash_node2);
            }
            else  //<link rel="apple-touch-startup-image" href="/startup.png">
            {
                HtmlNode splash_node = htmlDoc.CreateElement("link");
                splash_node.Attributes.Append(htmlDoc.CreateAttribute("rel", "apple-touch-startup-image"));
                if ((bool)State["IsProduction"] == false)
                {
                    splash_node.Attributes.Append(htmlDoc.CreateAttribute("href", "http://viziapps.s3-website-us-east-1.amazonaws.com/apps/viziapps_splash.jpg"));
                }
                else
                {
                    splash_node.Attributes.Append(htmlDoc.CreateAttribute("href", util.GetApplicationSplashImage(State, application_id)));
                }
                head_node.AppendChild(splash_node);
            }

            string backgroundUrl = null;
            if (device_type != Constants.IPAD)
            {
                //get background image
                XmlNode configuration_node = xmlDoc.SelectSingleNode("//configuration");
                XmlNode background_node = configuration_node.SelectSingleNode("background");
                if (background_node == null)
                {
                    background_node = x_util.CreateNode(xmlDoc, configuration_node, "background");
                }
                XmlNode background_image_node = background_node.SelectSingleNode("image_source");
                if (background_image_node == null)
                {
                    background_image_node = x_util.CreateNode(xmlDoc, background_node, "image_source", "https://s3.amazonaws.com/MobiFlexImages/apps/images/backgrounds/standard_w_header_iphone.jpg");
                }
                string background_image = background_image_node.InnerText;
                if (background_image.Contains("s3.amazonaws.com"))
                {
                    if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE)
                        background_image = background_image.Replace("_iphone.", "_android.");
                    backgroundUrl = background_image;
                }
                else
                {
                    background_image = background_image.Substring(background_image.LastIndexOf("/") + 1);
                    if (State["SelectedDeviceType"].ToString() == Constants.ANDROID_PHONE)
                        background_image = background_image.Replace("_iphone.", "_android.");

                    backgroundUrl = "https://s3.amazonaws.com/MobiFlexImages/apps/images/backgrounds/" + background_image;
                }
            }

            //Load App Pages
            XmlNodeList page_nodes = xmlDoc.SelectNodes("//pages/page");
            if (page_nodes == null)
                return "";

            //get first page
            XmlNode first_page_name_node = xmlDoc.SelectSingleNode("//pages/first_page_name");
            ArrayList page_node_list = new ArrayList();
            string first_page_name = "";
            if (first_page_name_node != null)
            {
                first_page_name = first_page_name_node.InnerText;
                foreach (XmlNode page_node in page_nodes)
                {
                    if (page_node.SelectSingleNode("name").InnerText == first_page_name)
                    {
                        page_node_list.Add(page_node);
                        break;
                    }
                }
            }

            foreach (XmlNode page_node in page_nodes)
            {
                if (page_node.SelectSingleNode("name").InnerText != first_page_name)
                {
                    page_node_list.Add(page_node);
                }
            }

            HtmlNode body_node = root.SelectSingleNode("//body");

            StringBuilder functions = new StringBuilder();

            if ((bool)State["IsProduction"] == false && State["SelectedAppType"].ToString() == Constants.HYBRID_APP_TYPE)
            {
                //add first function to go to login page
                StringBuilder settings_actions = new StringBuilder("$('#viziapps_login_button').bind('tap',function(event){\n");
                settings_actions.Append("\t\twindow.plugins.vsettings.login(null,null);\n");
                settings_actions.Append("\t\tevent.stopPropagation();\n");
                settings_actions.Append("\t});\n");
                functions.Append(settings_actions.ToString());
            }

            bool isFirstPage = true;
            foreach (XmlNode page_node in page_node_list)
            {
                ArrayList dialogs_in_page = new ArrayList();
                HtmlNode html_page_node = htmlDoc.CreateElement("div");
                html_page_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "page"));
                html_page_node.Attributes.Append(htmlDoc.CreateAttribute("id", page_node.SelectSingleNode("name").InnerText));
                if (device_type == Constants.IPAD || device_type == Constants.ANDROID_TABLET)
                    html_page_node.Attributes.Append(htmlDoc.CreateAttribute("style", "background-image: none; background-color:" + x_util.GetBackgroundColor(State)));

                HtmlNode content_node = htmlDoc.CreateElement("div");
                content_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "content"));
                content_node.Attributes.Append(htmlDoc.CreateAttribute("style", "background-image:none;background-color:transparent"));
                html_page_node.AppendChild(content_node);

                //create separate background image for phones
                if (device_type != Constants.IPAD)
                {
                    HtmlNode field_node = htmlDoc.CreateElement("div");
                    Size size = util.GetImageSize(backgroundUrl);
                    if (size != null)
                    {
                        double background_width = Convert.ToDouble(size.Width) * x_size_factor;
                        double background_height = Convert.ToDouble(size.Height) * y_size_factor;
                        field_node.Attributes.Append(htmlDoc.CreateAttribute("style", "z-index:1;position:absolute;left:0px;top:0px; width:" + background_width.ToString() + "px;height:" + background_height.ToString() + "px;"));
                    }

                    x_util.AddImageNode(htmlDoc, field_node, backgroundUrl);
                    content_node.AppendChild(field_node);
                }

                XmlNode fields_node = page_node.SelectSingleNode("fields");
                if (fields_node == null)
                    continue;

                XmlNodeList field_list = page_node.SelectSingleNode("fields").ChildNodes;
                foreach (XmlNode field in field_list)
                {
                    Hashtable field_map = x_util.ParseXmlToHtml(field);
                    HtmlNode field_node = null;
                    switch (field.Name)
                    {
                        case "text_field":
                        case "hidden_field":
                             field_node = htmlDoc.CreateElement("input");
                            break;
                        case "map":
                        case "photo":
                        case "gps":
                            continue;
                        case "alert":
                        case "button":
                        case "image_button":
                            field_node = htmlDoc.CreateElement("a");
                            break;
                        default:
                            field_node = htmlDoc.CreateElement("div");
                            break;
                    }

                   content_node.AppendChild(field_node);
                   field_node.Attributes.Append(htmlDoc.CreateAttribute("field_type", field.Name));
                   SetCommonHtmlAttributes(htmlDoc, field_node, field_map, x_size_factor, y_size_factor, field.Name);

                    switch (field.Name)
                    {
                        case "image":
                            string image_url = field_map["image_source"].ToString();
                            if (!field_map.ContainsKey("width")) //the xml does not have the width and height so use the width and height of the actual image
                            {
                                Size size = util.GetImageSize(image_url);
                                if (size != null)
                                {
                                    field_node.Attributes["style"].Value += "width:" + size.Width.ToString() + "px;height:" + size.Height.ToString() + "px;";
                                }
                            }
                            x_util.AddImageNode(htmlDoc, field_node, image_url);
                            break;
                        case "audio":
                            break;
                        case "label":
                            field_node.InnerHtml = field_map["text"].ToString();
                            field_node.Attributes["style"].Value += "text-shadow:none;";
                            break;
                        case "text_field":
                            field_node.Attributes["style"].Value += "background-color:#f0f0f0;text-shadow:none;padding:4px;margin:0px";
                            if (field_map["text"] != null)
                            {
                                HtmlAttribute text_field_value = htmlDoc.CreateAttribute("value");
                                text_field_value.Value = HttpUtility.HtmlAttributeEncode(field_map["text"].ToString());
                                field_node.Attributes.Append(text_field_value);
                            }
                            field_node.Attributes.Append(htmlDoc.CreateAttribute("type", field_map["type"].ToString()));
                            break;
                        case "text_area":
                            field_node.Attributes["style"].Value += "overflow-y: hidden;";
                            HtmlNode nav = htmlDoc.CreateElement("nav");
                            field_node.AppendChild(nav);
                            HtmlNode textarea = htmlDoc.CreateElement("textarea");
                            textarea.Attributes.Append(htmlDoc.CreateAttribute("data-role","none" ));
                            textarea.Attributes.Append(htmlDoc.CreateAttribute("style", "text-shadow:none;margin: 0px;padding: 7px 7px 7px 7px;border-color:#aaaaaa;"));
                            SetTextHtmlAttributes(textarea, field_map);
                            if (field_map["edit_type"] != null && field_map["edit_type"].ToString() == "non_editable")
                                textarea.Attributes.Append(htmlDoc.CreateAttribute("readonly", "readonly"));
                            textarea.InnerHtml = HttpUtility.HtmlEncode(field_map["text"].ToString().Replace("\\n", "\n"));
                            nav.AppendChild(textarea);
                             break;
                        case "image_button":
                            field_node.Attributes["style"].Value += "margin: 0 0 0 0;";
                             Hashtable imagebuttonAction = GetAction(field);
                            SetActions(page_node, field_map, imagebuttonAction, functions);
                            if (imagebuttonAction["next_page"] != null)
                                field_node.Attributes.Append(htmlDoc.CreateAttribute("href", "#" + imagebuttonAction["next_page"].ToString()));
                            else if (imagebuttonAction["previous_page"] != null)//do not use history function (commented code) because it does not work with embedded iframe. Use ChangePage instead
                            {
                                 field_node.Name = "div";
                            }
                            else
                                field_node.Attributes.Append(htmlDoc.CreateAttribute("href", "#"));

                            HtmlNode image_button_node = htmlDoc.CreateElement("img");
                            image_button_node.Attributes.Append(htmlDoc.CreateAttribute("src", field_map["image_source"].ToString()));
                            image_button_node.Attributes.Append(htmlDoc.CreateAttribute("width", "100%"));
                            image_button_node.Attributes.Append(htmlDoc.CreateAttribute("height", "100%"));
                            field_node.AppendChild(image_button_node);
                           break;
                        case "button":
                            field_node.Attributes["style"].Value += "margin: 0 0 0 0;";
                            Hashtable buttonAction = GetAction(field);
                            Boolean isActiveButton = true;
                            if (buttonAction["next_page"] != null)
                            {
                                field_node.Attributes.Append(htmlDoc.CreateAttribute("href", "#" + buttonAction["next_page"].ToString()));
                            }
                            else if (buttonAction["previous_page"] != null)//do not use history function (commented code) because it does not work with embedded iframe. Use ChangePage instead
                            {
                                field_node.Name = "div";
                            }
                            else
                            {
                                field_node.Name = "div";
                                isActiveButton = false;
                            }

                            if (isActiveButton)
                            {
                                field_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "button"));
                                field_node.Attributes.Append(htmlDoc.CreateAttribute("data-inline", "true"));
                                field_node.Attributes.Append(htmlDoc.CreateAttribute("data-transition", viziapps_transition_type));
                            }

                            //get the button theme
                            if (field_map["image_source"] != null)
                            {
                                string button_image_url = field_map["image_source"].ToString();
                                string theme = button_image_url.Substring(button_image_url.LastIndexOf("/") + 1);
                                if (theme == "a" || theme == "b" || theme == "c" || theme == "d" || theme == "e")
                                     field_node.Attributes.Append(htmlDoc.CreateAttribute("data-theme", theme));
                                else
                                    field_node.Attributes["style"].Value += "background-image:url(" + field_map["image_source"].ToString() + ");background-size:100% 100%;";
                            }
                            else
                            {
                                field_node.Attributes.Append(htmlDoc.CreateAttribute("data-theme", "b"));
                            }

                            SetActions(page_node, field_map, buttonAction, functions);
                            HtmlNode button_table_node = htmlDoc.CreateElement("table");
                            int height_start = field_node.Attributes["style"].Value.IndexOf("height:") + 7;
                            int height_end = field_node.Attributes["style"].Value.IndexOf("px", height_start);
                            button_table_node.Attributes.Append(htmlDoc.CreateAttribute("style", "width:100%;height:" +
                            field_node.Attributes["style"].Value.Substring(height_start, height_end - height_start) + "px"));
                            HtmlNode row_node = htmlDoc.CreateElement("tr");
                            HtmlNode column_node = htmlDoc.CreateElement("td");
                            column_node.InnerHtml = field_map["text"].ToString();
                            column_node.Attributes.Append(htmlDoc.CreateAttribute("style", "text-shadow:none;display:table-cell; vertical-align:middle;text-align:center"));
                            row_node.AppendChild(column_node);
                            button_table_node.AppendChild(row_node);
                            field_node.AppendChild(button_table_node);
                            break;
                        case "picker":
                            field_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "fieldcontain"));
                            field_node.Attributes["style"].Value += "height:25px;font-size:16px;margin: 0 0 0 0;padding: 0 0 0 0;";

                            HtmlNode select_node = htmlDoc.CreateElement("select");
                            select_node.Attributes.Append(htmlDoc.CreateAttribute("name", field_map["id"].ToString()));
                            select_node.Attributes.Append(htmlDoc.CreateAttribute("id", field_map["id"].ToString()));
                            select_node.Attributes.Append(htmlDoc.CreateAttribute("data-native-menu", "false"));
                            field_node.AppendChild(select_node);

                            string picker_type = field_map["picker_type"].ToString();
                            if (picker_type.Contains("section"))
                            {
                                XmlNodeList picker_fields = field.SelectNodes("picker_fields/picker_field");
                                StringBuilder option_list = new StringBuilder();
                                foreach (XmlNode picker_field in picker_fields) //this code does not process multiple fields yet
                                {
                                    XmlNode name_node = picker_field.SelectSingleNode("name");
                                    XmlNode options_node = picker_field.SelectSingleNode("options");
                                    if (options_node != null)
                                    {
                                        string option_string = options_node.InnerText;
                                        string[] picker_option_list = option_string.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                        foreach (string option in picker_option_list)
                                        {
                                            HtmlNode option_node = htmlDoc.CreateElement("option");
                                            option_node.Attributes.Append(htmlDoc.CreateAttribute("value", option));
                                            option_node.InnerHtml = option;
                                            select_node.AppendChild(option_node);
                                        }
                                    }
                                }
                            }
                            break;
                        case "switch":
                            field_node.Attributes["style"].Value += "margin: 0 0 0 0;";
                            Hashtable switchAction = GetAction(field);
                            SetActions(page_node, field_map, switchAction, functions);
                            string default_switch_value = field_map["default_value"].ToString();

                            field_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "fieldcontain"));

                            HtmlNode switch_node = htmlDoc.CreateElement("select");
                            switch_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "slider"));
                            HtmlNode option_off = htmlDoc.CreateElement("option");
                            option_off.Attributes.Append(htmlDoc.CreateAttribute("value", "off"));
                            HtmlNode option_on = htmlDoc.CreateElement("option");
                            option_on.Attributes.Append(htmlDoc.CreateAttribute("value", "on"));
                            switch_node.AppendChild(option_off);
                            switch_node.AppendChild(option_on);

                            if (field_map["type"] == null)
                                field_map["type"] = "on_off";

                            switch (field_map["type"].ToString())
                            {
                                case "on_off":
                                    option_off.InnerHtml = "Off";
                                    option_on.InnerHtml = "On";
                                    if (default_switch_value == "on")
                                        option_on.Attributes.Append(htmlDoc.CreateAttribute("selected", "selected"));
                                    else
                                        option_off.Attributes.Append(htmlDoc.CreateAttribute("selected", "selected"));
                                    break;
                                case "true_false":
                                    option_off.InnerHtml = "False";
                                    option_on.InnerHtml = "True";
                                    if (default_switch_value == "true")
                                        option_on.Attributes.Append(htmlDoc.CreateAttribute("selected", "selected"));
                                    else
                                        option_off.Attributes.Append(htmlDoc.CreateAttribute("selected", "selected"));
                                    break;
                                case "yes_no":
                                    option_off.InnerHtml = "No";
                                    option_on.InnerHtml = "Yes";
                                    if (default_switch_value == "yes")
                                        option_on.Attributes.Append(htmlDoc.CreateAttribute("selected", "selected"));
                                    else
                                        option_off.Attributes.Append(htmlDoc.CreateAttribute("selected", "selected"));
                                    break;
                            }
                            field_node.AppendChild(switch_node);

                            break;
                        case "checkbox":
                            field_node.Attributes["style"].Value += "margin: 0 0 0 0;";
                            Hashtable checkboxAction = GetAction(field);
                            SetActions(page_node, field_map, checkboxAction, functions);
                            HtmlNode checkbox_node = htmlDoc.CreateElement("input");
                            checkbox_node.Attributes.Append(htmlDoc.CreateAttribute("type", "checkbox"));
                            checkbox_node.Attributes.Append(htmlDoc.CreateAttribute("class", "custom"));
                            checkbox_node.Attributes.Append(htmlDoc.CreateAttribute("name", field_map["id"].ToString() + "_0"));
                            checkbox_node.Attributes.Append(htmlDoc.CreateAttribute("id", field_map["id"].ToString() + "_0"));
                            string default_value = field_map["default_value"].ToString();
                            if (default_value == "checked")
                                checkbox_node.Attributes.Append(htmlDoc.CreateAttribute("checked", "checked"));
                            field_node.AppendChild(checkbox_node);
                            HtmlNode checkbox_label_node = htmlDoc.CreateElement("label");
                            checkbox_label_node.InnerHtml = "&nbsp;";
                            checkbox_label_node.Attributes.Append(htmlDoc.CreateAttribute("for", field_map["id"].ToString() + "_0"));
                            field_node.AppendChild(checkbox_label_node);
                            break;
                        case "slider":
                            HtmlNode slider_node = htmlDoc.CreateElement("input");
                            slider_node.Attributes.Append(htmlDoc.CreateAttribute("name", field_map["id"].ToString()));
                            slider_node.Attributes.Append(htmlDoc.CreateAttribute("type", "range"));
                            slider_node.Attributes.Append(htmlDoc.CreateAttribute("min", field_map["min_value"].ToString()));
                            slider_node.Attributes.Append(htmlDoc.CreateAttribute("max", field_map["max_value"].ToString()));
                            double slider_value = (Convert.ToDouble(field_map["min_value"].ToString()) + Convert.ToDouble(field_map["max_value"].ToString())) / 2.0;
                            slider_node.Attributes.Append(htmlDoc.CreateAttribute("value", slider_value.ToString()));
                            slider_node.Attributes.Append(htmlDoc.CreateAttribute("data-theme", "b"));
                            slider_node.Attributes.Append(htmlDoc.CreateAttribute("data-track-theme", "c"));
                            field_node.AppendChild(slider_node);
                            break;
                        case "table":
                            HtmlNode table_nav_node = htmlDoc.CreateElement("nav");
                            HtmlNode table_node = htmlDoc.CreateElement("ul");
                            table_nav_node.AppendChild(table_node);
                            field_node.AppendChild(table_nav_node);
                            Hashtable tableActions = GetAction(field);
                            table_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "listview"));
                            table_node.Attributes.Append(htmlDoc.CreateAttribute("data-inset", "true"));
                            table_node.Attributes.Append(htmlDoc.CreateAttribute("data-theme", "d"));
                            HtmlNode header = htmlDoc.CreateElement("li");
                            header.Attributes.Append(htmlDoc.CreateAttribute("data-role", "list-divider"));
                            if (field_map["display_name"] == null)
                                header.InnerHtml = field_map["id"].ToString();
                            else
                                header.InnerHtml = field_map["display_name"].ToString();
                            table_node.AppendChild(header);

                            XmlNodeList table_fields = field.SelectNodes("table_fields/table_field");
                            StringBuilder table_option_list = new StringBuilder();
                            ArrayList rows = new ArrayList();
                            int field_index = 0;
                            string[] field_types = new string[table_fields.Count];
                            string[] field_name_list = new string[table_fields.Count];
                            string[,] table = null;
                            int n_rows = 0;
                            int n_cols = 0;
                            string hidden_field_name = null;
                            foreach (XmlNode table_field in table_fields)
                            {
                                XmlNode field_name_node = table_field.SelectSingleNode("name");
                                field_name_list[field_index] = field_name_node.InnerText;
                                XmlNode type_node = table_field.SelectSingleNode("type");
                                field_types[field_index] = type_node.InnerText;
                                if (type_node.InnerText == "hidden")
                                    hidden_field_name = field_name_list[field_index];
                                XmlNode options_node = table_field.SelectSingleNode("options");
                                if (options_node != null)
                                {
                                    string option_string = options_node.InnerText;
                                    string[] option_list = option_string.Split(";".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                    int row_index = 0;

                                    foreach (string option in option_list)
                                    {
                                        if (table == null) //the first array of options sets the number of rows
                                        {
                                            n_rows = option_list.Length;
                                            n_cols = table_fields.Count;
                                            table = new string[n_rows, n_cols];
                                        }
                                        if (row_index >= n_rows)
                                            return "Error: Field " + field_name_list[field_index] + " has more than the " + n_rows.ToString() + " rows in field " + field_name_list[0];
                                        table[row_index, field_index] = option;
                                        row_index++;
                                    }
                                }
                                else //when there are no preloaded lists create 1 row as a template for the others to come
                                {
                                    if (table == null)
                                    {
                                        n_rows = 1;
                                        n_cols = table_fields.Count;
                                        table = new string[n_rows, n_cols];
                                    }
                                    table[0, field_index] = "";

                                }
                                field_index++;
                            }

                            SetTableRowActions(page_node, field_map["id"].ToString(), field_map, tableActions, functions);

                            //selected how row will appear
                            string row_html = null;
                            switch (field_map["table_type"].ToString())
                            {
                                case "1text":
                                    row_html = Constants.one_text;
                                    break;
                                case "1texthidden":
                                    row_html = Constants.one_text_hidden;
                                    break;
                                case "2texts":
                                    row_html = Constants.two_texts;
                                    break;
                                case "2textshidden":
                                    row_html = Constants.two_texts_hidden;
                                    break;
                                case "image1text":
                                    row_html = Constants.image_1text;
                                    break;
                                case "image1texthidden":
                                    row_html = Constants.image_1text_hidden;
                                    break;
                                case "image2texts":
                                    row_html = Constants.image_2texts;
                                    break;
                                case "image2textshidden":
                                    row_html = Constants.image_2texts_hidden;
                                    break;
                            }
                            for (int r = 0; r < n_rows; r++)
                            {
                                HtmlNode row = htmlDoc.CreateElement("li");
                                row.Attributes.Append(htmlDoc.CreateAttribute("data-icon", "arrow-r"));
                                string id = field_map["id"].ToString() + "_" + r.ToString();
                                row.Attributes.Append(htmlDoc.CreateAttribute("id", id));
                                HtmlNode a = htmlDoc.CreateElement("a");
                                a.Attributes.Append(htmlDoc.CreateAttribute("data-transition", viziapps_transition_type));
                                if (tableActions["next_page"] != null)
                                {
                                    a.Attributes.Append(htmlDoc.CreateAttribute("href", "#" + tableActions["next_page"].ToString()));
                                }
                                else
                                    a.Attributes.Append(htmlDoc.CreateAttribute("href", "#"));

                                a.Attributes.Append(htmlDoc.CreateAttribute("style", "padding:0;width:100%"));
                                a.InnerHtml = row_html;
                                HtmlNode a_table = a.SelectSingleNode("table");
                                a_table.Attributes["style"].Value = "width:" + (Convert.ToInt16(field_map["width"].ToString())).ToString() + "px";
                                field_index = 0;
                                for (int c = 0; c < n_cols; c++)
                                {
                                    if (table[r, c] != null)
                                    {
                                        switch (field_types[field_index])
                                        {
                                            case "image":
                                                HtmlNode td_img = a.SelectSingleNode("table/tr/td");
                                                td_img.Attributes["name"].Value = field_name_list[field_index];
                                                HtmlNode img = td_img.SelectSingleNode("img");
                                                img.Attributes["src"].Value =  table[r, c];
                                                break;
                                            case "text":
                                                HtmlNode td  = null;
                                                int td_width_adjust = 30;
                                                switch (field_map["table_type"].ToString())
                                                {
                                                    case "1texthidden":
                                                    case "1text":
                                                        td = a.SelectSingleNode("table/tr/td");
                                                        break;
                                                    case "2textshidden":
                                                    case "2texts":
                                                        if (c == 0)
                                                            td = a.SelectSingleNode("table/tr/td");
                                                        else
                                                        {
                                                            td = a.SelectSingleNode("table/tr").NextSibling;
                                                            td = td.SelectSingleNode("td");
                                                        }
                                                        break;
                                                    case "image1texthidden":
                                                    case "image1text":
                                                        td = a.SelectSingleNode("table/tr/td").NextSibling;
                                                        td_width_adjust = 120;
                                                        break;
                                                    case "image2textshidden":
                                                    case "image2texts":
                                                        td_width_adjust = 120;
                                                        if (c == 1)
                                                            td = a.SelectSingleNode("table/tr/td").NextSibling;
                                                        else
                                                        {
                                                            td = a.SelectSingleNode("table/tr").NextSibling;
                                                            td = td.SelectSingleNode("td");
                                                        }
                                                        break;
                                                }

                                                td.Attributes["name"].Value =  field_name_list[field_index];
                                                HtmlNode td_div = td.SelectSingleNode("div");
                                                td_div.Attributes.Append(htmlDoc.CreateAttribute("style", "width:" + (Convert.ToInt16(field_map["width"].ToString()) - td_width_adjust).ToString() + "px"));
                                                td_div.InnerHtml = table[r, c];
                                                break;
                                            case "hidden":
                                                HtmlNode hidden = a.SelectSingleNode("table").NextSibling;
                                                hidden.Attributes["name"].Value = field_name_list[field_index];
                                                hidden.Attributes["value"].Value = table[r, c];
                                                break;
                                        }
                                    }
                                    field_index++;
                                }
                                row.AppendChild(a);
                                table_node.AppendChild(row);
                            }

                            break;
                        case "alert":
                            //<a href="foo.html" data-rel="dialog">Open dialog</a>
                            field_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "button"));
                            field_node.Attributes.Append(htmlDoc.CreateAttribute("data-rel", "dialog"));
                            field_node.Attributes.Append(htmlDoc.CreateAttribute("data-transition", "pop"));
                            field_node.Attributes.Append(htmlDoc.CreateAttribute("href", "#"+field_map["id"].ToString() + "_page"));
                            field_node.Attributes["style"].Value += "display:none";

                            HtmlNode alert_page_node = htmlDoc.CreateElement("div");
                            alert_page_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "page"));
                            alert_page_node.Attributes.Append(htmlDoc.CreateAttribute("field_type", "alert"));
                            alert_page_node.Attributes.Append(htmlDoc.CreateAttribute("id", field_map["id"].ToString() + "_page"));

                            HtmlNode alert_header = htmlDoc.CreateElement("div");
                            alert_header.Attributes.Append(htmlDoc.CreateAttribute("data-role", "header"));
                            alert_header.Attributes.Append(htmlDoc.CreateAttribute("data-theme", "d"));

                            HtmlNode alert_title = htmlDoc.CreateElement("h1");
                            alert_title.Attributes.Append(htmlDoc.CreateAttribute("id", field_map["id"].ToString() + "_title"));
                            alert_title.InnerHtml = "Alert";
                            alert_header.AppendChild(alert_title);

                            alert_page_node.AppendChild(alert_header);

                            HtmlNode alert_content_node = htmlDoc.CreateElement("div");
                            alert_content_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "content"));
                            alert_content_node.Attributes.Append(htmlDoc.CreateAttribute("data-theme", "c"));

                            HtmlNode dialog_message = htmlDoc.CreateElement("p");
                            dialog_message.Attributes.Append(htmlDoc.CreateAttribute("id", field_map["id"].ToString() + "_message"));
                            dialog_message.InnerHtml = "Message";
                            alert_content_node.AppendChild(dialog_message);

                            alert_page_node.AppendChild(alert_content_node);

                            dialogs_in_page.Add(alert_page_node);
                            break;
                        case "hidden_field":
                            field_node.Attributes.Append(htmlDoc.CreateAttribute("type", "hidden"));
                            break;
                        case "html_panel":
                            field_node.Attributes.Append(htmlDoc.CreateAttribute("data-role", "none"));
                            field_node.Attributes["style"].Value += "margin: 0 0 0 0;overflow-x:auto;overflow-y:hidden;background-color:#ffffff;";
                            HtmlNode panel_nav = htmlDoc.CreateElement("nav");
                            field_node.AppendChild(panel_nav);
                            HtmlNode container_node = htmlDoc.CreateElement("div");
                            container_node.Attributes.Append(htmlDoc.CreateAttribute("style", "width:100%;height:100%;"));
                            container_node.InnerHtml = HttpUtility.HtmlDecode(field_map["html"].ToString());
                            panel_nav.AppendChild(container_node);
                            break;
                        case "web_view":
                            field_node.Attributes["style"].Value += "margin: 0 0 0 0;overflow-x:scroll;overflow-y:scroll";
                            HtmlNode iframe_node = htmlDoc.CreateElement("iframe");
                            field_node.AppendChild(iframe_node);
                            if(field_map["url"] == null)
                                iframe_node.Attributes.Append(htmlDoc.CreateAttribute("src",""));
                            else
                                 iframe_node.Attributes.Append(htmlDoc.CreateAttribute("src", field_map["url"].ToString()));
                            iframe_node.Attributes.Append(htmlDoc.CreateAttribute("width", "100%"));
                            iframe_node.Attributes.Append(htmlDoc.CreateAttribute("height", "100%"));
                            iframe_node.Attributes.Append(htmlDoc.CreateAttribute("style", "border-width:0;overflow-x:scroll;overflow-y:scroll"));
                            break;
                        case "gps":
                            break;
                        case "photo":
                            break;
                    }
                }

                if(isFirstPage){
                    isFirstPage = false;
                    if ((bool)State["IsProduction"] == false &&  State["SelectedAppType"].ToString() == Constants.HYBRID_APP_TYPE)
                    {
                        //add login button
                        HtmlNode login_button_node = htmlDoc.CreateElement("div");
                        int settings_button_left = 280;
                        int settings_button_top = 5;
                        int settings_button_height = 32;
                        if (x_size_factor != 1.0D)
                        {
                            settings_button_left = Convert.ToInt16(292.0D * x_size_factor);
                            settings_button_top = Convert.ToInt16(3.0D * y_size_factor);
                            settings_button_height = Convert.ToInt16(22.0D * y_size_factor);
                        }
                        login_button_node.Attributes.Append(htmlDoc.CreateAttribute("style", "position:absolute;height:" + settings_button_height.ToString() + "px;left:" + settings_button_left.ToString() + "px;top:" + settings_button_top.ToString() + "px;z-index:50000;width:" + settings_button_height.ToString() + "px;"));
                        login_button_node.Attributes.Append(htmlDoc.CreateAttribute("id", "viziapps_login_button"));
                        HtmlNode image_button_node = htmlDoc.CreateElement("img");
                        image_button_node.Attributes.Append(htmlDoc.CreateAttribute("src", "http://viziapps.s3-website-us-east-1.amazonaws.com/apps/viziapps_settings_button.png"));
                        image_button_node.Attributes.Append(htmlDoc.CreateAttribute("width", "100%"));
                        image_button_node.Attributes.Append(htmlDoc.CreateAttribute("height", "100%"));
                        login_button_node.AppendChild(image_button_node);
                        content_node.AppendChild(login_button_node);
                    }
                }
                body_node.AppendChild(html_page_node);
                if (dialogs_in_page.Count > 0)
                {
                    foreach (HtmlNode dialog_node in dialogs_in_page)
                    {
                        body_node.AppendChild(dialog_node);
                    }
                }

                //Set data source operations
                XmlNode data_sources = page_node.SelectSingleNode("data_sources");
                if (data_sources == null)
                    continue;

                XmlNodeList data_source_list = data_sources.SelectNodes("data_source");
                int data_source_index = 0;
                string page_name = page_node.SelectSingleNode("name").InnerText;
                foreach (XmlNode data_source in data_source_list)
                {
                    //get data source type
                    XmlNode data_source_id = data_source.SelectSingleNode("data_source_id");
                    XmlNode app_data_source_id = xmlDoc.SelectSingleNode("//application/data_sources/data_source/data_source_id[.='" + data_source_id.InnerText + "']");
                    if (app_data_source_id != null)
                    {
                        XmlNode data_source_type = app_data_source_id.ParentNode.SelectSingleNode("data_source_type");
                        string connection_string = app_data_source_id.ParentNode.SelectSingleNode("data_source_configuration/connection_string").InnerText;
                        if (data_source_type.InnerText == "google_spreadsheet")
                        {
                            XmlNode event_node = data_source.SelectSingleNode("event");
                            if (event_node == null)
                                continue;
                            XmlNode data_source_event_type = event_node.SelectSingleNode("data_source_event_type");
                            string sql_command_list_name = "data_source_operations_" + page_name + "_" + data_source_index.ToString();
                            if (data_source_event_type.InnerText == "page")
                            {
                                XmlNodeList sql_command_list = event_node.SelectNodes("data_source_operations/sql_commands/sql_command");
                                customInitScript.Append(SetDataSourceSqlCommands(xmlDoc, page_name, data_source_index, sql_command_list));

                                StringBuilder spreadsheet_actions = new StringBuilder();
                                if (page_name == first_page_name) //this binds to before the first page is shown
                                {
                                    spreadsheet_actions.Append("$(window).load(function() {\n");
                                    spreadsheet_actions.Append("\tdoGoogleDocsInterface(\"" + connection_string + "\"," + sql_command_list_name + ");\n");
                                    spreadsheet_actions.Append("});\n");
                                    functions.Append(spreadsheet_actions.ToString());
                                }

                                //this bind to before the page is shown after first time
                                else
                                {
                                    spreadsheet_actions.Append("$('#" + page_name + "').live('pagebeforeshow', function (event, ui) {\n");
                                    spreadsheet_actions.Append("\tdoGoogleDocsInterface(\"" + connection_string + "\"," + sql_command_list_name + ");\n");
                                    spreadsheet_actions.Append("});\n");
                                    functions.Append(spreadsheet_actions.ToString());
                                }
                            }
                            else if (data_source_event_type.InnerText == "field")
                            {
                                XmlNode data_source_event_field = event_node.SelectSingleNode("data_source_event_field");
                                XmlNodeList sql_command_list = event_node.SelectNodes("data_source_operations/sql_commands/sql_command");
                                customInitScript.Append(SetDataSourceSqlCommands(xmlDoc, page_name, data_source_index, sql_command_list));

                                StringBuilder spreadsheet_actions = new StringBuilder("\t$('#" + data_source_event_field.InnerText + "').bind('tap',function(event){\n");
                                spreadsheet_actions.Append("\tdoGoogleDocsInterface(\"" + connection_string + "\"," + sql_command_list_name + ");\n");
                                spreadsheet_actions.Append("\tevent.stopPropagation();\n");
                                spreadsheet_actions.Append("});\n");

                                functions.Append(spreadsheet_actions.ToString());
                            }
                        }
                    }
                    data_source_index++;
                }
            }

            //insert all custom scripts
            HtmlNodeCollection script_nodes = root.SelectNodes("//script");
            foreach (HtmlNode script_node in script_nodes)
            {
                if (script_node.InnerText.Contains("CUSTOM_VIZIAPPS_INIT"))
                {
                    script_node.InnerHtml = script_node.InnerHtml.Replace("CUSTOM_VIZIAPPS_INIT", customInitScript.ToString());
                }
                else if (script_node.InnerText.Contains("CUSTOM_VIZIAPPS_FUNCTIONS"))
                {
                    script_node.InnerHtml = script_node.InnerHtml.Replace("CUSTOM_VIZIAPPS_FUNCTIONS", functions.ToString());
                }
            }

            return htmlDoc.DocumentNode.WriteContentTo();
        }
        catch (Exception ex)
        {
            Util util = new Util();
            util.LogError(State, ex);
            throw new Exception(ex.Message + ": " + ex.StackTrace);
        }
    }
Exemple #19
0
        /// <summary>
        /// Creates XML string from instance of module
        /// </summary>
        /// <param name="module">Module</param>
        /// <returns>XML Node of module</returns>
        public HtmlNode GetNodeFromModule(AModule module)
        {
            Type moduleType = module.GetType();
            Type setupType = module.setup.GetType();

            // Create root node
            String moduleName = (String)moduleType.GetField("name", BindingFlags.Static | BindingFlags.Public | BindingFlags.FlattenHierarchy).GetValue(null);

            HtmlDocument htmlDoc = new HtmlDocument();
            HtmlNode node = htmlDoc.CreateElement("module");

            // Save all setup_* members to attributes
            MemberInfo[] setupMembers = setupType.GetMember("setup_*", BindingFlags.Public | BindingFlags.Instance);
            foreach (MemberInfo setupMember in setupMembers)
            {
                HtmlAttribute attribute = htmlDoc.CreateAttribute(setupMember.Name);
                attribute.Value = (String)setupType.InvokeMember(setupMember.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty, null, module.setup, null);
                node.Attributes.Append(attribute);
            }

            // Save name(type) of module
            HtmlAttribute nameAttr = htmlDoc.CreateAttribute("name");
            nameAttr.Value = moduleName;
            node.Attributes.Append(nameAttr);

            // Save position as attr
            Rectangle location = (Rectangle)setupType.GetField("location", BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy).GetValue(module.setup);
            HtmlAttribute locationAttr = htmlDoc.CreateAttribute("location");
            RectangleConverter converter = new RectangleConverter();
            locationAttr.Value = converter.ConvertToString(location);
            node.Attributes.Append(locationAttr);

            return node;
        }