Exemple #1
0
        void webServer_ProcessRequest(object sender, ProcessRequestEventArgs args)
        {
            var r = args.Response;

            r.ContentType = "text/html";
            r.WriteLine("<html><h1>Hello World!</h1></html>");
        }
        public bool ProcessAsync(ProcessRequestEventArgs args)
        {
            string output = "";

            output += string.Format("{0}: {1}\n", "sent_messages", sent_messages);
            args.Response.Producer = new BufferedProducer(output);
            resetStats();
            return(false);
        }
        public bool ProcessAsync(ProcessRequestEventArgs args)
        {
            string output = "";

            output += "<a href=\"munin.stats.blocks\">munin.stats.blocks</a><br>\n";
            output += "<a href=\"munin.stats.players\">munin.stats.players</a><br>\n";
            output += "<a href=\"munin.stats.chat\">munin.stats.chat</a><br>\n";
            args.Response.Producer = new BufferedProducer(output);
            return(false);
        }
        public bool ProcessAsync(ProcessRequestEventArgs args)
        {
            string output = "";

            output += string.Format("{0}: {1}\n", "blocks_placed", blocks_placed);
            output += string.Format("{0}: {1}\n", "blocks_destroyed", blocks_destroyed);
            output += string.Format("{0}: {1}\n", "blocks_used", blocks_used);
            args.Response.Producer = new BufferedProducer(output);
            resetStats();
            return(false);
        }
        public bool ProcessAsync(ProcessRequestEventArgs args)
        {
            calculatePlayerStats();
            string output = "";

            output += string.Format("{0}: {1}\n", "players_online", players_online);
            output += string.Format("{0}: {1}\n", "players_npc", players_npc);
            output += string.Format("{0}: {1}\n", "players_spectator", players_spectator);
            output += string.Format("{0}: {1}\n", "players_max", players_max);
            args.Response.Producer = new BufferedProducer(output);
            return(false);
        }
Exemple #6
0
        void webServer_ProcessRequest(object sender, ProcessRequestEventArgs args)
        {
            try
            {
                string cmd = args.Request.Path;
                if (cmd == "/ver")
                {
                    UpgradeHelper helper = new UpgradeHelper();
                    string        baseVersion;
                    string        latestVersion;
                    string[]      vers;
                    string        currentVersion;
                    helper.ShowVersion(out baseVersion, out latestVersion, out vers, out currentVersion);



                    VersionJson json = new VersionJson();
                    json.baseVersion    = baseVersion;
                    json.latestVersion  = latestVersion;
                    json.vers           = vers;
                    json.currentVersion = currentVersion;

                    string jsonString;
                    jsonString = JsonMapper.ToJson(json);

                    var data = Encoding.UTF8.GetBytes(jsonString);
                    args.Response.BinaryWrite(data);
                }
                else if (cmd == "/upgrade")
                {
                    Thread thread1 = new Thread(() =>
                    {
                        UpgradeHelper helper = new UpgradeHelper();
                        helper.Upgrade("");
                    });
                    thread1.Start();

                    var data = Encoding.UTF8.GetBytes("Launched");
                    args.Response.BinaryWrite(data);
                }
                else if (cmd == "/progress")
                {
                    string jsonString;
                    jsonString = JsonMapper.ToJson(currentProgress);
                    var data = Encoding.UTF8.GetBytes(jsonString);
                    args.Response.BinaryWrite(data);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine("Http Request Exception:" + e.Message);
            }
        }
 public bool ProcessAsync(ProcessRequestEventArgs args)
 {
     var html = @"<!doctype html>
     <html>
     <head>
     <title>Hello World</title>
     <style type='text/css'>
     * { font-family: Arial, sans-serif  }
     </style>
     </head>
     <body>
     <h1>Hello World</h1>
     <p>This is a demo from a simple HttpModule for the lightweight, async focused HTTP library libHTTP.</p>
     </body>
     </html>";
     args.Response.Headers.Add("Content-Type", "text/html");
     args.Response.Producer = new BufferedProducer(html);
     return false;
 }
Exemple #8
0
 public bool ProcessAsync(ProcessRequestEventArgs args)
 {
     var postDump = "";
     if (args.Request.Method == HttpMethod.POST)
     {
         postDump = String.Format("Raw POST data: <strong>{0}</strong><br />", Encoding.UTF8.GetString(args.Request.Body));
     }
     var html = @"<html>
     <body>
     <form action='/testpost' method='post'>
     " + postDump + @"
     <input type='text' name='testvar' value='' />
     <input type='submit' />
     </form>
     </body>
     </html>";
     args.Response.Producer = new BufferedProducer(html);
     return false;
 }
        void webServer_ProcessRequest(object sender, ProcessRequestEventArgs args)
        {
            string cmd = args.Request.Path;

            if (cmd == "/ver")
            {
                UpgradeHelper helper = new UpgradeHelper();
                string        baseVersion;
                string        latestVersion;
                string[]      vers;
                string        currentVersion;
                helper.ShowVersion(out baseVersion, out latestVersion, out vers, out currentVersion);



                VersionJson json = new VersionJson();
                json.baseVersion    = baseVersion;
                json.latestVersion  = latestVersion;
                json.vers           = vers;
                json.currentVersion = currentVersion;

                string jsonString;
                jsonString = JsonMapper.ToJson(json);

                var data = Encoding.UTF8.GetBytes(jsonString);
                args.Response.BinaryWrite(data);
            }
            else if (cmd == "/upgrade")
            {
                UpgradeHelper helper = new UpgradeHelper();
                helper.Upgrade("");

                var data = Encoding.UTF8.GetBytes("Launched");
                args.Response.BinaryWrite(data);
            }
            else if (cmd == "/progress")
            {
                string jsonString;
                jsonString = JsonMapper.ToJson(currentProgress);
                var data = Encoding.UTF8.GetBytes(jsonString);
                args.Response.BinaryWrite(data);
            }
        }
Exemple #10
0
        public bool ProcessAsync(ProcessRequestEventArgs args)
        {
            pageViews++;
            double cpu  = Process.GetCurrentProcess().TotalProcessorTime.TotalSeconds / stopwatch.Elapsed.TotalSeconds;
            string html = "<html>";

            html += "<h1>System Statistics</h1>";
            html += "<ul>";
            html += string.Format("<li>Uptime: {0} <br/></li>", ToReadableString(stopwatch.Elapsed));
            html += string.Format("<li>CPU usage: {0:P2} <br/></li>", cpu);
            html += string.Format("<li>Total processor time: {0}<br/></li>", ToReadableString(Process.GetCurrentProcess().TotalProcessorTime));
            html += string.Format("<li>Working set: {0}<br/></li>", BytesToString(Process.GetCurrentProcess().WorkingSet64));
            html += string.Format("<li>Total bytes downloaded: {0}<br/></li>", BytesToString(m.TotalReceivedBytes()));
            html += string.Format("<li>Total bytes uploaded: {0}<br/></li>", BytesToString(m.TotalSentBytes()));
            html += "</ul>";
            html += string.Format("Page accessed <b>{0}</b> times.<br/>", pageViews);
            html += "</html>";
            args.Response.Producer = new BufferedProducer(html);
            return(false);
        }
Exemple #11
0
        public bool ProcessAsync(ProcessRequestEventArgs args)
        {
            var html = @"<!doctype html>
<html>
    <head>
        <title>Hello World</title>
        <style type='text/css'>
            * { font-family: Arial, sans-serif  }
        </style>
    </head>
    <body>
        <h1>Hello World</h1>
        <p>This is a demo from a simple HttpModule for the lightweight, async focused HTTP library libHTTP.</p>
    </body>
</html>";

            args.Response.Headers.Add("Content-Type", "text/html");
            args.Response.Producer = new BufferedProducer(html);
            return(false);
        }
Exemple #12
0
        public bool ProcessAsync(ProcessRequestEventArgs args)
        {
            var postDump = "";

            if (args.Request.Method == HttpMethod.POST)
            {
                postDump = String.Format("Raw POST data: <strong>{0}</strong><br />", Encoding.UTF8.GetString(args.Request.Body));
            }
            var html = @"<html>
    <body>
        <form action='/testpost' method='post'>
            " + postDump + @"
            <input type='text' name='testvar' value='' />
            <input type='submit' />
        </form>
    </body>
</html>";

            args.Response.Producer = new BufferedProducer(html);
            return(false);
        }
 private void Init_OnRequestUnresolved(object sender, ProcessRequestEventArgs e)
 {
 }
Exemple #14
0
 private static void WebServer_ProcessRequest(object sender, ProcessRequestEventArgs args)
 {
     throw new NotImplementedException();
 }
        // 处理一个通道的通讯活动
        public virtual void HandleClient(TcpClient tcpClient,
                                         Action close_action,
                                         CancellationToken token)
        {
#if NO
            ZServerChannel channel = _zChannels.Add(tcpClient);
            // 允许对 channel 做额外的初始化
            if (this.ChannelOpened != null)
            {
                this.ChannelOpened(channel, new EventArgs());
            }
            try
            {
                string ip = "";

                try
                {
                    ip = GetClientIP(tcpClient);
                    channel.Touch();

                    int  i       = 0;
                    bool running = true;
                    while (running)
                    {
                        if (token != null && token.IsCancellationRequested)
                        {
                            return;
                        }
                        // 注意调用返回后如果发现返回 null 或者抛出了异常,调主要主动 Close 和重新分配 TcpClient
                        BerTree request = await ZProcessor.GetIncomingRequest(tcpClient);

                        if (request == null)
                        {
                            Console.WriteLine("client close on request " + i);
                            break;
                        }
                        Console.WriteLine("request " + i);

                        channel.Touch();
                        if (token != null && token.IsCancellationRequested)
                        {
                            return;
                        }

                        byte[] response = null;
                        if (this.ProcessRequest == null)
                        {
                            response = await DefaultProcessRequest(channel, request);
                        }
                        else
                        {
                            ProcessRequestEventArgs e = new ProcessRequestEventArgs();
                            e.Request = request;
                            this.ProcessRequest(channel, e);
                            response = e.Response;
                        }

                        channel.Touch();
                        if (token != null && token.IsCancellationRequested)
                        {
                            return;
                        }

                        // 注意调用返回 result.Value == -1 情况下,要及时 Close TcpClient
                        Result result = await SendResponse(response, tcpClient);

                        channel.Touch();
                        if (result.Value == -1)
                        {
                            Console.WriteLine("error on response " + i + ": " + result.ErrorInfo);
                            break;
                        }

                        i++;
                    }
                }
                catch (Exception ex)
                {
                    string strError = "ip:" + ip + " HandleClient() 异常: " + ExceptionUtil.GetExceptionText(ex);
                    ZManager.Log?.Error(strError);
                    // Console.WriteLine(strError);
                }
                finally
                {
                    // tcpClient.Close();
                    // 清除全局结果集
                }
            }
            finally
            {
                _zChannels.Remove(channel);
                channel.Close();
                close_action.Invoke();
            }
#endif
        }
Exemple #16
0
    static void ProcessRequestHandler <I, O>(GetProcessInstance <I, O> getProcessInstance, object sender, ProcessRequestEventArgs <I, O> args)
    {
        var process = getProcessInstance();

        if (args.Parent != null)
        {
            ProcessExitCallback forceChildExit = (s, e) => process.ForceExit();
            ProcessExitCallback detachChild    = (s, e) => {
                args.Parent.OnExit -= forceChildExit;
                Debug.Log("Detached child: " + process);
            };
            process.OnExit     += detachChild;
            args.Parent.OnExit += forceChildExit;
        }

        if (args.SetChild != null)
        {
            args.SetChild(process);
        }

        ProcessExitCallback castCallback = (s, e) => args.Callback(s, (O)e);

        process.OnExit += castCallback;

        //Debug.Log("Started: " + process);
        //process.OnExit += (s, e) => Debug.Log("Ended: " + process);

        process.Initialize(args.Data);
    }
Exemple #17
0
        private void Ws_ProcessRequest(object sender, ProcessRequestEventArgs e)
        {
            if (Field.dataLoaded)
            {
                try
                {
                    //r.ContentType = "text/html";
                    HttpRequest  req = e.Request;
                    HttpResponse res = e.Response;
                    string       cmd = "", data = "";
                    req.TryGetFirstQueryValue("cmd", out cmd);
                    req.TryGetFirstQueryValue("data", out data);
                    e.Response.IsKeepAlive = false;
                    switch (cmd)
                    {
                    case "btn":
                        Buttons b = Field.button.Find(x => x.code == data);
                        if (b != null)
                        {
                            Machine m = Field.machine.Find(x => x.btnid.Contains("," + b.id + ","));
                            if (m != null)
                            {
                                string no = "";
                                req.TryGetFirstQueryValue("no", out no);
                                switch (b.type)
                                {
                                case 1:         //NotGood
                                    if (no != null && Field.NotGoodl.ContainsKey(no))
                                    {
                                        MessageBox.Show("This is ng button for machine id " + m.id + " and ng is " + Field.NotGoodl[no].name);
                                    }
                                    break;

                                case 2:         //Repair
                                    MessageBox.Show("This is repair button for machine id " + m.id + " and repair is " + no);
                                    break;

                                case 3:         //Downtime
                                    if (no != null)
                                    {
                                        if (no != "12" && !m.downtime && Field.downtimel.ContainsKey(no))
                                        {
                                            string dtname = Field.downtimel[no].name;
                                            int    index  = -1;
                                            if ((index = m.dtLab.FindIndex(x => x == dtname)) == -1)
                                            {
                                                m.dtLab.Add(dtname);
                                                m.dtVal.Add(1);
                                                index = m.dtLab.Count - 1;
                                            }
                                            else
                                            {
                                                m.dtVal[index]++;
                                            }
                                            m.ldname = dtname;
                                            m.iddt   = no;
                                            m.DownTime(true);
                                            Field.help.mHitung(3, m, m.act);
                                            //MessageBox.Show("This is downtime button for machine id " + m.id + " and downtime is " + Field.downtimel[no].name);
                                        }
                                        else if (no == "12")
                                        {
                                            m.DownTime(false);
                                            Field.help.mHitung(3, m, m.act);
                                        }
                                    }
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                        break;

                    case "shift":
                        break;

                    case "reset":
                        //MessageBox.Show(await Field.web.getData(true, "api/indata", "{\"mode\":-1, \"data\":\"\"}"));
                        //Field.resetGateway();
                        Field.getData = false;
                        e.Response.Write("Reseting");
                        Field.resetGateway();
                        Field.setStatus("Reload data ...", false);
                        Field.web.getAllData(true);
                        Field.getData = true;
                        break;

                    case "gdata":
                        if (!Field.mqtt.isConnected)
                        {
                            Field.mqtt.Start();
                        }
                        if (Field.mqtt.isConnected)
                        {
                            JArray ja = new JArray();
                            foreach (Machine m in Field.machine)
                            {
                                ja.Add(JToken.FromObject(m));
                            }
                            e.Response.Write(ja.ToString());
                        }
                        break;

                    case "stop":
                        string no2 = "";
                        req.TryGetFirstQueryValue("id", out no2);
                        Machine m2 = Field.machine.Find(x => x.id.ToString() == no2);
                        if (m2 != null && !Field.statind.Contains(m2))
                        {
                            Field.statind.Add(m2);
                            e.Response.Write("true");
                            return;
                        }
                        e.Response.Write("false");
                        break;

                    case "start":
                        string no3 = "";
                        req.TryGetFirstQueryValue("id", out no3);
                        if (no3 == "all")
                        {
                            Field.statind.Clear();
                            e.Response.Write("true");
                            return;
                        }
                        else
                        {
                            int m3 = Field.statind.FindIndex(x => x.id.ToString() == no3);
                            if (m3 > -1)
                            {
                                Field.statind.RemoveAt(m3);
                                e.Response.Write("true");
                                return;
                            }
                        }
                        e.Response.Write("false");
                        break;

                    default:
                        e.Response.ContentType = "text/html";
                        e.Response.Write("<a href=\"?cmd=reset\"><button>Reset</button></a>");
                        break;
                    }
                }
                catch (Exception ea)
                {
                    MessageBox.Show(ea.Message + "\n" + ea.StackTrace);
                }
            }
        }
Exemple #18
0
 private static void W3s_ProcessRequest(object sender, ProcessRequestEventArgs args)
 {
     // default is text/plain
     args.Response.ContentType = "text/html";
     args.Response.WriteLine("<html><body><h1>Hello World</h1></body>");
 }