Ejemplo n.º 1
0
        private static string render_pageHtml(HttpApplication app, string html, oPage page)
        {
            string render     = string.Empty,
                   footerPage = string.Empty,
                   key        = string.Format("{0}.{1}", page.path, page.theme),
                   path       = string.Empty,
                   temp       = string.Empty,
                   file       = string.Empty,
                   bodyClass  = string.Empty,
                   uiID       = string.Empty,
                   uiJs       = string.Empty,
                   uiCss      = string.Empty,
                   uis        = string.Empty,
                   uiName     = string.Empty,
                   uiTag      = string.Empty,
                   uiHtml     = string.Empty,
                   uiTick     = DateTime.Now.ToString("yyMMddHHmmssfff");

            string[] a, uiArr, uiArrFull;

            if (_CONST.SET_CACHE)
            {
                if (mSite_Modules.ContainsKey(key))
                {
                    mSite_Modules.TryGetValue(key, out uis);
                    if (!string.IsNullOrWhiteSpace(uis))
                    {
                        a = uis.Split(';');
                        if (a.Length == 1)
                        {
                            uiName = a[0];
                            uiTag  = "{{" + uiName + "}}";
                            if (mUI_Html.ContainsKey(uiName))
                            {
                                mUI_Html.TryGetValue(uiName, out uiHtml);
                            }
                            html  = html.Replace(uiTag, uiHtml);
                            uiJs += @"<script src=""/ui/" + uiName.Split('.')[0] + @".js"" type=""text/javascript""></script>";
                        }
                        else
                        {
                            for (int i = 0; i < a.Length; i++)
                            {
                                uiName = a[i];
                                uiTag  = "{{" + uiName + "}}";
                                if (mUI_Html.ContainsKey(uiName))
                                {
                                    mUI_Html.TryGetValue(uiName, out uiHtml);
                                }
                                html  = html.Replace(uiTag, uiHtml);
                                uiJs += @"<script src=""/ui/" + uiName.Split('.')[0] + @".js"" type=""text/javascript""></script>";
                            }
                        }
                    }
                }

                //s = s +
                //    @"<script src=""/io/vue.min.js"" type=""text/javascript""></script>" +
                //    uiJs +
                //    @"<script src=""/io/ui.sdk.js"" type=""text/javascript""></script>" +
                //    "</body>";
                //render = html.Replace("</body>", s);
            }
            else
            {
                uiArr = html.Split(new string[] { "{{" }, StringSplitOptions.None)
                        .Where(ax => ax.Length > 1)
                        .Where((ax, k) => k > 0 && k < ax.Length - 2)
                        .Select(x => x.Split('}')[0].Trim())
                        .Distinct()
                        .ToArray();

                if (uiArr.Length > 0)
                {
                    var dic = new Dictionary <string, string>()
                    {
                    };
                    for (int i = 0; i < uiArr.Length; i++)
                    {
                        uiName = uiArr[i];
                        a      = uiName.Split(new string[] { "_", "--" }, StringSplitOptions.None);
                        if (a.Length > 3)
                        {
                            bodyClass += " " + uiName;

                            path = string.Format(@"/public/{0}/{1}.htm", page.site_id, uiName);
                            file = (ROOT_PATH + path).Replace("\\/", "\\");
                            if (!File.Exists(file))
                            {
                                path = string.Format(@"/io/ui/{0}/{1}/{2}--{3}.htm", a[0], a[1], a[2], a[3]);
                                file = (ROOT_PATH + path).Replace("\\/", "\\");
                            }

                            if (File.Exists(file))
                            {
                                uiHtml = File.ReadAllText(file);

                                path = string.Format(@"/io/ui/{0}/{1}/{2}.js", a[0], a[1], a[0] + "_" + a[1]);
                                file = (ROOT_PATH + path).Replace("\\/", "\\");
                                if (File.Exists(file))
                                {
                                    uiJs += Environment.NewLine + @"<script src=""" + path + @""" type=""text/javascript""></script>";
                                }

                                path = string.Format(@"/io/ui/{0}/{1}/{2}.css", a[0], a[1], a[0] + "_" + a[1]);
                                file = (ROOT_PATH + path).Replace("\\/", "\\");
                                if (File.Exists(file))
                                {
                                    uiCss += Environment.NewLine + @"<link href=""" + path + @""" rel=""stylesheet"">";
                                }
                            }
                            else
                            {
                                uiHtml = string.Format(_CONST.PAGE_NOT_FOUND, file);
                            }
                        }
                        else
                        {
                            uiHtml = string.Format(_CONST.COMPONENT_SETTING_WRONG, uiName);
                        }
                        dic.Add(uiName, uiHtml);
                    }

                    uiArrFull = html.Split(new string[] { "{{" }, StringSplitOptions.None).ToArray();
                    var bi  = new StringBuilder(string.Empty);
                    int pos = -1;
                    for (int i = 0; i < uiArrFull.Length; i++)
                    {
                        temp = uiArrFull[i];
                        pos  = temp.IndexOf("}}");
                        if (pos == -1)
                        {
                            bi.Append(temp);
                        }
                        else
                        {
                            uiName = temp.Substring(0, pos);
                            if (dic.ContainsKey(uiName))
                            {
                                uiID   = "ui-" + uiTick + "-" + i.ToString();
                                a      = uiName.Split(new string[] { "_", "--" }, StringSplitOptions.None);
                                pos    = pos + 2;
                                uiHtml = Environment.NewLine +
                                         @"<div ui-name=""" + uiName + @""" id=""edit-" + uiID + @""" ui-id=""[{ID}]"" name=""___io_ui"" class=""[{ID}]--edit-vc ___io_ui--edit-vc"" " +
                                         @"ui-group=""" + a[0] + @""" ui-kit=""" + a[1] +
                                         @""" ui-theme=""" + a[2] + @""" ui-temp=""" + a[3] + @""" onclick=""___io_editVcChose(this)""></div>" +
                                         Environment.NewLine +
                                         dic[uiName] + temp.Substring(pos, temp.Length - pos);

                                uiHtml = uiHtml.Replace("[{ID}]", uiID);

                                bi.Append(uiHtml);
                            }
                        }
                    }

                    file = app.Server.MapPath("~/io/ui.sdk.htm");
                    if (File.Exists(file))
                    {
                        END_BODY_HTML = File.ReadAllText(file);
                    }

                    html = bi.ToString() + uiCss + uiJs + END_BODY_HTML;
                    html = html
                           .Replace("[{SITE}]", page.site_id.ToString())
                           .Replace("[{THEME}]", page.theme)
                           .Replace("[{TOKEN}]", page.token);
                }

                render = html.Replace("[{BODY_CLASS}]", bodyClass);
            }

            return(render);
        }
Ejemplo n.º 2
0
        private static bool response_rewritePath(HttpApplication app, string pathFile, oPage page)
        {
            string file = string.Empty;

            if (!string.IsNullOrWhiteSpace(pathFile))
            {
                file = app.Server.MapPath(pathFile);
            }
            if (page == null)
            {
                if (File.Exists(file))
                {
                    HttpContext.Current.RewritePath(pathFile);
                    return(true);
                }
                return(false);
            }

            string key = string.Format("{0}.{1}", page.path, page.theme), html = string.Empty;

            if (_CONST.SET_CACHE && mCaches.ContainsKey(key))
            {
                mCaches.TryGetValue(key, out html);
            }
            else if (File.Exists(file))
            {
                html = File.ReadAllText(file);
                html = render_pageHtml(app, html, page);
                mCaches.TryAdd(key, html);
            }
            else
            {
                html = string.Format(_CONST.PAGE_NOT_FOUND, file);
            }

            //string name = "io_page_" + page.path.ToLower(), value = page.theme;
            //HttpContext.Current.Response.Cookies.Set(new HttpCookie(name, value));

            //name = "io_site_" + page.path.ToLower();
            //value = page.site_id.ToString();
            //HttpContext.Current.Response.Cookies.Set(new HttpCookie(name, value));

            response_Write(html, "text/html");

            return(true);
        }
Ejemplo n.º 3
0
        static bool request_RouterGET(HttpApplication app, string path, string key)
        {
            int    index = -1, id = -1;
            string newPath, pathFile, file;

            if (path.EndsWith(".json"))
            {
                newPath = "~/" + path;
                file    = app.Server.MapPath(newPath);
                if (File.Exists(file))
                {
                    HttpContext.Current.RewritePath(newPath);
                    return(true);
                }
                else
                {
                    response_Write("{}");
                    return(true);
                }
            }

            if (path.StartsWith("io/"))
            {
                newPath = "~/" + path;
                HttpContext.Current.RewritePath(newPath);
                return(true);
            }

            if (path.StartsWith("test/"))
            {
                newPath = "~/" + path + ".html";
                HttpContext.Current.RewritePath(newPath);
                return(true);
            }

            for (int i = 0; i < mPaths.Length; i++)
            {
                if (mPaths[i] == key)
                {
                    index = i;
                    break;
                }
            }

            oPage page = null;

            if (index != -1 &&
                mPathPage.ContainsKey(index) &&
                mPathPage.TryGetValue(index, out id) &&
                mPages.ContainsKey(id) &&
                mPages.TryGetValue(id, out page))
            {
                pathFile = string.Format("~/io/site/{0}.{1}.htm", page.path, page.theme);
                if (response_rewritePath(app, pathFile, page) == false)
                {
                    pathFile = string.Format("~/io/site/404.{0}.htm", page.theme);
                    if (response_rewritePath(app, pathFile, page) == false)
                    {
                        pathFile = "~/io/site/404.htm";
                        if (response_rewritePath(app, pathFile, page))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }
            }

            pathFile = "~/io/site/404.htm";
            if (response_rewritePath(app, pathFile, page))
            {
                return(true);
            }
            //response_Write(new { Ok = false, Message = "Cannot find page: " + path });

            return(true);
        }
Ejemplo n.º 4
0
        public static void app_loadConfig(HttpApplication app)
        {
            List <string> listPaths = new List <string>()
            {
            };
            string file = app.Server.MapPath("~/io/config.json");

            if (File.Exists(file))
            {
                string  json  = File.ReadAllText(file);
                oSite[] sites = new oSite[] { };
                try
                {
                    sites = JsonConvert.DeserializeObject <oSite[]>(json);
                    var ss = sites.GroupBy(x => x.id).Select(x => x.Last()).ToArray();
                    foreach (var site in ss)
                    {
                        mSites.TryAdd(site.id, site);

                        string[] domains = new string[] { };
                        if (site.domains != null && site.domains.Length > 0)
                        {
                            domains = site.domains.Distinct().ToArray();
                        }
                        foreach (string domain in domains)
                        {
                            mDomainSite.TryAdd(domain, site.id);
                        }

                        var pages = new string[][] { };
                        if (site.pages != null && site.pages.Length > 0)
                        {
                            pages = site.pages.Distinct()
                                    .Select(x => x.ToLower().Split('.'))
                                    .Where(x => x.Length == 3)
                                    .ToArray();
                        }

                        foreach (var ps in pages)
                        {
                            var p = new oPage()
                            {
                                id      = mPages.Count + 1,
                                key     = string.Join(".", ps),
                                login   = ps[2] == "1",
                                site_id = site.id,
                                path    = ps[0],
                                theme   = ps[1]
                            };
                            mPages.TryAdd(p.id, p);

                            foreach (var domain in domains)
                            {
                                string fullPath = string.Format("{0}/{1}", domain, ps[0]);
                                mPathPage.TryAdd(listPaths.Count, p.id);
                                listPaths.Add(fullPath);
                            }
                        }
                    }
                }
                catch { }
            }

            mPaths = listPaths.ToArray();
        }