예제 #1
0
        public void ProcessRequest(HttpContext context)
        {
            var            request     = context.Request;
            var            response    = context.Response;
            var            filepath    = request["filepath"];
            var            filecontent = request["filecontent"];
            ResponseResult result      = new ResponseResult();

            if (string.IsNullOrEmpty(filepath))
            {
                result.Fail("文件名字");
            }
            if (string.IsNullOrEmpty(filecontent))
            {
                filecontent = "";
            }
            var realpath = context.Server.MapPath("~" + filepath);

            try
            {
                File.WriteAllText(realpath, filecontent);
                result.Success();
            }
            catch (Exception e)
            {
                result.Fail(e.Message.Replace('\n', ' ').Replace('\r', ' '));
            }
            context.Response.Write(result);
        }
예제 #2
0
        public void ProcessRequest(HttpContext context)
        {
            var            request  = context.Request;
            var            response = context.Response;
            var            filepath = request["filepath"];
            ResponseResult result   = new ResponseResult();

            if (string.IsNullOrEmpty(filepath))
            {
                result.Fail("文件名字");
            }
            var realpath = context.Server.MapPath("~" + filepath);

            try
            {
                FileInfo fi    = new FileInfo(realpath);
                string   total = "";
                string   s     = "";
                using (StreamReader sr = fi.OpenText())
                {
                    while ((s = sr.ReadLine()) != null)
                    {
                        total += s + "\n";
                    }
                }
                result.Success().AddData(total);
            }
            catch (Exception e)
            {
                result.Fail(e.Message.Replace('\n', ' ').Replace('\r', ' '));
            }
            context.Response.Write(result);
        }
예제 #3
0
        public void ProcessRequest(HttpContext context)
        {
            var            request  = context.Request;
            var            response = context.Response;
            var            filepath = request["filepath"];
            ResponseResult result   = new ResponseResult();

            if (string.IsNullOrEmpty(filepath))
            {
                result.Fail("路径名字");
            }
            else
            {
                var realpath  = context.Server.MapPath("~" + filepath);
                var typeradio = request["typeradio"];
                try
                {
                    FileInfo fi = null;
                    switch (typeradio)
                    {
                    case "module":
                        fi = new FileInfo(realpath + ".js");
                        fi.Delete();
                        fi = new FileInfo(realpath + ".htm");
                        fi.Delete();
                        break;

                    case "folder":
                        DirectoryInfo di = new DirectoryInfo(realpath);
                        di.Delete(true);
                        break;

                    default:
                        fi = new FileInfo(realpath);
                        fi.Delete();
                        break;
                    }
                    result.Success();
                }
                catch (Exception e)
                {
                    result.Fail(e.Message.Replace('\n', ' ').Replace('\r', ' '));
                }
            }
            context.Response.Write(result);
        }
예제 #4
0
        public void ProcessRequest(HttpContext context)
        {
            var            request  = context.Request;
            var            response = context.Response;
            var            filepath = request["filepath"];
            ResponseResult result   = new ResponseResult();

            if (string.IsNullOrEmpty(filepath))
            {
                result.Fail("路径名字");
            }
            else
            {
                var realpath  = context.Server.MapPath("~" + filepath);
                var typeradio = request["typeradio"];
                var filename  = request["name"];
                if (string.IsNullOrEmpty(filename) && typeradio != "img")
                {
                    result.Fail("文件名字");
                }
                else
                {
                    try
                    {
                        FileInfo fi = null;
                        switch (typeradio)
                        {
                        case "module":
                            if (File.Exists(realpath + "/" + filename + ".js"))
                            {
                                result.Fail("模块" + filename + "已存在,请删除后再试");
                                break;
                            }
                            fi = new FileInfo(realpath + "/" + filename + ".js");
                            var clspath = filepath.Replace('/', '.');
                            if (clspath != "")
                            {
                                clspath = clspath.Substring(1);
                            }
                            clspath += "." + filename;
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.WriteLine("//@ sourceURL=" + clspath);
                                sw.WriteLine("$.u.define(\"" + clspath + "\", null, {");
                                sw.WriteLine("    init: function () {");
                                sw.WriteLine("");
                                sw.WriteLine("    },");
                                sw.WriteLine("    afterrender: function () {");
                                sw.WriteLine("");
                                sw.WriteLine("    },");
                                sw.WriteLine("    resize: function () {");
                                sw.WriteLine("");
                                sw.WriteLine("    },");
                                sw.WriteLine("    destroy: function () {");
                                sw.WriteLine("        this._super();");
                                sw.WriteLine("    }");
                                sw.WriteLine("}, { usehtm: true, usei18n: false });");
                                sw.WriteLine("");
                                sw.WriteLine("");
                                sw.WriteLine(clspath + ".widgetjs = [];");
                                sw.WriteLine(clspath + ".widgetcss = [];");
                            }
                            fi = new FileInfo(realpath + "/" + filename + ".htm");
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.WriteLine("<!DOCTYPE html>");
                                sw.WriteLine("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
                                sw.WriteLine("<head>");
                                sw.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>");
                                sw.WriteLine("    <title></title>");
                                sw.WriteLine("</head>");
                                sw.WriteLine("<body>");
                                sw.WriteLine("");
                                sw.WriteLine("</body>");
                                sw.WriteLine("</html>");
                            }
                            result.Success();
                            break;

                        case "folder":
                            if (File.Exists(realpath + "/" + filename))
                            {
                                result.Fail("文件夹" + filename + "已存在,请删除后再试");
                                break;
                            }
                            DirectoryInfo di = new DirectoryInfo(realpath + "/" + filename);
                            di.Create();
                            result.Success().AddData(di.CreationTime.Ticks + "-" + filename);
                            break;

                        case "css":
                            if (File.Exists(realpath + "/" + filename + ".css"))
                            {
                                result.Fail("样式" + filename + "已存在,请删除后再试");
                                break;
                            }
                            fi = new FileInfo(realpath + "/" + filename + ".css");
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.WriteLine("body{");
                                sw.WriteLine("");
                                sw.WriteLine("}");
                            }
                            result.Success();
                            break;

                        case "html":
                            if (File.Exists(realpath + "/" + filename + ".html"))
                            {
                                result.Fail("html" + filename + "已存在,请删除后再试");
                                break;
                            }
                            fi = new FileInfo(realpath + "/" + filename + ".html");
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.WriteLine("<!DOCTYPE html>");
                                sw.WriteLine("<html xmlns=\"http://www.w3.org/1999/xhtml\">");
                                sw.WriteLine("<head>");
                                sw.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\"/>");
                                sw.WriteLine("    <title></title>");
                                sw.WriteLine("</head>");
                                sw.WriteLine("<body>");
                                sw.WriteLine("");
                                sw.WriteLine("</body>");
                                sw.WriteLine("</html>");
                            }
                            result.Success();
                            break;

                        case "js":
                            if (File.Exists(realpath + "/" + filename + ".js"))
                            {
                                result.Fail("js" + filename + "已存在,请删除后再试");
                                break;
                            }
                            fi = new FileInfo(realpath + "/" + filename + ".js");
                            using (StreamWriter sw = fi.CreateText())
                            {
                                sw.WriteLine("//");
                            }
                            result.Success();
                            break;

                        case "img":
                            HttpPostedFile file = request.Files[0];
                            if (File.Exists(realpath + "/" + file.FileName))
                            {
                                result.Fail("图片" + file.FileName + "已存在,请删除后再试");
                                break;
                            }
                            file.SaveAs(realpath + "/" + file.FileName);
                            result.Success();
                            break;

                        default:
                            result.Fail("不支持的文件类型");
                            break;
                        }
                    }
                    catch (Exception e)
                    {
                        result.Fail(e.Message.Replace('\n', ' ').Replace('\r', ' '));
                    }
                }
            }
            context.Response.Write(result);
        }