private CssParser GetParserFormXML(XmlDocument xmlFile, string currentCSSFile)
        {
            CssParser parser = new CssParser();
            StringBuilder style = new StringBuilder();

            //FormatXML(xmlFile);

            foreach (XmlNode node in xmlFile.FirstChild.ChildNodes)
            {
                foreach (XmlNode chNode in node.ChildNodes)
                {
                    if (chNode.Name == "MinHeaderHeight")
                    {
                        style.AppendFormat("{0}{{{1}:{2};}} ", chNode.Attributes["element"].Value, chNode.Attributes["attribute"].Value, chNode.InnerText + "px");
                    }
                    else
                    {
                        style.AppendFormat("{0}{{{1}:{2};}} ", chNode.Attributes["element"].Value, chNode.Attributes["attribute"].Value, chNode.InnerText);
                    }
                }
            }

            Directory.CreateDirectory(Server.MapPath("~/temp/"));
            TextWriter sw = System.IO.File.CreateText(Server.MapPath("~/temp/site.css"));
            sw.Write(style.ToString());
            sw.Close();
            parser.AddStyleSheet(currentCSSFile);
            parser.AddStyleSheet(Server.MapPath("~/temp/site.css"));
            System.IO.File.Delete(Server.MapPath("~/temp/site.css"));
            return parser;
        }
        private void GetGradientColors(CssParser parser, ref string portletColor1, ref string portletColor2, ref string buttonColor1, ref string buttonColor2)
        {
            if (string.IsNullOrEmpty(portletColor1))
            {
                if (parser.Styles.ContainsKey(".portlet"))
                {
                    if (parser.Styles[".portlet"].Attributes.ContainsKey("background"))
                    {
                        portletColor1 = parser.Styles[".portlet"].Attributes["background"].Split(new char[] { ' ', ',', ')', '(' }).Where(a => a.StartsWith("#")).FirstOrDefault();
                    }
                    else
                    {
                        if (parser.Styles[".portlet"].Attributes.ContainsKey("background-color"))
                        {
                            portletColor1 = parser.Styles[".portlet"].Attributes["background-color"].Split(new char[] { ' ', ',', ')', '(' }).Where(a => a.StartsWith("#")).FirstOrDefault();
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(portletColor2))
            {
                if (parser.Styles.ContainsKey(".portlet"))
                {
                    if (parser.Styles[".portlet"].Attributes.ContainsKey("background"))
                    {
                        portletColor1 = parser.Styles[".portlet"].Attributes["background"].Split(new char[] { ' ', ',', ')', '(' }).Where(a => a.StartsWith("#")).LastOrDefault();
                    }
                    else
                    {
                        if (parser.Styles[".portlet"].Attributes.ContainsKey("background-color"))
                        {
                            portletColor1 = parser.Styles[".portlet"].Attributes["background-color"].Split(new char[] { ' ', ',', ')', '(' }).Where(a => a.StartsWith("#")).LastOrDefault();
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(buttonColor1))
            {
                if (parser.Styles.ContainsKey(".CSSButton"))
                {
                    if (parser.Styles[".CSSButton"].Attributes.ContainsKey("background"))
                    {
                        buttonColor1 = parser.Styles[".CSSButton"].Attributes["background"].Split(new char[] { ' ', ',', ')', '(' }).Where(a => a.StartsWith("#")).FirstOrDefault();
                    }
                    else
                    {
                        if (parser.Styles[".CSSButton"].Attributes.ContainsKey("background-color"))
                        {
                            buttonColor1 = parser.Styles[".CSSButton"].Attributes["background-color"].Split(new char[] { ' ', ',', ')', '(' }).Where(a => a.StartsWith("#")).FirstOrDefault();
                        }
                    }
                }
            }

            if (string.IsNullOrEmpty(buttonColor2))
            {
                if (parser.Styles.ContainsKey(".CSSButton"))
                {
                    if (parser.Styles[".CSSButton"].Attributes.ContainsKey("background"))
                    {
                        buttonColor2 = parser.Styles[".CSSButton"].Attributes["background"].Split(new char[] { ' ', ',', ')', '(' }).Where(a => a.StartsWith("#")).LastOrDefault();
                    }
                    else
                    {
                        if (parser.Styles[".CSSButton"].Attributes.ContainsKey("background-color"))
                        {
                            buttonColor2 = parser.Styles[".CSSButton"].Attributes["background-color"].Split(new char[] { ' ', ',', ')', '(' }).Where(a => a.StartsWith("#")).LastOrDefault();
                        }
                    }
                }
            }
        }
        // GET: UISettings
        public ActionResult Index()
        {
            UICustomiseModel model = new UICustomiseModel(Guid.NewGuid(), "SITE", null);
            CssParser parser = new CssParser();

            parser.AddStyleSheet(Server.MapPath("/Themes/City/Site.css"));

            model.PageBackgroundImage = "/Themes/City/city_bg.png";
            model.Type = "SITE";

            model.SiteId = Guid.NewGuid();
            model.PageId = Guid.NewGuid();

            model.SiteHeaderBackgroundImage = null;
            model.SiteHeaderLogoImage = null;
            model.MenuLevel1Colors = false;

            var portlet = parser.Styles[".portlet"];

            model.CssParser = parser;

            return View(model);
        }
        public string CreateCSS(CssParser parser, string lCColor1, string lCColor2, string bColor1, string bColor2)
        {
            StringBuilder style = new StringBuilder();
            if (parser.Styles.ContainsKey(".portlet"))
            {
                if (parser.Styles[".portlet"].Attributes.ContainsKey("background"))
                {
                    parser.Styles[".portlet"].Attributes.Remove("background");
                }
                else
                {
                    if (parser.Styles[".portlet"].Attributes.ContainsKey("background-color"))
                        parser.Styles[".portlet"].Attributes.Remove("background-color");
                }
            }
            if (parser.Styles.ContainsKey(".CSSButton"))
            {
                if (parser.Styles[".CSSButton"].Attributes.ContainsKey("background"))
                {
                    parser.Styles[".CSSButton"].Attributes.Remove("background");
                }
                else
                {
                    if (parser.Styles[".CSSButton"].Attributes.ContainsKey("background-color"))
                    {
                        parser.Styles[".CSSButton"].Attributes.Remove("background-color");
                    }
                }
            }
            if (parser.Styles.ContainsKey(".CSSButton:hover"))
            {
                if (parser.Styles[".CSSButton:hover"].Attributes.ContainsKey("background"))
                {
                    parser.Styles[".CSSButton:hover"].Attributes.Remove("background");
                }
                else
                {
                    if (parser.Styles[".CSSButton:hover"].Attributes.ContainsKey("background-color"))
                    {
                        parser.Styles[".CSSButton:hover"].Attributes.Remove("background-color");
                    }
                }
            }
            foreach (KeyValuePair<string, CssParser.StyleClass> kv in parser.Styles)
            {
                style.AppendFormat("{0}{{", kv.Key);
                if (kv.Key == ".portlet")
                {
                    style.Append(GetPortletGradient(lCColor1, lCColor2));
                }
                if (kv.Key == ".CSSButton")
                {
                    style.Append(GetButtonGradient(bColor1, bColor2));
                }

                if (kv.Key == ".CSSButton:hover")
                {
                    style.Append(GetButtonGradient(bColor2, bColor1));
                }

                foreach (KeyValuePair<string, string> attribute in kv.Value.Attributes)
                {
                    //check for styles that shouldn't be overwriten
                    if (kv.Key.ToLower().Contains("breadcrumb") || kv.Key == ".ui-corner-all")
                    {
                        if (!attribute.Value.Contains("important"))
                        {
                            style.AppendFormat("{0}:{1} !important; ", attribute.Key, attribute.Value);
                        }
                        else
                        {
                            style.AppendFormat("{0}:{1}; ", attribute.Key, attribute.Value);
                        }
                    }
                    else
                    {
                        style.AppendFormat("{0}:{1}; ", attribute.Key, attribute.Value);
                    }
                }
                style.Append("} ");
            }
            //temp fix for hover
            if (parser.Styles.ContainsKey(".Breadcrumb a:hover"))
            {
                if (!parser.Styles[".Breadcrumb a:hover"].Attributes.ContainsKey("color"))
                {
                    style.AppendFormat(".Breadcrumb a:hover{{color:{0} !important;}}", parser.Styles.ContainsKey(".Breadcrumb a") ? parser.Styles[".Breadcrumb a"].Attributes.ContainsKey("color") ? parser.Styles[".Breadcrumb a"].Attributes["color"] : "" : "");
                }
            }
            string s = style.ToString();
            return s;
        }
 public void GetCssParser(CssParser parser)
 {
     var cssParser = Newtonsoft.Json.JsonConvert.DeserializeObject<CssParser>(Request.Form["parser"]);
 }