コード例 #1
0
        public static void Move(string source, string target, bool overwrite = false)
        {
            if (overwrite && Filesystem.Exist(target))
            {
                File.Delete(target);
            }

            File.Move(source, target);
        }
コード例 #2
0
        public static byte[] HandleWebInterFaceRequest(ref HttpListenerRequest request, ref SQLDatabase db)
        {
            var length = ulong.MinValue;
            var url    = ParseRequest(request.Url.LocalPath != null ? request.Url.LocalPath.ToLowerInvariant() :
                                      "/", request.QueryString, request.HttpMethod, out length);

            if (string.IsNullOrEmpty(url))
            {
                return(new byte[0]);
            }

            if (!Filesystem.Exist(url) && request.HttpMethod == "GET")
            {
                return(new byte[0]);
            }

            var data      = new byte[length];
            var bytesRead = 0;

            Files.Read(url, ref data, out bytesRead);

            if (url.EndsWith(".htm") || url.EndsWith(".html") || url.EndsWith(".js") || url.EndsWith(".css"))
            {
                var pagecontent = string.Empty;
                if (url.EndsWith(".htm") || url.EndsWith(".html"))
                {
                    pagecontent += HTML_header("utf-8", ref db);

                    if (url.EndsWith("index.html"))
                    {
                        pagecontent += "\t\t<div id=\"page\">\n";

                        pagecontent += "\t\t\t<nav>\n";
                        pagecontent += Generate_head_bar(ref db);
                        pagecontent += "\t\t\t</nav>\n";

                        pagecontent += "\t\t<header>\n";
                        pagecontent += "\t\t<h2></h2>\n";
                        pagecontent += "\t\t</header>\n";
                    }

                    pagecontent += "\t<script type=\"text/javascript\">\n";
                    pagecontent += "\t\tdocument.getElementById('anchor_summary').click();\n";
                    pagecontent += "\t</script>\n";
                    pagecontent += "\t\t\t<main>\n";
                }

                pagecontent += Exts.EncodeTo(data, Encoding.UTF8);

                if (url.EndsWith(".htm") || url.EndsWith(".html"))
                {
                    pagecontent = pagecontent.Replace("[[DESIGN]]", "Default");
                    pagecontent = pagecontent.Replace("[[SERVER_INFO_BLOCK]]", Generate_device_list(ref db));

                    pagecontent += "\t\t\t</main>\n";
                    pagecontent += "\t\t</div>\n";
                    pagecontent += HTML_footer();
                }

                data = Encoding.UTF8.GetBytes(pagecontent);
            }

            return(data);
        }