예제 #1
0
        public static void AddAdminLog(Kooboo.Data.Context.RenderContext context, RenderRespnose response)
        {
            if (response != null && response.ContentType != null && response.ContentType.ToLower().Contains("html"))
            {
                BackendLog model = new BackendLog();
                model.IP = context.Request.IP;
                if (context.User != null)
                {
                    model.UserId   = context.User.Id;
                    model.UserName = context.User.UserName;
                }
                model.Url        = context.Request.RawRelativeUrl;
                model.StatusCode = 200;

                if (context.Request.Cookies != null)
                {
                    foreach (var item in context.Request.Cookies)
                    {
                        model.Data[item.Key] = item.Value;
                    }
                }

                if (context.Request.Forms != null)
                {
                    foreach (var item in context.Request.Forms.AllKeys)
                    {
                        string key   = item;
                        string value = null;

                        var itemvalue = context.Request.Forms.GetValues(item);
                        if (itemvalue != null)
                        {
                            value = string.Join(";", itemvalue);
                        }

                        model.Data[key] = value;
                    }
                }

                if (context.Request.QueryString != null)
                {
                    foreach (var item in context.Request.QueryString.AllKeys)
                    {
                        string key   = item;
                        string value = null;

                        var itemvalue = context.Request.QueryString.GetValues(item);
                        if (itemvalue != null)
                        {
                            value = string.Join(";", itemvalue);
                        }

                        model.Data[key] = value;
                    }
                }

                Add(model);
                Kooboo.Data.Service.UserLoginService.UpdateLastPath(model);
            }
        }
예제 #2
0
        public static RenderRespnose Render(RenderContext Context, JsTestOption option)
        {
            string root = option.GetDiskRoot(Context);

            string         relativeurl = RenderEngine.ParseRelativeUrl(Context.Request.RawRelativeUrl, option);
            RenderRespnose response    = new RenderRespnose();

            var command = JsTestHelper.ParseCommand(relativeurl);

            if (command.IsJs)
            {
                RenderJs(Context, option, root, response, command);
            }
            else
            {
                response.ContentType = "text/html";

                if (command.Command == JsTestCommand.JsCommand.view)
                {
                    RenderTestView(Context, option, response, command);
                }
                else if (command.Command == JsTestCommand.JsCommand.run)
                {
                    RenderTestRun(Context, option, response, command);
                }
            }
            return(response);
        }
예제 #3
0
        public static void RenderTestView(RenderContext Context, JsTestOption option, RenderRespnose response, JsTestCommand command)
        {
            if (string.IsNullOrEmpty(command.Folder) || command.Folder == "\\" || command.Folder == "/")
            {
                // find the start html.
                var    starthtml = JsTestHelper.GetStartHtml(Context, option);
                string url       = GenerateUrl(option, JsTestCommand.JsCommand.run, null, null);

                var    folders = JsTestHelper.ListTestFolders(Context, option);
                var    count   = JsTestHelper.CountTest(Context, option, folders.ToList());
                string html    = "<h3><a href='" + url + "'>run all tests</a>  (" + count.ToString() + " tests)</h3>\r\n";

                html += "<ul>";
                foreach (var item in folders)
                {
                    var files     = JsTestHelper.ListAllTestFiles(Context, option, item);
                    int testcount = JsTestHelper.CountTest(Context, option, item);

                    if (testcount > 0)
                    {
                        html += "<li>";

                        url   = GenerateUrl(option, JsTestCommand.JsCommand.run, item, null);
                        html += "<a href='" + url + "'>run</a> || ";

                        url   = GenerateUrl(option, JsTestCommand.JsCommand.view, item, null);
                        html += "<a href='" + url + "'>view</a> || ";

                        html += files.Count.ToString() + " files || ";
                        html += testcount.ToString() + " tests || Folder: ";
                        html += item;
                        html += "</li>";
                    }
                }
                html += "</ul>";

                string output = starthtml.Replace(JsTestHelper.PlaceHolder, html);

                string info = JsTestHelper.GetInfoHtml(Context, option);

                output = output.Replace("<div id=\"information\"></div>", info);

                response.Body = output;
            }

            else
            {
                if (string.IsNullOrEmpty(command.File))
                {
                    // view folder...
                    var starthtml = JsTestHelper.GetStartHtml(Context, option);

                    var files = JsTestHelper.ListFolderFiles(Context, option, command.Folder);

                    var count = JsTestHelper.CountTest(Context, option, command.Folder);

                    string url  = GenerateUrl(option, JsTestCommand.JsCommand.run, command.Folder, null);
                    string html = "<h3><a href='" + url + "'>run all tests</a>  (" + count.ToString() + " tests)</h3>\r\n";

                    html += "<ul>";

                    foreach (var item in files)
                    {
                        var functions = JsTestHelper.ListFileFunctions(Context, option, item.Folder, item.file);

                        html += "<li>";

                        url   = GenerateUrl(option, JsTestCommand.JsCommand.run, item.Folder, item.file);
                        html += "<a href='" + url + "'>run</a> || ";

                        url   = GenerateUrl(option, JsTestCommand.JsCommand.view, item.Folder, item.file);
                        html += "<a href='" + url + "'>view</a>  || ";

                        html += functions.Count.ToString() + " tests || File: " + System.IO.Path.Combine(item.Folder, item.file);

                        html += "</li>";
                    }
                    html += "</ul>";


                    response.Body = starthtml.Replace(JsTestHelper.PlaceHolder, html);
                }
                else
                {
                    //view file.
                    var    starthtml = JsTestHelper.GetStartHtml(Context, option);
                    string url       = GenerateUrl(option, JsTestCommand.JsCommand.run, command.Folder, command.File);

                    var functions = JsTestHelper.ListFileFunctions(Context, option, command.Folder, command.File);

                    string html = "<h3><a href='" + url + "'>run all tests</a>  (" + functions.Count.ToString() + " tests)</h3>\r\n";

                    html += "<ul>";

                    foreach (var item in functions)
                    {
                        url   = GenerateUrl(option, JsTestCommand.JsCommand.run, command.Folder, command.File, item);
                        html += "<li><a href='" + url + "'>run</a> || Test: " + item + "</li>";
                    }
                    html         += "</ul>";
                    response.Body = starthtml.Replace(JsTestHelper.PlaceHolder, html);
                }
            }
        }
예제 #4
0
        public static void RenderJs(RenderContext Context, JsTestOption option, string root, RenderRespnose response, JsTestCommand command)
        {
            response.ContentType = "application/javascript";

            if (!string.IsNullOrEmpty(command.JsPath))
            {
                string filename = command.JsPath.Replace("/", "\\");

                if (filename.IndexOf("?") > -1)
                {
                    filename = filename.Substring(0, filename.IndexOf("?"));
                }

                if (filename.StartsWith("\\"))
                {
                    filename = filename.Substring(1);
                }

                string fullname = root;
                string prepath  = option.FolderPath(Context);

                if (!string.IsNullOrEmpty(prepath))
                {
                    fullname = IOHelper.CombinePath(root, prepath);
                }

                fullname = IOHelper.CombinePath(fullname, filename);


                if (!System.IO.File.Exists(fullname))
                {
                    // This is to make sure the render of assert js...
                    foreach (var item in option.AssertJs)
                    {
                        if (filename.EndsWith(item))
                        {
                            fullname = System.IO.Path.Combine(Kooboo.Data.AppSettings.RootPath, "/_admin/kbtest/" + item);
                        }
                    }
                }

                if (System.IO.File.Exists(fullname))
                {
                    string baserelarive = GetRelative(prepath, command.JsPath);


                    if (command.Command == JsTestCommand.JsCommand.run)
                    {
                        string retryurl  = string.Empty;
                        string rawfolder = filename;
                        int    lastslash = rawfolder.LastIndexOf("\\");
                        if (lastslash > -1)
                        {
                            string folder     = rawfolder.Substring(0, lastslash);
                            string jsfilename = rawfolder.Substring(lastslash + 1);
                            retryurl = GenerateUrl(option, JsTestCommand.JsCommand.run, folder, jsfilename);
                        }

                        // TODO: Render the k commands.
                        var alltext = IOHelper.ReadAllText(fullname);
                        alltext = RenderServerSide(alltext, root, Context, baserelarive);

                        response.Body = RenderJs(option, alltext, command.Function, retryurl);
                    }
                    else
                    {
                        var alltext = IOHelper.ReadAllText(fullname);
                        alltext = RenderServerSide(alltext, root, Context, baserelarive);

                        response.Body = alltext;
                    }
                }
            }
        }
예제 #5
0
        private static void RenderTestRun(RenderContext Context, JsTestOption option, RenderRespnose response, JsTestCommand command)
        {
            var    starthtml = JsTestHelper.GetStartHtml(Context, option);
            string html      = "<div>";

            html += "\r\n<script src='/_admin/kbtest/expect.js'></script>";
            html += "\r\n<script src='/_admin/kbtest/mock.js'></script>";

            var references = JsTestHelper.GetReferenceJs(Context, option, command.Folder);

            foreach (var item in references)
            {
                html += "\r\n<script src='" + item + "'></script>";
            }

            if (string.IsNullOrEmpty(command.Folder) || command.Folder == "\\" || command.Folder == "/")
            {
                // run all.
                var allfiles = JsTestHelper.ListAllTestFiles(Context, option, null);
                foreach (var file in allfiles)
                {
                    string fileurl = GeneratejsFile(option, file, JsTestCommand.JsCommand.run);
                    html += "\r\n<script src='" + fileurl + "'></script>";
                }
            }

            else if (string.IsNullOrEmpty(command.File))
            {
                // run folder.
                var allfiles = JsTestHelper.ListAllTestFiles(Context, option, command.Folder);
                foreach (var file in allfiles)
                {
                    string fileurl = GeneratejsFile(option, file, JsTestCommand.JsCommand.run);
                    html += "\r\n<script src='" + fileurl + "'></script>";
                }
            }
            else
            {
                if (string.IsNullOrEmpty(command.Function))
                {
                    // run file.
                    string filename = Lib.Helper.IOHelper.CombinePath(command.Folder, command.File);

                    string fileurl = GeneratejsFile(option, filename, JsTestCommand.JsCommand.run);
                    html += "\r\n<script src='" + fileurl + "'></script>";
                }
                else
                {
                    // run function.
                    string filename = Lib.Helper.IOHelper.CombinePath(command.Folder, command.File);

                    html += "<div><h4>You are running one unit test, open console to view any errors</h4></div>";

                    string fileurl = GeneratejsFile(option, filename, JsTestCommand.JsCommand.run, command.Function);
                    html += "\r\n<script src='" + fileurl + "'></script>";
                }
            }

            html         += "</div>";
            response.Body = starthtml.Replace(JsTestHelper.PlaceHolder, html);
        }