Exemple #1
0
        internal static bool TestCase()
        {
            using (tcpHttp.tcpServer server = new tcpHttp.tcpServer())
            {
                if (server.Start())
                {
                    fastCSharp.code.cSharp.tcpServer tcpServer = fastCSharp.code.typeAttribute.GetAttribute <fastCSharp.code.cSharp.tcpServer>(typeof(tcpHttp), false, false);
                    System.Text.Encoding             encoding  = System.Text.Encoding.UTF8;
                    string url = "http://" + tcpServer.Host + ":" + tcpServer.Port.toString() + "/";
                    using (tcpHttp.tcpClient client = new tcpHttp.tcpClient())
                        using (fastCSharp.net.webClient webClient = new fastCSharp.net.webClient())
                        {
                            incValue = 0;
                            //TCP调用
                            client.Inc();
                            if (incValue != 1)
                            {
                                return(false);
                            }
                            //HTTP+JSON调用
                            incValue            = 0;
                            webClient.KeepAlive = false;
                            if (webClient.UploadData(url + "Inc", new byte[0]).deSerialize() != web.ajax.Object || incValue != 1)
                            {
                                return(false);
                            }
                            //HTTP+POST调用
                            incValue = 0;
                            if (webClient.UploadValues(url + "Inc", new NameValueCollection()).deSerialize() != web.ajax.Object || incValue != 1)
                            {
                                return(false);
                            }
                            //HTTP+GET调用
                            incValue = 0;
                            if (webClient.DownloadData(url + "Inc").deSerialize() != web.ajax.Object || incValue != 1)
                            {
                                return(false);
                            }

                            client.Set(3);
                            if (incValue != 3)
                            {
                                return(false);
                            }
                            incValue = 0;
                            if (webClient.UploadData(url + "Set", encoding.GetBytes(3.ToJson())).deSerialize() != web.ajax.Object || incValue != 3)
                            {
                                return(false);
                            }
                            //incValue = 0;
                            //if (webClient.UploadValues(url + "Set", fastCSharp.emit.formGetter<.form.Get(new { a = 3 })).deSerialize() != web.ajax.Object || incValue != 3) return false;
                            //incValue = 0;
                            //if (webClient.DownloadData(url + "Set?" + urlQuery.query.Get(new { a = 3 }, encoding)).deSerialize() != web.ajax.Object || incValue != 3) return false;

                            client.Add(2, 3);
                            if (incValue != 5)
                            {
                                return(false);
                            }
                            incValue = 0;
                            if (webClient.UploadData(url + "Add", encoding.GetBytes(fastCSharp.emit.jsonSerializer.ObjectToJson(new { a = 2, b = 3 }))).deSerialize() != web.ajax.Object || incValue != 5)
                            {
                                return(false);
                            }
                            //incValue = 0;
                            //if (webClient.UploadValues(url + "Add", urlQuery.form.Get(new { a = 2, b = 3 })).deSerialize() != web.ajax.Object || incValue != 5) return false;
                            //incValue = 0;
                            //if (webClient.DownloadData(url + "Add?" + urlQuery.query.Get(new { a = 2, b = 3 }, encoding)).deSerialize() != web.ajax.Object || incValue != 5) return false;

                            if (client.inc().Value != 6 || incValue != 6)
                            {
                                return(false);
                            }
                            incValue = 5;
                            if (fastCSharp.emit.jsonParser.Parse <int>(webClient.UploadData(url + "inc", new byte[0]).deSerialize()) != 6 || incValue != 6)
                            {
                                return(false);
                            }
                            incValue = 5;
                            if (fastCSharp.emit.jsonParser.Parse <int>(webClient.UploadValues(url + "inc", new NameValueCollection()).deSerialize()) != 6 || incValue != 6)
                            {
                                return(false);
                            }
                            incValue = 5;
                            if (fastCSharp.emit.jsonParser.Parse <int>(webClient.DownloadData(url + "inc").deSerialize()) != 6 || incValue != 6)
                            {
                                return(false);
                            }

                            if (client.inc(8).Value != 9)
                            {
                                return(false);
                            }
                            if (fastCSharp.emit.jsonParser.Parse <int>(webClient.UploadData(url + "inc1", encoding.GetBytes(8.ToJson())).deSerialize()) != 9)
                            {
                                return(false);
                            }
                            //if (webClient.UploadValues(url + "inc1", urlQuery.form.Get(new { a = 8 })).deSerialize() != "9") return false;
                            //if (webClient.DownloadData(url + "inc1?" + urlQuery.query.Get(new { a = 8 }, encoding)).deSerialize() != "9") return false;

                            if (client.add(10, 13).Value != 23)
                            {
                                return(false);
                            }
                            if (fastCSharp.emit.jsonParser.Parse <int>(webClient.UploadData(url + "add", encoding.GetBytes(fastCSharp.emit.jsonSerializer.ObjectToJson(new { a = 10, b = 13 }))).deSerialize()) != 23)
                            {
                                return(false);
                            }
                            //if (webClient.UploadValues(url + "add", urlQuery.form.Get(new { a = 10, b = 13 })).deSerialize() != "23") return false;
                            //if (webClient.DownloadData(url + "add?" + urlQuery.query.Get(new { a = 10, b = 13 }, encoding)).deSerialize() != "23") return false;

                            int a;
                            incValue = 15;
                            if (client.inc(out a).Value != 16 || a != 15)
                            {
                                return(false);
                            }
                            incValue = 15;
                            outReturn value = fastCSharp.emit.jsonParser.Parse <outReturn>(webClient.UploadData(url + "inc2", new byte[0]).deSerialize());
                            if (value.Return != 16 || value.outValue != 15)
                            {
                                return(false);
                            }
                            incValue = 15;
                            value    = fastCSharp.emit.jsonParser.Parse <outReturn>(webClient.UploadValues(url + "inc2", new NameValueCollection()).deSerialize());
                            if (value.Return != 16 || value.outValue != 15)
                            {
                                return(false);
                            }
                            incValue = 15;
                            value    = fastCSharp.emit.jsonParser.Parse <outReturn>(webClient.DownloadData(url + "inc2").deSerialize());
                            if (value.Return != 16 || value.outValue != 15)
                            {
                                return(false);
                            }

                            if (client.inc(20, out a).Value != 21 || a != 20)
                            {
                                return(false);
                            }
                            value = fastCSharp.emit.jsonParser.Parse <outReturn>(webClient.UploadData(url + "inc3", encoding.GetBytes(fastCSharp.emit.jsonSerializer.ObjectToJson(new { a = 20 }))).deSerialize());
                            if (value.Return != 21 || value.outValue != 20)
                            {
                                return(false);
                            }
                            //if (webClient.UploadValues(url + "inc3", urlQuery.form.Get(new { a = 20 })).deSerialize() != @"{""b"":20,""_Return_"":21}") return false;
                            //if (webClient.DownloadData(url + "inc3?" + urlQuery.query.Get(new { a = 20 }, encoding)).deSerialize() != @"{""b"":20,""_Return_"":21}") return false;

                            if (client.add(30, 33, out a).Value != 63 || a != 33)
                            {
                                return(false);
                            }
                            value = fastCSharp.emit.jsonParser.Parse <outReturn>(webClient.UploadData(url + "add1", encoding.GetBytes(fastCSharp.emit.jsonSerializer.ObjectToJson(new { a = 30, b = 33 }))).deSerialize());
                            if (value.Return != 63 || value.outValue != 33)
                            {
                                return(false);
                            }
                            //if (webClient.UploadValues(url + "add1", urlQuery.form.Get(new { a = 30, b = 33 })).deSerialize() != @"{""c"":33,""_Return_"":63}") return false;
                            //if (webClient.DownloadData(url + "add1?" + urlQuery.query.Get(new { a = 30, b = 33 }, encoding)).deSerialize() != @"{""c"":33,""_Return_"":63}") return false;

                            if (webClient.UploadData(url + "setCookie", encoding.GetBytes(fastCSharp.emit.jsonSerializer.ObjectToJson(new { name = "a", value = "b" }))).deSerialize() != web.ajax.Object)
                            {
                                return(false);
                            }
                            if (webClient.ResponseHeaders["Set-Cookie"] != "a=b")
                            {
                                return(false);
                            }
                            //if (webClient.UploadValues(url + "setCookie", urlQuery.form.Get(new { name = "c", value = "d" })).deSerialize() != web.ajax.Object) return false;
                            //if (webClient.ResponseHeaders["Set-Cookie"] != "c=d") return false;
                            //if (webClient.DownloadData(url + "setCookie?" + urlQuery.query.Get(new { name = "e", value = "f" }, encoding)).deSerialize() != web.ajax.Object) return false;
                            //if (webClient.ResponseHeaders["Set-Cookie"] != "e=f") return false;

                            if (!fastCSharp.emit.jsonParser.Parse <bool>(webClient.UploadData(url + "setSession", encoding.GetBytes("b".ToJson())).deSerialize()))
                            {
                                return(false);
                            }
                            webClient.Cookies.SetCookies(new Uri(url), webClient.ResponseHeaders["Set-Cookie"].Split(';')[0]);
                            if (fastCSharp.emit.jsonParser.Parse <string>(webClient.UploadData(url + "getSession", new byte[0]).deSerialize()) != "b")
                            {
                                return(false);
                            }

                            //if (webClient.UploadValues(url + "setSession", urlQuery.form.Get(new { value = "d" })).deSerialize() != @"1") return false;
                            //if (webClient.UploadValues(url + "getSession", new NameValueCollection()).deSerialize() != @"""d""") return false;

                            //if (webClient.DownloadData(url + "setSession?" + urlQuery.query.Get(new { value = "f" }, encoding)).deSerialize() != @"1") return false;
                            //if (webClient.DownloadData(url + "getSession").deSerialize() != @"""f""") return false;
#if APP
#else
                            //HTTP文件上传
#if MONO
                            FileInfo fileInfo = new FileInfo((@"..\..\Program.cs").pathSeparator());
#else
                            FileInfo fileInfo = new FileInfo((@"..\..\tcpHttp.cs").pathSeparator());
#endif
                            if (fastCSharp.emit.jsonParser.Parse <long>(webClient.UploadFile(url + "httpUpload", fileInfo.FullName).deSerialize()) != fileInfo.Length)
                            {
                                return(false);
                            }
#endif
                            return(true);
                        }
                }
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// 环境检测
        /// </summary>
        /// <returns></returns>
        public static bool Check()
        {
            DirectoryInfo jsDirectory = new DirectoryInfo(@"..\..\..\ui\js\");

            if (jsDirectory.Exists)
            {
                copyJs(jsDirectory, new DirectoryInfo(@"..\..\js\"), true);
            }
            FileInfo loadJs = new FileInfo(@"..\..\js\loadPage.js");

            if (!loadJs.Exists)
            {
#if VS2010
                Console.WriteLine(@"错误:没有找到必要的脚本文件 " + loadJs.FullName + @"
你可能需要先成功编译 fastCSharp.ui.vs2010 项目,然后再 重新编译 此项目。");
#else
                Console.WriteLine(@"错误:没有找到必要的脚本文件 " + loadJs.FullName + @"
你可能需要先成功编译 fastCSharp.ui 项目,然后再 重新编译 此项目。");
#endif
                return(false);
            }
            FileInfo aceJs = new FileInfo(@"..\..\js\ace\mode-csharp.js");
            if (!aceJs.Exists)
            {
                FileInfo aceZip = new FileInfo(@"..\..\js\ace.zip");
                if (!aceZip.Exists)
                {
                    Console.WriteLine(@"警告:代码编辑组件 ACE 缺少某些文件,正在尝试下载 https://www.51nod.com/upload/ace.zip");
                    byte[] data;
                    using (fastCSharp.net.webClient client = new fastCSharp.net.webClient()) data = client.CrawlData("https://www.51nod.com/upload/ace.zip");
                    if (data.length() == 1867400)
                    {
                        File.WriteAllBytes(aceZip.FullName, data);
                        Console.WriteLine(@"代码编辑组件 ACE 下载成功");
                    }
                    else
                    {
                        Console.WriteLine("代码编辑组件 ACE 下载失败。");
                    }
                }
                if ((aceZip = new FileInfo(aceZip.FullName)).Exists)
                {
                    string jsPath = new DirectoryInfo(@"..\..\js\").fullName();
                    using (FileStream stream = aceZip.OpenRead())
                        using (ZipArchive zip = new ZipArchive(stream, ZipArchiveMode.Read, false))
                        {
                            foreach (ZipArchiveEntry zipEntry in zip.Entries)
                            {
                                if (zipEntry.Length != 0)
                                {
                                    FileInfo file = new FileInfo(jsPath + zipEntry.FullName);
                                    if (!file.Exists)
                                    {
                                        DirectoryInfo directory = file.Directory;
                                        if (!directory.Exists)
                                        {
                                            directory.Create();
                                        }
                                        using (Stream aceFileStream = new FileStream(file.FullName, FileMode.Create))
                                            using (Stream zipStream = zipEntry.Open())
                                            {
                                                zipStream.CopyTo(aceFileStream);
                                            }
                                    }
                                }
                            }
                        }
                }
            }
            FileInfo fastCSharpSln = new FileInfo(@"..\..\..\fastCSharp.sln");
            if (fastCSharpSln.Exists)
            {
                Default.FastCSharpPath = fastCSharpSln.Directory.fullName();
            }
            else
            {
                Console.WriteLine(@"警告:没有找到 fastCSharp 解决方案文件 " + fastCSharpSln.FullName);
            }
            return(true);
        }