コード例 #1
0
ファイル: Program.cs プロジェクト: bookman920/RobotChat
        static void Main()
        {
            //开启控制台监控
            UserFunc.AllocConsole();

            // Create Module manager that handles all modules in the server
            var moduleManager = new ModuleManager();

            // Add the LogicModule
            moduleManager.Add(new CommOfWebModule());
            // Start the WebServer.
            server = new HttpServer(moduleManager);
            server.Start(IPAddress.Any, 9988);
            Console.WriteLine("WebServer Listened On PORT " + server.LocalPort);

            //开启任务队列
            new Thread(delegate() {
                while (StopService == false)
                {
                    try
                    {
                        if (QueueWorker != null)
                        {
                            PacketOfWeb data = QueueWorker.Remove();
                            if (data != null)
                            {
                                data.SyncOper();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }

                QueueWorker.Release();
            }).Start();

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new frmMainForm());

            //关闭线程服务
            StopService = true;

            //End the WebServer
            server.Stop();

            //关闭控制台
            UserFunc.FreeConsole();
        }
コード例 #2
0
        public ModuleResult HandleRequest(IHttpContext context)
        {
            if (context.Request.HttpMethod.Equals("GET", StringComparison.OrdinalIgnoreCase))
            {//Get
                Match getAct = (new Regex("act=(\\d+)")).Match(context.Request.Uri.Query);
                if (getAct.Groups.Count > 1)
                {
                    int aNo = 0;
                    int.TryParse(getAct.Groups[1].Value, out aNo);
                    if (aNo > 0)
                    {
                        PacketOfWeb pac = PacketOfWeb.FactoryOfPacket(aNo);

                        //执行异步操作并返回结果
                        var sb = new StringBuilder();
                        sb.Append(pac.Analyze(context).Execute());
                        context.Response.Body = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString()));
                        context.Response.AddHeader("Content-Type", "application/json");
                        context.Response.AddHeader("Access-Control-Allow-Origin", "*");

                        //执行同步操作
                        Program.QueueWorker.Push(pac);
                    }
                }
                else
                {
                    var sb = new StringBuilder();
                    sb.Append(string.Format(@"
                        <img style='-webkit-user-select:none' src='{0}'><br/>
                        <form action='http://*****:*****@"
                        <form action='http://*****:*****@"
                            <form action='http://*****:*****@"
                            <form action='http://*****:*****@"
                            <form action='http://*****:*****@"
                        <form action='http://localhost:9988' method='get'>
                            <input type='hidden' name='act' value='1005' /><input type='text' name='content' value={0} /><input type = 'submit' value = '删除' />
                        </form>
                        ", word));
                        return(true);
                    });
                    context.Response.Body = new MemoryStream(Encoding.UTF8.GetBytes(sb.ToString()));
                    context.Response.AddHeader("Content-Type", "text/html");
                }
            }
            else   //Post
                   //todo
            {
            }

            return(ModuleResult.Continue);
        }