コード例 #1
0
        internal static void LogPage(HttpListenerContext context)
        {
            byte[] page;

            // Process changes
            if (context.Request.ContentLength64 > 0)
            {
                int    len  = (int)context.Request.ContentLength64;
                byte[] post = new byte[1024];

                context.Request.InputStream.Read(post, 0, len);
                string resp = Encoding.Default.GetString(post);
                resp = resp.Substring(0, len);

                foreach (string item in resp.Split('&'))
                {
                    string[] pair = item.Split('=');
                    switch (pair[0])
                    {
                    case "sLogLevel":
                        int l = 0;
                        int.TryParse(pair[1], out l);
                        if (l != WF_Config.LogLevel)
                        {
                            WF_Config.LogLevel = l;
                            WFLogging.Level    = (LOG_LEVELS)l;
                            WeatherFlowNS.SaveConfiguration();
                        }
                        break;

                    case "Save":
                        // Look up value of filename and save log to that file
                        string fname = element(resp, "filename");
                        try {
                            using (StreamWriter sw = new StreamWriter(fname)) {
                                sw.Write(WFLogging.ToString());
                            }
                        } catch (Exception ex) {
                            WFLogging.Error(ex.Message);
                        }
                        break;

                    case "Clear":
                        WFLogging.Clear();
                        break;
                    }
                }
            }

            page = ASCIIEncoding.ASCII.GetBytes(MakeLog());

            context.Response.ContentType     = "text/html";
            context.Response.ContentLength64 = page.Length;
            context.Response.AddHeader("Date", DateTime.Now.ToString("r"));
            context.Response.StatusCode = (int)HttpStatusCode.OK;
            context.Response.OutputStream.Write(page, 0, page.Length);
            context.Response.OutputStream.Flush();
            context.Response.OutputStream.Close();
            context.Response.Close();
        }
コード例 #2
0
        internal static void LogText(HttpListenerContext context)
        {
            byte[] page;

            page = ASCIIEncoding.ASCII.GetBytes(WFLogging.ToString());

            context.Response.ContentType     = "text/text";
            context.Response.ContentLength64 = page.Length;
            context.Response.AddHeader("Date", DateTime.Now.ToString("r"));
            context.Response.StatusCode = (int)HttpStatusCode.OK;
            context.Response.OutputStream.Write(page, 0, page.Length);
            context.Response.OutputStream.Flush();
            context.Response.OutputStream.Close();
            context.Response.Close();
        }