writeSuccess() public method

public writeSuccess ( ) : void
return void
示例#1
0
		private void Deal(HttpProcessor p,string url, string data,bool isGet){
			if(url==null){
				return;
			}
			if(url=="/"||url.StartsWith("/room.php")||url.StartsWith("/room.json")){
				//房间列表
				p.writeSuccess();
				p.outputStream.Write(GetContent(url, data));
			}else if(url.StartsWith("/deck.php")){
				//卡片列表
				if(data.IndexOf("pwd=caicai")<0){
					p.writeFailure();
					return;
				}
				p.writeSuccess();
				string[] args = data.Split('&');
				foreach(string a in args){
					if(a != null && a.StartsWith("name=")){
						int i = a.IndexOf("=");
						if(i>=0 && i< a.Length-1){
							string name = a.Substring(i+1);
							List<int> cards = GameManager.GameCards(name);
							foreach(int id in cards){
								p.outputStream.WriteLine(""+id);
							}
						}
					}
				}
			}
			else{
				p.writeFailure();
			}
		}
示例#2
0
        public override void handleGETRequest(HttpProcessor p)
        {
            string urlText = p.http_url;

            int pos = urlText.IndexOf("&");
            if (pos != -1)
            {
                urlText = urlText.Substring(0, pos);
            }

            if (urlText.EndsWith("/getSnapshot") == true)
            {
                p.writeSuccess("application/json");
                p.outputStream.Write(_document.SnapshotText);
            }
            else if (urlText.Contains("/setSlide/") == true)
            {
                string txt = urlText.Substring(urlText.LastIndexOf('/') + 1);

                int slide;
                if (Int32.TryParse(txt, out slide) == true)
                {
                    _document.SetCurrentSlide(slide);
                }

                p.writeSuccess("text/html");
                p.outputStream.Write("OK");
            }
            else if (urlText.Contains("/startShow/") == true)
            {
                string txt = urlText.Substring(urlText.LastIndexOf('/') + 1);

                int slide;
                if (Int32.TryParse(txt, out slide) == true)
                {
                    _document.StartShow(slide);
                }

                p.writeSuccess("text/html");
                p.outputStream.Write("OK");
            }
            else if (urlText.Contains("/startShow") == true)
            {
                _document.StartShow(1);
                p.writeSuccess("text/html");
                p.outputStream.Write("OK");
            }
            else if (urlText.Contains("/nextAnimation") == true)
            {
                _document.NextAnimation();
                p.writeSuccess("text/html");
                p.outputStream.Write("OK");
            }
        }
        public override void handleGETRequest(HttpProcessor p)
        {
            if (p.http_url.Equals("/Test.png"))
            {
                Stream fs = File.Open("../../Test.png", FileMode.Open);

                p.writeSuccess("image/png");
                fs.CopyTo(p.outputStream.BaseStream);
                p.outputStream.BaseStream.Flush();
            }
            var buf_data = p.http_url.Split('=');

            string token    = "";
            string username = "";

            if (buf_data[0] == "/?user_name")
            {
                token = buf_data[2].ToString();
                Console.WriteLine("token: " + token);

                int index = buf_data[1].IndexOf("&");
                if (index > 0)
                {
                    username = buf_data[1].Substring(0, index);
                }
                Console.WriteLine("username: "******"update btk.Users set user_token='"+token+"' where username='******';");
                //// объект для выполнения SQL-запроса
                //MySqlCommand command = new MySqlCommand(sql, conn);
                //// объект для чтения ответа сервера
                //MySqlDataReader reader = command.ExecuteReader();
                //reader.Close();
                //conn.Close();
            }


            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
            p.outputStream.WriteLine("url : {0}", p.http_url);

            p.outputStream.WriteLine("<form method=post action=/form>");
            p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            p.outputStream.WriteLine("</form>");
        }
示例#4
0
        public override void handleGETRequest(HttpProcessor processor)
        {
            Console.WriteLine("--GET REQUEST BEGIN--");
            Console.WriteLine("Request:\n\t" + processor.http_url);
            Console.WriteLine("Parameter:");

            Console.WriteLine("\nSearching Handler..");
            foreach (ITaskReciverPlugin cmd in pluginLoader.LoadedPlugins)
            {
                if (processor.http_url.StartsWith(cmd.CommandTrigger))
                {
                    Console.Write(" Found!");

                    List<Tuple<string, string>> param = new List<Tuple<string,string>>();

                    param = GetParams(processor.http_url, cmd.CommandTrigger);

                    param.ForEach(x => Console.WriteLine("\t" + x.Item1 + " = " + ((x.Item2 == "") ? "no value" : x.Item2)));

                    Console.WriteLine("Executing!");
                    Console.WriteLine("--GET REQUEST END--\n");

                    cmd.Execute(param);
                    processor.writeSuccess();
                    return;
                }
            }

            processor.writeFailure();
            Console.Write(" Non Found :(");
            Console.WriteLine("--GET REQUEST END--\n");
        }
        public override void handleGETRequest(HttpProcessor p)
        {
            Log.Write("request: " + p.http_url);

            string result = "";

            if (p.http_url == "/GetVolumeSerialNumber")
            {
                var license = ((Bend.Util.MyHttpServer)p.srv).license;

                result = license.GetVolumeSerialNumber();
            }
            else if (p.http_url == "/GetAd")
            {
                var license = ((Bend.Util.MyHttpServer)p.srv).license;

                foreach (var a in license.ads)
                {
                    result += a;
                }
            }

            p.writeSuccess();
            p.outputStream.WriteLine(result);
        }
示例#6
0
        public override void handleGETRequest(HttpProcessor p)
        {
            Console.WriteLine("request: {0}", p.http_url);
            p.writeSuccess();

            //p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            //p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
            //p.outputStream.WriteLine("url : {0}", p.http_url);

            //p.outputStream.WriteLine("<form method=post action=/form>");
            //p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            //p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            //p.outputStream.WriteLine("</form>");

            if (p.http_url.Contains("www"))
            {
                string appPath = Path.GetDirectoryName(Application.ExecutablePath);
                string fileName = appPath + "/" + p.http_url.Substring(p.http_url.IndexOf("www"));
                FileInfo fi = new FileInfo(fileName);
                using (StreamReader sr = new StreamReader(fi.OpenRead()))
                {
                    p.outputStream.Write(sr.ReadToEnd());
                }
            }
            else
            {
                System.Web.Script.Serialization.JavaScriptSerializer j = new System.Web.Script.Serialization.JavaScriptSerializer();

                p.outputStream.WriteLine(j.Serialize(Temps));
            }
        }
示例#7
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            Console.WriteLine("POST request: {0}", p.http_url);
            string rawBody = inputData.ReadToEnd();

            // Consume the POST request only if it's a webhook notification
            if ("/webhook".Equals(p.http_url))
            {
                JavaScriptSerializer serializer = new JavaScriptSerializer();
                dynamic jsonDict = serializer.DeserializeObject(rawBody);

                if (jsonDict.ContainsKey("number") && jsonDict.ContainsKey("message"))
                {
                    string usrNumber  = jsonDict["number"];
                    string usrMessage = jsonDict["message"];

                    Console.WriteLine("Received a valid webhook notification!");
                    handleUserMessageRecevied(usrNumber, usrMessage);
                }
                else
                {
                    Console.WriteLine("Received an INVALID webhook notification: " + rawBody);
                }
            }

            // Return 200 OK no mater what.
            p.writeSuccess();
            p.outputStream.WriteLine("Done");
        }
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            MoaLog.Debug(String.Format("POST request: {0}", p.http_url));
            string data = inputData.ReadToEnd();

            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("<a href=/test>return</a><p>");
            p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data);
        }
        public override void handleGETRequest(HttpProcessor p)
        {
            string wantedUrl = p.http_url;


            string[] splittenUrl = wantedUrl.Split('/');
            string   action      = splittenUrl[1];

            if (String.Equals(action, "space",
                              StringComparison.OrdinalIgnoreCase))
            {
                p.writeSuccess();
                p.outputStream.WriteLine("SPACE");
                SendKeys.SendWait(" ");
            }
            else if (String.Equals(action, "back",
                                   StringComparison.OrdinalIgnoreCase))
            {
                p.writeSuccess();
                p.outputStream.WriteLine("back");
                SendKeys.SendWait("{LEFT} {LEFT} {LEFT} {LEFT} {LEFT}");
            }
            else if (String.Equals(action, "forward",
                                   StringComparison.OrdinalIgnoreCase))
            {
                p.writeSuccess();
                p.outputStream.WriteLine("forward");
                SendKeys.SendWait("{RIGHT} {RIGHT} {RIGHT} {RIGHT} {RIGHT}");
            }


            /*
             * Console.WriteLine("request: {0}", p.http_url);
             * p.writeSuccess();
             * p.outputStream.WriteLine("<html><body><h1>test server</h1>");
             * p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
             * p.outputStream.WriteLine("url : {0}", p.http_url);
             *
             * p.outputStream.WriteLine("<form method=post action=/form>");
             * p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
             * p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
             * p.outputStream.WriteLine("</form>");*/
        }
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            Console.WriteLine("POST request: {0}", p.http_url);
            string data = inputData.ReadToEnd();

            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("<a href=/test>return</a><p>");
            p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data);
        }
示例#11
0
 public override void handleGETRequest(HttpProcessor p)
 {
     p.writeSuccess();
     p.outputStream.WriteLine("<html><body><h1>test server</h1>");
     p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
     p.outputStream.WriteLine("url : {0}", p.http_url);
     p.outputStream.WriteLine("<form method=post action=/form>");
     p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
     p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
     p.outputStream.WriteLine("</form>");
 }
示例#12
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            Console.WriteLine("POST request: {0}", p.http_url);
            string data = inputData.ReadToEnd();

            //Console.WriteLine(data);
            //Console.ReadLine();

            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>This is a test server that gets JSON and makes it browser ready</h1>");
            p.outputStream.WriteLine("Tolerances: <pre>{0}</pre>", data);
            ////HttpContext.Current.Response.Redirect("http://localhost:8080/testpage");
        }
        public override void handleGETRequest(HttpProcessor p)
        {
            if (p.http_url.Equals("/Test.png"))
            {
                Stream fs = File.Open("../../Test.png", FileMode.Open);

                p.writeSuccess("image/png");
                fs.CopyTo(p.outputStream.BaseStream);
                p.outputStream.BaseStream.Flush();
            }

            MoaLog.Debug(String.Format("request: {0}", p.http_url));
            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
            p.outputStream.WriteLine("url : {0}", p.http_url);

            p.outputStream.WriteLine("<form method=post action=/form>");
            p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            p.outputStream.WriteLine("</form>");
        }
示例#14
0
        public override void handleGETRequest(HttpProcessor p)
        {
            if (p.http_url.Equals("/Test.png"))
            {
                Stream fs = File.Open("../../Test.png", FileMode.Open);

                p.writeSuccess("image/png");
                fs.CopyTo(p.outputStream.BaseStream);
                p.outputStream.BaseStream.Flush();
            }

            Console.WriteLine("request: {0}", p.http_url);
            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
            p.outputStream.WriteLine("url : {0}", p.http_url);

            p.outputStream.WriteLine("<form method=post action=/form>");
            p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            p.outputStream.WriteLine("</form>");
        }
示例#15
0
        public override void handleGETRequest(HttpProcessor p)
        {
            if (p.http_url == "/")
            {
                p.http_url = "/index.html";
            }
            Console.WriteLine("request: {0}", p.http_url);
            Console.WriteLine(Directory.GetCurrentDirectory());
            int        nBytes = 2048;
            FileStream fs;

            try
            {
                if (p.http_url.Split('/')[1] == "Files")
                {
                    fs = new FileStream(Directory.GetCurrentDirectory() + p.http_url, FileMode.Open, FileAccess.Read);
                    p.writeSuccessRar("", fs.Length, @"application/x-rar-compressed, application/octet-stream");
                    while (true)
                    {
                        byte[] ByteArray  = new byte[nBytes];
                        int    nBytesRead = fs.Read(ByteArray, 0, nBytes);
                        if (nBytesRead == 0)
                        {
                            break;
                        }
                        p.outputStream.BaseStream.Write(ByteArray, 0, ByteArray.Length);
                    }

                    fs.Close();
                }
                else
                {
                    p.writeSuccess();
                    p.outputStream.Write(@"<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>
<html><meta charset='utf-8'><head><title></title></head>
");
                    if (!p.isAuth())
                    {
                        p.printAuth();
                        return;
                    }
                    p.outputStream.Write(@"<body>");
                    PrintTable(p);
                }
            }
            catch (Exception ex)
            {
                p.outputStream.WriteLine("404 - файл " + p.http_url + " не найден.<br>" + ex.Message);
                Console.WriteLine("404 - файл " + p.http_url + " не найден.<br>" + ex.Message);
            }
        }
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            Console.WriteLine("POST request: {0}", p.http_url);
            var stopWatch = new Stopwatch();
            stopWatch.Start();

            string data = inputData.ReadToEnd();
            var board = JsonConvert.DeserializeObject<DynaShipBoard>(data);
            var response = new DynaShipAI(board).Process();
            p.writeSuccess("application/json");
            p.outputStream.Write(String.Format("{{\"x\": {0}, \"y\": {1}}}", response.X, response.Y));

            stopWatch.Stop();
            Console.WriteLine("Time taken: " + stopWatch.Elapsed);
        }
示例#17
0
        public override void handleGETRequest(HttpProcessor p)
        {
            Console.WriteLine("request: {0}", p.http_url);
            p.writeSuccess();

            string callback = String.Empty;
            this.setData(ParseParameters(p.http_url, out callback));

            try
            {
                p.outputStream.WriteLine(callback + "(\"OK\")");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}", ex.Message);
            }
        }
示例#18
0
        public override void handleGETRequest(HttpProcessor p)
        {
            Console.WriteLine("request: {0}", p.http_url);
            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
            p.outputStream.WriteLine("url : {0}", p.http_url);

            MyScale sc = new MyScale();

            sc.initScale();
            p.outputStream.WriteLine("SCALE: " + sc.readScale());
            sc.stopScale();

            p.outputStream.WriteLine("Hello - <form method=post action=/form>");
            p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            p.outputStream.WriteLine("</form>");
        }
        public override void handleGETRequest(HttpProcessor p)
        {
            Console.WriteLine("request: {0}", p.http_url);
            p.writeSuccess();

            /*
             * p.outputStream.WriteLine("<html><body><h1>test server</h1>");
             * p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
             * p.outputStream.WriteLine("url : {0}", p.http_url);
             *
             * p.outputStream.WriteLine("<form method=post action=/form>");
             * p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
             * p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
             * p.outputStream.WriteLine("</form>");
             * */
            HttpRequest hr   = new HttpRequest();
            string      html = HttpUtility.HtmlDecode(hr.httpRepuest(p.http_url));

            p.outputStream.WriteLine(html);
        }
示例#20
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            Console.WriteLine("POST request: {0}", p.http_url);
            string data = inputData.ReadToEnd();

            p.writeSuccess();

            String[] args = data.Split('&');
            Dictionary<String, String> act_args = new Dictionary<string, string>();
            foreach (String s in args)
            {
                String[] arg_pair = s.Split('=');
                act_args[arg_pair[0]] = arg_pair[1];
            }

            bool success = false;

            if (p.http_url.Equals("/vote/index.csh"))
            {
                String user = act_args["user"];
                String pass = act_args["pw"];
                String md5pass = Util.getMD5Hash(pass);
                int uid = Convert.ToInt32(act_args["uid"]);

                success = pl.vote(uid, um.getUser(user, md5pass));

                p.outputStream.WriteLine("<h1>Vote aftersite</h1>");
                p.outputStream.WriteLine("<a href=/vote/vote.csh>Vote was {0}</a><p>", (success) ? "successfull" : "not successfull");
            }
            else if (p.http_url.Equals("/vote/pass.csh"))
            {
                Dictionary<String, String> vars_to_pass = new Dictionary<string,string>();
                vars_to_pass["UID"] = act_args["uid"];

                openFile("/vote/pass.csh", p.outputStream, vars_to_pass);
            }

            //p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data);
        }
示例#21
0
文件: Server.cs 项目: bi-tm/openABAP
 public override void handleGETRequest(HttpProcessor p)
 {
     Console.WriteLine ("request: {0}", p.http_url);
     if (p.http_url.Equals ("/")) {
         // return form
         WriteForm (p);
     } else {
         //return static file
         try {
             FileInfo f = new FileInfo(p.http_url.TrimStart('/'));
             if (f.Exists) {
                 StreamReader s = new StreamReader(f.FullName);
                 p.writeSuccess();
                 p.outputStream.Write(s.ReadToEnd());
             } else {
                 p.writeFailure();
             }
         } catch(Exception e) {
             p.writeFailure();
         }
     }
 }
示例#22
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            var license = ((Bend.Util.MyHttpServer)p.srv).license;

            Log.Write("request: " + p.http_url);

            string data = inputData.ReadToEnd();

            Log.Write("data: " + data);

            string connectPort = "COM1";

            if (p.httpHeaders["Port"] != null)
            {
                connectPort = p.httpHeaders["Port"].ToString();
            }

            string connectBaudrate = "115200";

            if (p.httpHeaders["Baudrate"] != null)
            {
                connectBaudrate = p.httpHeaders["Baudrate"].ToString();
            }

            string readTimeout = "";

            if (p.httpHeaders["ReadTimeout"] == null)
            {
                readTimeout = p.httpHeaders["ReadTimeout"].ToString();
            }

            string result = Command.Exec(data, connectPort, connectBaudrate, readTimeout, license);

            Log.Write("result: " + result);

            p.writeSuccess();
            p.outputStream.WriteLine(result);
        }
示例#23
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            string data = inputData.ReadToEnd();

            Console.WriteLine("POST request: {0}", data);

            var   regex = new Regex(@"<cert>(?<certificate_path>.+?)</cert><privkey>(?<private_key_path>.+?)</privkey><sign_type>(?<sign_type>.+?)</sign_type><value>(?<value>.+?)</value>");
            Match match = regex.Match(data);

            string cert      = match.Groups["certificate_path"].Value;
            string privkey   = match.Groups["private_key_path"].Value;
            string sign_type = match.Groups["sign_type"].Value;
            string value     = match.Groups["value"].Value;


            Console.WriteLine("cert: {0}", cert);
            Console.WriteLine("privkey: {0}", privkey);
            Console.WriteLine("sign_type: {0}", sign_type);
            Console.WriteLine("value: {0}", value);

            string response = null;

            if (sign_type.Equals("auth"))
            {
                response = Signer.Program.SignAuthToken(cert, privkey, value);
            }

            if (sign_type.Equals("file"))
            {
                response = Signer.Program.SignFile(cert, privkey, value);
            }


            p.writeSuccess();


            p.outputStream.WriteLine("<signed>{0}</signed>", response);
        }
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            string data = inputData.ReadToEnd();
            char[] delimiterChars = { ' ', ',', '.', ':', '\t', '=' };

            // 取得 Post 傳入值 name=機器名 的第二個參數(也就是機器名)
            string[] reqwords = data.Split(delimiterChars);
            string classname = reqwords[1];

            if (shouldBeShutdown(p, classname))
            {
                Console.WriteLine("{0} 連入伺服器:傳送關機訊號。   {1}", classname, DateTime.Now.ToString());
                p.outputStream.WriteLine("shutdown");
            }
            else
            {
                Console.WriteLine("{0} 連入伺服器:狀態正常。   {1}", classname, DateTime.Now.ToString());
                p.outputStream.WriteLine("boot");
            }

            p.writeSuccess();
        }
示例#25
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            Console.WriteLine("POST request: {0}", p.http_url);
            string      data = inputData.ReadToEnd();
            XmlDocument Doc  = new XmlDocument();

            Doc.LoadXml(data);
            XmlNodeList elemList  = Doc.GetElementsByTagName("title");
            string      titleData = elemList[0].InnerXml;

            elemList = Doc.GetElementsByTagName("subtitle");
            string subtitleData = elemList[0].InnerXml;

            elemList = Doc.GetElementsByTagName("owner");
            string ownerData = elemList[0].InnerXml;

            elemList = Doc.GetElementsByTagName("Location");
            string location = elemList[0].InnerXml;

            elemList = Doc.GetElementsByTagName("manufacturer");
            string manufacturerData = elemList[0].InnerXml;

            elemList = Doc.GetElementsByTagName("description");
            string descriptionData = elemList[0].InnerXml;



            elemList = Doc.GetElementsByTagName("ageID");
            int ageID = Convert.ToInt32(elemList[0].InnerXml);



            elemList = Doc.GetElementsByTagName("uploaderID");
            int uploaderID = Convert.ToInt32(elemList[0].InnerXml);

            elemList = Doc.GetElementsByTagName("categoryID");
            int categoryID = Convert.ToInt32(elemList[0].InnerXml);

            string        activeDir;
            string        type            = "threedobject";
            string        connetionString = null;
            SqlConnection cnn;

            connetionString = "Data Source=192.168.35.244;Initial Catalog=ddwdb;Integrated Security=False;User ID=HttpServer;Password=Welkom01";
            cnn             = new SqlConnection(connetionString);
            try
            {
                cnn.Open();
                Console.WriteLine("Connection Open ! ");
                if (type == "threedobject")
                {
                    elemList = Doc.GetElementsByTagName("dimensions");
                    string dimensionsData = elemList[0].InnerXml;

                    elemList = Doc.GetElementsByTagName("material");
                    string materialData = elemList[0].InnerXml;

                    elemList = Doc.GetElementsByTagName("textureID");
                    int textureID = Convert.ToInt32(elemList[0].InnerXml);


                    elemList = Doc.GetElementsByTagName("weightID");
                    int weightID = Convert.ToInt32(elemList[0].InnerXml);

                    elemList = Doc.GetElementsByTagName("shapeID");
                    int shapeID = Convert.ToInt32(elemList[0].InnerXml);

                    elemList = Doc.GetElementsByTagName("color");
                    string colorData = elemList[0].InnerXml;
                    using (SqlCommand cmd = new SqlCommand("dbo.3Dobject_Add", cnn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        // set up the parameters
                        cmd.Parameters.Add("@ModelID", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@Title", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@SubTitle", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@DateTimeO", SqlDbType.DateTime);
                        cmd.Parameters.Add("@Location", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Owner", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Manufacturer", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Description", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Quantity", SqlDbType.Int);
                        cmd.Parameters.Add("@Dimensions", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Material", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Color", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Category_ID", SqlDbType.Int);
                        cmd.Parameters.Add("@Uploader_ID", SqlDbType.Int);
                        cmd.Parameters.Add("@Texture_ID", SqlDbType.Int);
                        cmd.Parameters.Add("@Age_ID", SqlDbType.Int);
                        cmd.Parameters.Add("@Weight_ID", SqlDbType.Int);
                        cmd.Parameters.Add("@ShapeID", SqlDbType.Int);

                        cmd.Parameters["@Title"].Value        = titleData;
                        cmd.Parameters["@SubTitle"].Value     = subtitleData;
                        cmd.Parameters["@DateTimeO"].Value    = DateTime.Now;
                        cmd.Parameters["@Location"].Value     = location;
                        cmd.Parameters["@Owner"].Value        = ownerData;
                        cmd.Parameters["@Manufacturer"].Value = manufacturerData;
                        cmd.Parameters["@Description"].Value  = descriptionData;
                        cmd.Parameters["@Quantity"].Value     = 5;
                        cmd.Parameters["@Dimensions"].Value   = dimensionsData;
                        cmd.Parameters["@Material"].Value     = materialData;
                        cmd.Parameters["@Color"].Value        = colorData;
                        cmd.Parameters["@Category_ID"].Value  = categoryID;
                        cmd.Parameters["@Uploader_ID"].Value  = uploaderID;
                        cmd.Parameters["@Texture_ID"].Value   = textureID;
                        cmd.Parameters["@Age_ID"].Value       = ageID;
                        cmd.Parameters["@Weight_ID"].Value    = weightID;
                        cmd.Parameters["@ShapeID"].Value      = shapeID;

                        cmd.ExecuteNonQuery();
                        int idFromServer = Convert.ToInt32(cmd.Parameters["@ModelID"].Value);
                        Console.WriteLine("Insert executed successfully " + idFromServer.ToString());

                        // open connection and execute stored procedure
                        cnn.Close();


                        activeDir = @"D:\FontysFactory\3DObjects";
                        string newPath = System.IO.Path.Combine(activeDir, Convert.ToString(idFromServer));
                        System.IO.Directory.CreateDirectory(newPath);
                        string path    = activeDir;
                        string folder1 = path.Substring(path.LastIndexOf("\\") + 1);
                        path = path.Remove(path.LastIndexOf("\\"));
                        string folder2 = path.Substring(path.LastIndexOf("\\") + 1);
                        string result  = System.IO.Path.Combine(folder2, idFromServer.ToString());
                        Console.WriteLine(result);
                        p.writeSuccess();
                        p.outputStream.WriteLine(result);
                    }
                }
                else
                {
                    elemList = Doc.GetElementsByTagName("extension");
                    string extension = elemList[0].InnerXml;
                    using (SqlCommand cmd = new SqlCommand("dbo.OtherObject_Add", cnn))
                    {
                        cmd.CommandType = CommandType.StoredProcedure;

                        // set up the parameters
                        cmd.Parameters.Add("@ObjectID", SqlDbType.Int).Direction = ParameterDirection.Output;
                        cmd.Parameters.Add("@Title", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@SubTitle", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@DateTimeO", SqlDbType.DateTime);
                        cmd.Parameters.Add("@Location", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Owner", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Manufacturer", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Description", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Quantity", SqlDbType.Int);
                        cmd.Parameters.Add("@Extension", SqlDbType.VarChar, -1);
                        cmd.Parameters.Add("@Age_ID", SqlDbType.Int);
                        cmd.Parameters.Add("@Category_ID", SqlDbType.Int);
                        cmd.Parameters.Add("@Uploader_ID", SqlDbType.Int);


                        cmd.Parameters["@Title"].Value        = titleData;
                        cmd.Parameters["@SubTitle"].Value     = subtitleData;
                        cmd.Parameters["@DateTimeO"].Value    = DateTime.Now;
                        cmd.Parameters["@Location"].Value     = location;
                        cmd.Parameters["@Owner"].Value        = ownerData;
                        cmd.Parameters["@Manufacturer"].Value = manufacturerData;
                        cmd.Parameters["@Description"].Value  = descriptionData;
                        cmd.Parameters["@Quantity"].Value     = 5;
                        cmd.Parameters["@Extension"].Value    = extension;
                        cmd.Parameters["@Age_ID"].Value       = ageID;
                        cmd.Parameters["@Category_ID"].Value  = categoryID;
                        cmd.Parameters["@Uploader_ID"].Value  = uploaderID;


                        cmd.ExecuteNonQuery();
                        int idFromServer = Convert.ToInt32(cmd.Parameters["@ObjectID"].Value);
                        Console.WriteLine("Insert executed successfully " + idFromServer.ToString());

                        // open connection and execute stored procedure
                        cnn.Close();


                        activeDir = @"D:\FontysFactory\OtherObjects";
                        string newPath = System.IO.Path.Combine(activeDir, Convert.ToString(idFromServer));
                        System.IO.Directory.CreateDirectory(newPath);
                        string path    = activeDir;
                        string folder1 = path.Substring(path.LastIndexOf("\\") + 1);
                        path = path.Remove(path.LastIndexOf("\\"));
                        string folder2 = path.Substring(path.LastIndexOf("\\") + 1);
                        string result  = System.IO.Path.Combine(folder1, idFromServer.ToString());
                        Console.WriteLine(result);
                        p.writeSuccess();
                        p.outputStream.WriteLine(result);
                    }
                }
                cnn.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                p.writeFailure();
            }
        }
        public override void handleGETRequest(HttpProcessor p)
        {
            Console.WriteLine("request: {0}", p.http_url);
            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
            p.outputStream.WriteLine("url : {0}", p.http_url);

            MyScale sc = new MyScale();
            sc.initScale();
            p.outputStream.WriteLine("SCALE: "+sc.readScale());
            sc.stopScale();

            p.outputStream.WriteLine("Hello - <form method=post action=/form>");
            p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            p.outputStream.WriteLine("</form>");
        }
示例#27
0
        public override void handleGETRequest(HttpProcessor p)
        {
            Console.WriteLine("request: {0}", p.http_url);

            EndPoint ep = p.socket.Client.RemoteEndPoint;
            if (ep.AddressFamily == AddressFamily.InterNetwork) {
                Console.WriteLine("Address: {0}",ep.ToString());
            }
            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
            p.outputStream.WriteLine("url : {0}", p.http_url);

            p.outputStream.WriteLine("<form method=post action=/form>");
            p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            p.outputStream.WriteLine("</form>");
        }
示例#28
0
        public override void handleGETRequest(HttpProcessor p)
        {
            if (p.http_url.Equals ("/Test.png")) {
                Stream fs = File.Open("../../Test.png",FileMode.Open);

                p.writeSuccess("image/png",fs.Length);
                p.outputStream.Flush();
                fs.CopyTo (p.outputStream.BaseStream);
                p.outputStream.BaseStream.Flush ();
                fs.Close();
                return;
            }

            if (p.http_url.StartsWith ("/m3u8")) {
                string path = "http://scgd-m3u8.joyseetv.com:10009";
                path += p.http_url;
                path += GenKey();

                if (p.http_url == pid && DateTime.Now.Subtract(lastQueryTime).TotalSeconds < 10)
                    {
                        p.writeSuccess("application/vnd.apple.mpegurl", length);
                        p.outputStream.Flush();
                        Stream fs2= new MemoryStream(copyfsbytes, 0, (int)length);
                        fs2.CopyTo(p.outputStream.BaseStream);
                        p.outputStream.BaseStream.Flush();
                    fs2.Close();

                    Console.WriteLine("1:"+lastQueryTime + DateTime.Now);
                    return;
                }
                else
                {
                    copyfsbytes = new byte[5000];

                }

                    pid = p.http_url;
                    lastQueryTime = DateTime.Now;
                    Console.WriteLine("2:" + lastQueryTime + DateTime.Now);

                // The downloaded resource ends up in the variable named content.

                // Initialize an HttpWebRequest for the current URL.
                var webReq = (HttpWebRequest)WebRequest.Create(path);

                webReq.UserAgent = "Android/TVPlayerSDK/1.0";
                WebResponse response = webReq.GetResponse();
                Stream fs = webReq.GetResponse().GetResponseStream();
                fs.Read(copyfsbytes, 0, (int)response.ContentLength);
                fs = new MemoryStream(copyfsbytes,0, (int)response.ContentLength);
                length = response.ContentLength;

                p.writeSuccess("application/vnd.apple.mpegurl", response.ContentLength);
                p.outputStream.Flush();
                fs.CopyTo (p.outputStream.BaseStream);
                p.outputStream.BaseStream.Flush ();
                fs.Close();
                return;
            }

            Console.WriteLine("request: {0}", p.http_url);
            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
            p.outputStream.WriteLine("url : {0}", p.http_url);

            p.outputStream.WriteLine("<form method=post action=/form>");
            p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            p.outputStream.WriteLine("</form>");
        }
示例#29
0
        private void LandingPage(HttpProcessor p)
        {
            p.writeSuccess();
            Stream fs = File.Open("../../../html/index.html", FileMode.Open);
            StreamReader reader = new StreamReader(fs);
            string html = reader.ReadToEnd();
            fs.Close();

            html = html.Replace("#UTTERANCE#", lastrequest);

            string addString;
            addString = "";
            foreach (string s in Targets) addString += htmlListElement(s);
            html = html.Replace("#TARGETS#", addString);

            addString = "";
            foreach (string s in Instructions) addString += htmlListElement(s);
            html = html.Replace("#INSTRUCTIONS#", addString);

            
    
            /*p.outputStream.WriteLine("<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>");
            p.outputStream.WriteLine("<html xmlns=/'http://www.w3.org/1999/xhtml'>");
            p.outputStream.WriteLine("<head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /><title>EMOTE Utterance Tester</title></head><body>");
            p.outputStream.WriteLine("<form name='input' action='performUtterance' method='post'><textarea type='text' name='utterance' rows='10' cols='150'>" + lastrequest + "</textarea><br><input type='submit' value='Perform'></form><br>");

            p.outputStream.WriteLine("Available Targets:<br>");
            foreach (string s in Targets) p.outputStream.WriteLine(s + "<br>");

            p.outputStream.WriteLine("</body></html>");*/
            p.outputStream.WriteLine(html);
            p.outputStream.BaseStream.Flush();   
        }
示例#30
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData)
        {
            //这是回写的数据
            HashMap responseObj  = new HashMap();
            HashMap responseData = new HashMap();


            Console.WriteLine("POST request: {0}", p.http_url);
            string data = inputData.ReadToEnd();
            //这是来自客户端POST的数据,UTF8编码

            String bodyData = HttpUtility.UrlDecode(data, Encoding.UTF8);
            //这是解码后的数据


            int    errorCode    = -1;
            String errorMessage = "";

            String serviceType = "";

            try
            {
                HashMap requestObj = JsonConvert.DeserializeObject <HashMap>(bodyData);


                if (requestObj == null)
                {
                    errorCode = -1;
                    throw new Exception("解析到了空的HashMap对象");
                }

                if (!requestObj.ContainsKey("key"))
                {
                    errorCode = -1;
                    throw new Exception("未能找到注册的服务类型KEY");
                }
                serviceType = requestObj["key"].ToString();
                if (String.IsNullOrEmpty(serviceType))
                {
                    errorCode = -1;
                    throw new Exception("传递了空的服务类型");
                }

                switch (serviceType)
                {
                case "printJob":
                    PrintJob job = new PrintJob();
                    job.ProcessPrintJob(bodyData, ref errorCode, ref errorMessage);
                    break;

                case "printerList":
                    List <String> list = Printer.GetLocalPrinters();
                    responseData.Add("printerList", list);
                    errorCode = 0;
                    break;

                default:
                    errorCode = -1;
                    throw new Exception("传递了未知的服务类型");
                }


                responseObj.Add("errorCode", errorCode);
                responseObj.Add("errorMessage", errorMessage);
                responseObj.Add("key", serviceType);

                responseData.Add("queryString", data);
                responseObj.Add("data", responseData);

                String responseText = JsonConvert.SerializeObject(responseObj);
                p.writeSuccess();
                p.outputStream.WriteLine(responseText);
            }
            catch (Exception e)
            {
                errorCode    = -1;
                errorMessage = e.Message;
                Console.WriteLine("SKTHttpEngine处理请求失败,原因为" + e.Message);
            }
        }
示例#31
0
 public override void handleGETRequest(HttpProcessor p)
 {
     p.writeSuccess();
     p.outputStream.WriteLine(IndexModule.content);
 }
示例#32
0
        public override void handlePOSTRequest(HttpProcessor p, StreamReader inputData) {
            Console.WriteLine("POST request: {0}", p.http_url);
            string data = inputData.ReadToEnd();
            StreamWriter sw = new StreamWriter("datei.json");
            sw.Write(data);
            sw.Close();
            Console.WriteLine(data);
            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("<a href=/test>return</a><p>");
            p.outputStream.WriteLine("postbody: <pre>{0}</pre>", data);
            

        }
        public override void handleGETRequest(HttpProcessor p)
        {


            string wantedUrl = p.http_url;


            string[] splittenUrl = wantedUrl.Split('/');
            string action = splittenUrl[1];

            if (String.Equals(action, "space",
                   StringComparison.OrdinalIgnoreCase))
            {
                p.writeSuccess();
                p.outputStream.WriteLine("SPACE");
                SendKeys.SendWait(" ");

            }
            else if (String.Equals(action, "back",
                   StringComparison.OrdinalIgnoreCase))
            {
                p.writeSuccess();
                p.outputStream.WriteLine("back");
                SendKeys.SendWait("{LEFT} {LEFT} {LEFT} {LEFT} {LEFT}");

            }
            else if (String.Equals(action, "forward",
                   StringComparison.OrdinalIgnoreCase))
            {
                p.writeSuccess();
                p.outputStream.WriteLine("forward");
                SendKeys.SendWait("{RIGHT} {RIGHT} {RIGHT} {RIGHT} {RIGHT}");

            }
            
            
            /*
            Console.WriteLine("request: {0}", p.http_url);
            p.writeSuccess();
            p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
            p.outputStream.WriteLine("url : {0}", p.http_url);

            p.outputStream.WriteLine("<form method=post action=/form>");
            p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            p.outputStream.WriteLine("</form>");*/
        }
示例#34
0
 public override void handleGETRequest(HttpProcessor p)
 {
     Console.WriteLine("GET request: {0}", p.http_url);
     p.writeSuccess();
     p.outputStream.WriteLine("Current Time: " + DateTime.Now.ToString());
 }
示例#35
0
        public override void handleGETRequest(HttpProcessor p)
        {
            Console.WriteLine("request: {0}", p.http_url);
            p.writeSuccess();
            /*p.outputStream.WriteLine("<html><body><h1>test server</h1>");
            p.outputStream.WriteLine("Current Time: 오전" + DateTime.Now.ToString());
            p.outputStream.WriteLine("url : {0}", p.http_url);

            p.outputStream.WriteLine("<form method=post action=/form>");
            p.outputStream.WriteLine("<input type=text name=foo value=foovalue>");
            p.outputStream.WriteLine("<input type=submit name=bar value=barvalue>");
            p.outputStream.WriteLine("</form>");*/
            p.outputStream.WriteLine("<data>");
            p.outputStream.WriteLine("<array1>2");
            p.outputStream.WriteLine("</array1>");
            p.outputStream.WriteLine("</data>");
        }
 public override void handleGETRequest(HttpProcessor p)
 {
     p.writeSuccess();
     p.outputStream.Write("Use HTTP POST instead");
 }
示例#37
0
        /*
         *  List folder
         *  Get file
         */
        public override void handleGETRequest(HttpProcessor p)
        {
            if (p.http_url.Equals("/"))
            {
                var files = Directory.GetFiles(basepath);

                p.writeSuccess();
                p.outputStream.WriteLine("[ " + String.Join(", ", files.Select(x => "\"" + new FileInfo(x).Name + "\"").ToArray()) + " ]");
                return;
            }
            else
            {
                FileInfo fi = new FileInfo(p.http_url.Substring(1));

                var t = File.OpenRead(basepath + fi.Name);
                p.writeSuccess("text/plain");
                p.outputStream.Flush();
                t.CopyTo(p.outputStream.BaseStream);
                p.outputStream.BaseStream.Flush();
                t.Close();
            }
        }
示例#38
0
文件: Server.cs 项目: bi-tm/openABAP
        private void WriteForm(HttpProcessor p)
        {
            string source = "PROGRAM test.";
            try {
                StreamReader stream = new StreamReader ("Test.abap");
                source = stream.ReadToEnd ();
                stream.Close ();
            } catch (Exception e) {
            }

            p.writeSuccess ();
            p.outputStream.WriteLine ("<html>");
            p.outputStream.WriteLine ("<head>");
            p.outputStream.WriteLine ("<script src=\"client.js\" type=\"text/javascript\"></script>");
            p.outputStream.WriteLine ("</head>");
            p.outputStream.WriteLine ("<body>");
            p.outputStream.WriteLine ("<h1>openABAP</h1>");
            p.outputStream.WriteLine ("<form name=screen method=get action=\"\">");
            p.outputStream.WriteLine ("<textarea name=source cols=120 rows=30>");
            p.outputStream.WriteLine (source);
            p.outputStream.WriteLine ("</textarea>");
            p.outputStream.WriteLine ("<input type=submit name=sy-ucomm value=OK onclick=\"return send();\">");
            p.outputStream.WriteLine ("<br/><textarea name=result cols=120 rows=10 readonly></textarea>");
            p.outputStream.WriteLine ("</form></body></html>");
        }