Пример #1
0
        public void TestMethod1()
        {
            Debug.Flush();
            var server = new NodeServer(new MessageEncoding(new MessageFactory()));
            var client = new NodeClient(new MessageEncoding(new MessageFactory()));

            server.Start();
            client.SendMessage();

            Thread.Sleep(1000);
        }
Пример #2
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            string          path     = @"E:\git\SOAFramework\01.Code\Bin\Api\ServiceController\Chainway.SyncData.ServiceMonitorBLL.dll";
            Assembly        assembly = Assembly.LoadFile(path);
            string          host     = @"http://127.0.0.1:9080/ServiceController/";
            NodeServer      node     = new NodeServer();
            List <Assembly> list     = new List <Assembly>();

            list.Add(assembly);
            node.Start(host, AppDomain.CurrentDomain, list);
        }
Пример #3
0
        private void test()
        {
            NodeServer server = new NodeServer();

            server.Start();

            for (int i = 0; i < 100; i++)
            {
                FAP.Network.Client.Client c = new FAP.Network.Client.Client();
                c.Test();
            }
            System.Console.ReadKey();
        }
Пример #4
0
        public void Start(int inport)
        {
            listener            = new NodeServer();
            listener.OnRequest += listener_OnRequest;

            bool trybind = true;
            int  port    = inport;

            do
            {
                try
                {
                    listener.Start(IPAddress.Parse(model.LocalNode.Host), port);
                    trybind = false;
                    if (isServer)
                    {
                        var f = new FAPServerHandler(IPAddress.Parse(model.LocalNode.Host),
                                                     port,
                                                     model,
                                                     container.Resolve <MulticastClientService>(),
                                                     container.Resolve <LANPeerFinderService>(),
                                                     container.Resolve <MulticastServerService>());
                        fap = f;
                        f.Start("Local", "Local");
                    }
                    else
                    {
                        var f = new FAPClientHandler(model, container.Resolve <ShareInfoService>(),
                                                     container.Resolve <IConversationController>(),
                                                     container.Resolve <BufferService>(),
                                                     container.Resolve <ServerUploadLimiterService>());
                        fap = f;
                        f.Start();
                        model.ClientPort = port;
                    }
                }
                catch
                {
                    //Try again
                    port++;
                    if (inport + 100 < port)
                    {
                        throw new Exception("Could to bind listener");
                    }
                }
            } while (trybind);
        }
Пример #5
0
        public async Task <int> Run()
        {
            if (_quitToken.IsCancellationRequested)
            {
                return(0);
            }

            await Kademlia.Start();

            TransactionManager.Start();
            await CouncilManager.Start();

            await NodeServer.Start();

            await ClientServer.Start();

            if (ServiceServer != null)
            {
                await ServiceServer.Start();
            }

            await _quitToken.WaitAsync();

            await PubSub.PublishAsync(new QuitEvent());

            await NodeServer.Stop();

            await ClientServer.Stop();

            await CouncilManager.Stop();

            TransactionManager.Stop();
            await Kademlia.Stop();

            await ChainManager.Stop();

            if (ServiceServer != null)
            {
                await ServiceServer.Stop();
            }

            await(Host as Host).Stop();

            return(0);
        }
Пример #6
0
        static void Main(string[] args)
        {
            var h  = DBFactory.CreateDBHelper(@"Data Source=E:\git\memberManager\db\membermanager.db;Version=3;", DBType.SQLite);
            var tb = h.GetTableWithSQL("SELECT NAME FROM sqlite_master WHERE type='table'");

            #region id generator
            IIDGenerator  iDGenerator = IDGeneratorFactory.Create(GeneratorType.SnowFlak);
            List <string> idlist      = new List <string>();
            for (int i = 0; i < 10000; i++)
            {
                idlist.Add(iDGenerator.Generate());
            }

            #endregion

            TestClass tc = new TestClass
            {
                tc = new TestClass
                {
                    a  = "hello",
                    b  = "word",
                    tc = new TestClass
                    {
                        a = "deep",
                    }
                },
                test = new List <TestClass>
                {
                    new TestClass
                    {
                        a = "<",
                    }
                },
            };
            #region xml testing
            TestRequest req = new TestRequest
            {
                c = new TestClass
                {
                    a  = "a",
                    b  = "b",
                    d  = "d",
                    dt = DateTime.Now,
                }
            };
            ISerializable serial = new XmlSerializor();
            var           xml    = serial.Serialize(req);

            var obj = serial.Deserialize <TestRequest>(xml);

            Dictionary <string, object> arg = new Dictionary <string, object>();
            arg["a"] = "a";
            arg["b"] = 3;
            arg["c"] = req;
            xml      = serial.Serialize(arg);
            var dicobj = serial.Deserialize <Dictionary <string, object> >(xml);
            #endregion
            //string jsonstring = "{\"Buyers\":[{\"ID\":\"395f7ce8de8340eda2dfd22098c81290\",\"Name\":\"爱的色放\",\"CardType\":\"1\",\"IdentityCode\":\"4444444444\",\"Phone\":\"123123123123\",\"Gender\":\"1\",\"Marrage\":\"1\",\"Address\":\"啊都是法师打发而且额外人\",\"OrignalName\":\"\",\"OrignalIdentityCode\":\"\",\"BankCode\":\"\",\"BankType\":\"1\",\"WorkUnit\":\"\",\"Quotient\":\"222\"},{\"ID\":\"\",\"Name\":\"阿萨法 \",\"CardType\":\"1\",\"IdentityCode\":\"986799283948723984\",\"Phone\":\"123123\",\"Gender\":\"2\",\"Marrage\":\"1\",\"Address\":\"三个地方集团研究研究\",\"OrignalName\":\"\",\"OrignalIdentityCode\":\"\",\"BankCode\":\"\",\"BankType\":\"\",\"WorkUnit\":\"\",\"Quotient\":\"333\"},{\"ID\":\"712feaff6c034244ab3f066268b9fe5a\",\"Name\":\"阿斯顿飞\",\"CardType\":\"1\",\"IdentityCode\":\"12312312312323\",\"Phone\":\"123123123\",\"Gender\":\"1\",\"Marrage\":\"1\",\"Address\":\"嘎达嗦嘎多个地方十多个地方各个\",\"OrignalName\":\"\",\"OrignalIdentityCode\":\"\",\"BankCode\":\"\",\"BankType\":\"1\",\"WorkUnit\":\"\",\"Quotient\":\"222\"}],\"Sellers\":[{\"ID\":\"55b71c225dc841a7b99ead4cecc601c5\",\"Name\":\"aeeboo\",\"CardType\":\"1\",\"IdentityCode\":\"234234235235\",\"Phone\":\"324234234234\",\"Gender\":\"1\",\"Marrage\":\"2\",\"Address\":\"的方式购房合同和投入和\",\"OrignalName\":\"\",\"OrignalIdentityCode\":\"\",\"BankCode\":\"\",\"BankType\":\"2\",\"WorkUnit\":\"\",\"Quotient\":\"111\"},{\"ID\":\"\",\"Name\":\"阿萨德飞44\",\"CardType\":\"1\",\"IdentityCode\":\"237856234\",\"Phone\":\"34234234\",\"Gender\":\"1\",\"Marrage\":\"1\",\"Address\":\"然后统一集团研究与\",\"OrignalName\":\"\",\"OrignalIdentityCode\":\"\",\"BankCode\":\"\",\"BankType\":\"\",\"WorkUnit\":\"\",\"Quotient\":\"123\"}],\"Assets\":[{\"ID\":\"\",\"Code\":\"44444444\",\"Usage\":\"1\",\"Position\":\"2\",\"Address\":\"景田西路八个道路\",\"Area\":\"123\",\"RegPrice\":\"44232\"},{\"ID\":\"\",\"Code\":\"1412412132\",\"Usage\":\"1\",\"Position\":\"1\",\"Address\":\"水电费个人个人高\",\"Area\":\"234324\",\"RegPrice\":\"123123\"}],\"Project\":{\"Source\":\"1\",\"AgentName\":\"213213\",\"CertificateData\":\"2015-08-05\",\"AgentContact\":\"\",\"Rebater\":\"\",\"RebateAccount\":\"\",\"OtherRebateInfo\":\"\",\"OrignalMortgageBank\":\"1\",\"OrignalMortgageBranch\":\"阿斯顿发顺丰\",\"OrignalFundCenter\":\"1\",\"OrignalFundBranch\":\"\",\"SupplyCardCopy\":\"\",\"OrignalCreditPI\":\"123123\",\"OrignalCreditCommerceMoney\":\"123\",\"OrignalCreditFundMoney\":\"123\",\"AssetRansomCustomerManager\":\"124142\",\"AssetRansomContactPhone\":\"24124\",\"NewCreditBank\":\"1\",\"NewCreditBranch\":\"2r323\",\"ShortTermAssetRansomBank\":\"1\",\"ShortTermAssetRansomBranch\":\"\",\"GuaranteeMoney\":\"123\",\"GuaranteeMonth\":\"1231\",\"BuyerCreditCommerceMoney\":\"213\",\"BuyerCreditFundMoney\":\"2\",\"LoanMoney\":\"123123\",\"DealMoney\":\"123123\",\"EarnestMoney\":\"123123\",\"SupervisionMoney\":\"123123\",\"SupervisionBank\":\"12123\",\"AssetRansomMoney\":\"122323\",\"CustomerPredepositMoney\":\"323232\",\"CreditReceiverName\":\"23123\",\"CreditReceiverBank\":\"2323\",\"CreditReceiverAccount\":\"2323\",\"TrusteeshipAccount\":\"\",\"AssetRansomPredictMoney\":\"2323\",\"AssetRansomer\":\"232323\",\"AssetRansomType\":\"1\",\"PredictDays\":\"2323\",\"ChargeType\":\"1\",\"CheckNumbersAndLimit\":\"123123\",\"Stagnationer\":\"\"},\"token\":\"0cbbd08b6b694428a30afe52098e5f7a\"}";
            //var json = JsonHelper.Deserialize<AddProjectServiceForm>(jsonstring);
            #region domain
            //AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad;
            //AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve1;
            //AppDomainSetup info = new AppDomainSetup();
            //info.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory + "Modules";
            //AppDomain domain = AppDomain.CreateDomain("mydomain", null, info);
            //Console.WriteLine(domain.BaseDirectory);
            //var allass = domain.GetAssemblies();
            //var ass = domain.Load(new AssemblyName("Controller"));
            //allass = domain.GetAssemblies();
            //var type = ass.GetType("SOAFramework.Library.HttpServer");
            //var instance = Activator.CreateInstance(type, null);
            //var start = type.GetMethod("Start");
            //start.Invoke(instance, new object[] { new string[] { "http://10.1.50.195:8094/c" } });
            //domain.AssemblyLoad += Domain_AssemblyLoad;
            #endregion

            #region http server
            Console.WriteLine("begin");
            NodeServer nodeserver = new NodeServer("http://10.1.50.195:8094/");
            nodeserver.Start();
            Console.ReadLine();
            //nodeserver.Close();

            HttpServer server = new HttpServer(new string[] { "http://10.1.50.195:8094/a" });
            server.Executing += new HttpExecutingHandler((a, b) =>
            {
                StreamReader reder = new StreamReader(b.Request.InputStream, System.Text.Encoding.UTF8);
                string post        = reder.ReadToEnd();
                Console.WriteLine("key:" + post);
                return("");
            });
            server.Start();

            //HttpServer server2 = new HttpServer(new string[] { "http://10.1.50.195:8094/b" });
            //server2.Start();
            Console.ReadLine();

            string[] prefix = new string[] { "http://*****:*****@"http://localhost/Service/Execute/SOAFramework.Service.Server.DefaultService/DiscoverService", data);
            testresult = ZipHelper.UnZip(testresult);
            List <ServiceInfo>          serviceList   = JsonHelper.Deserialize <List <ServiceInfo> >(testresult);
            string                      path          = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + @"\Templates\SDKRequest.cst";
            Dictionary <string, object> argsCodeSmith = new Dictionary <string, object>();
            argsCodeSmith["RequestNameSpace"] = "a.b.c";
            argsCodeSmith["ServiceInfo"]      = serviceList[0];
            string render = CodeSmithHelper.GenerateString(path, argsCodeSmith);

            string  fileName = AppDomain.CurrentDomain.BaseDirectory.TrimEnd('\\') + "\\SOAFramework.Library.CodeSmithConsole.exe ";
            Process p        = new Process();
            p.StartInfo.UseShellExecute        = false;
            p.StartInfo.FileName               = fileName;
            p.StartInfo.Arguments              = " " + path.Replace(@"\\", @"\" + " ") + " " + JsonHelper.Serialize(argsCodeSmith).Replace("\"", "\\\"") + " ";
            p.StartInfo.RedirectStandardInput  = true;
            p.StartInfo.RedirectStandardOutput = true;
            p.Start();
            p.WaitForExit();
            return;

            #endregion

            #region razor
            //string strr = File.ReadAllText("Temp.txt");
            //Dictionary<string, object> dicargs = new Dictionary<string, object>();
            //dicargs["a"] = "22222";
            //string r = Razor.Parse(strr, dicargs);
            #endregion

            #region json tester
            //List<TestClass> list = new List<TestClass>();
            //for (int i = 0; i < 10; i++)
            //{
            //    TestClass c = new TestClass
            //    {
            //        a = "a" + i.ToString(),
            //        b = "b" + i.ToString(),
            //        dic = new Dictionary<string, string>(),
            //    };
            //    c.dic["dic1"] = "dic1" + i.ToString();
            //    c.dic["dic2"] = "dic2" + i.ToString();
            //    c.dic["dic3"] = "dic3" + i.ToString();
            //    c.test = new List<TestClass>();
            //    c.test.Add(new TestClass { a = "aa" + i.ToString(), b = "bb" + i.ToString() });
            //    c.test.Add(new TestClass { a = "cc" + i.ToString(), b = "dd" + i.ToString() });
            //    list.Add(c);
            //}
            //watch.Start();
            //string strjson = JsonHelper.Serialize(list, false);
            //watch.Stop();
            //Console.WriteLine("序列化:{0}", watch.ElapsedMilliseconds);
            //watch.Reset();
            //watch.Start();
            //List<TestClass> list1 = JsonHelper.Deserialize<List<TestClass>>(strjson);
            //watch.Stop();
            //Console.WriteLine("反序列化:{0}", watch.ElapsedMilliseconds);
            //TestResponse re = JsonHelper.Deserialize<TestResponse>("{\"IsError\":false,\"Data\":[{\"InterfaceName\":\"SOAFramework.Service.Server.DefaultService.DiscoverService\"}]}");
            #endregion

            #region custom wcf binding
            //string baseAddress = "Http://localhost/Service";
            //ServiceHost host = new WebServiceHost(typeof(SOAService), new Uri(baseAddress));
            //host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "soap");
            //WebHttpBinding webBinding = new WebHttpBinding();
            //webBinding.ContentTypeMapper = new MyRawMapper();
            //host.AddServiceEndpoint(typeof(IService), webBinding, "json").Behaviors.Add(new NewtonsoftJsonBehavior());
            //Console.WriteLine("Opening the host");
            //host.Open();

            //ChannelFactory<IService> factory = new ChannelFactory<IService>(new BasicHttpBinding(), new EndpointAddress(baseAddress + "/soap"));
            //IService proxy = factory.CreateChannel();
            //byte[] newdata;
            //TestClass c1 = new TestClass();
            //c1.a = "a";
            //List<TestClass> list1 = new List<TestClass>();
            //list1.Add(c1);
            //string strnewdata = JsonHelper.Serialize(list1);
            //newdata = Encoding.UTF8.GetBytes(strnewdata);
            //string newtestresult = HttpHelper.Post(@"http://localhost/Service/SOAFramework.Service.Server.DefaultService/DiscoverService", newdata);

            //Console.WriteLine("Now using the client formatter");
            //ChannelFactory<IService> newFactory = new ChannelFactory<IService>(webBinding, new EndpointAddress(baseAddress + "/json"));
            //newFactory.Endpoint.Behaviors.Add(new NewtonsoftJsonBehavior());
            //IService newProxy = newFactory.CreateChannel();

            //Console.WriteLine("Press ENTER to close");
            //Console.ReadLine();
            //host.Close();
            //Console.WriteLine("Host closed");
            #endregion

            #region wcf host
            WebServiceHost newhost = new WebServiceHost(typeof(SOAService));
            newhost.Open();
            newhost.Ping();
            #endregion

            #region zip tester
            string zip    = "i am a string, to be zipped!";
            string zipped = ZipHelper.Zip(zip, System.Text.Encoding.Default);
            zip = ZipHelper.UnZip(zipped);
            #endregion

            #region orm
            //string abc = Model.Users.Mapping.ColumnsMapping["PK_UserID"].ToString();
            //a c = new a();
            //c.b = "haha ";
            //c.t = new a();
            //c.t.b = "aaaaaa";
            //string str1 = JsonHelper.Serialize(c);

            //c = JsonHelper.Deserialize<a>(str1);

            //FTPClient f = new FTPClient();
            //f.FtpUrl = "ftp://localhost/";
            //f.FileName = "ha.txt";
            //f.UserName = "******";
            //f.Password = "******";
            //f.BufferSize = 10;
            //f.LocalFilePath = "e:";
            //f.Download();

            //sw.Stop();
            //Console.WriteLine("linq:" + sw.ElapsedTicks);
            //Model.Users objUser = new Model.Users();
            //Hashtable htArgs = new Hashtable();
            //htArgs["str"] = "ok";
            //WebServiceCaller wsCaller = new WebServiceCaller();
            //wsCaller.Action = "PostTest";
            //wsCaller.Args = htArgs;
            //wsCaller.Action = "GetTest";
            //wsCaller.WSUrl = @"http://*****:*****@"F:\TestOut.docx";
            //List<MethodArg> lstArg = new List<MethodArg>();
            //lstArg.Add(new MethodArg("there"));
            //cr.RequestData.MethodArgs = lstArg.ToArray();
            //cr.RequestType = WSDataType.JSON;
            //string str = cr.GetRequestString();
            //cr.ResponseType = WSDataType.JSON;
            //string strReturn = cr.SendRequest();
            //ServerResponse response = cr.GetResponse();
            //byte[] bytTemp = response.ResponseData;
            //Stream sw = File.Open(strFileName, FileMode.OpenOrCreate, FileAccess.Write);
            //sw.Write(bytTemp, 0, bytTemp.Length);
            //sw.Close();

            //Model.Users u = new Model.Users();
            //Model.Customer_AutoIncrease t = new Model.Customer_AutoIncrease();
            #endregion

            #region soa tester

            //testresult = HttpUtility.Get("http://localhost/Service/GetTest");

            argslist.Add(new SOAFramework.Service.SDK.Core.PostArgItem {
                Key = "url", Value = "http://localhost/"
            });
            //argslist.Add(new PostArgItem { Key = "usage", Value = "1.00" });
            strData = JsonHelper.Serialize("http://localhost/");
            //strData = "\"" + strData + "\"";
            data       = System.Text.Encoding.UTF8.GetBytes(strData);
            testresult = HttpHelper.Post(@"http://*****:*****@"http://localhost/Service/Execute/SOAFramework.Service.Server.DefaultService/DiscoverService", data);
            testresult = ZipHelper.UnZip(testresult);
            watch.Stop();
            Console.WriteLine("发现服务测试耗时{0}", watch.ElapsedMilliseconds);


            watch.Restart();
            argslist.Clear();
            strData    = JsonHelper.Serialize(argslist);
            data       = System.Text.Encoding.UTF8.GetBytes(strData);
            testresult = HttpHelper.Post(@"http://localhost/Service/Execute/SOAFramework.Service.Server.DefaultService/BigDataTest", data);
            watch.Stop();
            Console.WriteLine("大数据测试耗时{0}", watch.ElapsedMilliseconds);

            watch.Restart();
            //download test
            string filename = "预付款类型批量导入.xls";
            testresult = HttpHelper.Get(@"http://localhost/Service/Download/" + filename);
            //testresult = ZipHelper.UnZip(testresult);
            testresult.ToFile("D:\\" + filename);
            watch.Stop();
            Console.WriteLine("下载测试耗时{0}", watch.ElapsedMilliseconds);

            watch.Restart();
            //uploadtest
            string   uploadFileName = "D:\\预付款类型批量导入.xls";
            FileInfo file           = new FileInfo(uploadFileName);
            string   fileString     = file.FileToString();
            data       = System.Text.Encoding.UTF8.GetBytes(fileString);
            testresult = HttpHelper.Post(@"http://localhost/Service/Upload/" + file.Name, data);
            watch.Stop();
            Console.WriteLine("上传测试耗时{0}", watch.ElapsedMilliseconds);

            watch.Restart();
            int count = 10000;
            //for (int i = 0; i < count; i++)
            //{
            //    List<SOAFramework.Service.SDK.Core.PostArgItem> list = new List<SOAFramework.Service.SDK.Core.PostArgItem>();
            //    list.Add(new SOAFramework.Service.SDK.Core.PostArgItem { Key = "a", Value = JsonHelper.Serialize("hello world") });
            //    list.Add(new SOAFramework.Service.SDK.Core.PostArgItem { Key = "b", Value = JsonHelper.Serialize(new TestClass { a = "a", b = "b" }) });
            //    //list.Add(new PostArgItem { Key = "a", Value = "hello world" });
            //    //list.Add(new PostArgItem { Key = "b", Value = new TestClass { a = "a", b = "b" } });
            //    strData = JsonHelper.Serialize(list);
            //    data = System.Text.Encoding.UTF8.GetBytes(strData);
            //    //testresult = HttpHelper.Post(@"http://localhost/Service/Execute/SOAFramework.Service.Server.SOAService/Test", data);
            //    testresult = ZipHelper.UnZip(testresult);

            //    PerformanceRequest prequest = new PerformanceRequest();
            //    prequest.a = "hello world";
            //    prequest.b = new TestClass { a = "a", b = "b" };
            //    PerformanceResponse presponse = SDKFactory.Client.Execute(prequest);
            //}
            watch.Stop();
            Console.WriteLine("{1}次测试耗时{0}", watch.ElapsedMilliseconds, count);
            #endregion

            #region sdk testing
            //TestRequest request = new TestRequest();
            //TestResponse reseponse = SDKFactory.Client.Execute(request);
            #endregion

            Console.ReadLine();
        }