Exemplo n.º 1
0
        private InvokeData AsyncCaller(InvokeMessage message)
        {
            InvokeResponse data;

            //开始计时
            var watch = Stopwatch.StartNew();

            try
            {
                //调用服务
                var invokeData = CastleFactory.Create().Invoke(node, message);
                data = new InvokeResponse(invokeData);
            }
            catch (Exception ex)
            {
                data = new InvokeResponse {
                    Exception = ex
                };
            }

            watch.Stop();
            data.ElapsedMilliseconds = watch.ElapsedMilliseconds;

            return(data);
        }
Exemplo n.º 2
0
 protected void Page_Load(object sender, EventArgs e)
 {
     if (!IsPostBack)
     {
         nodelist = CastleFactory.Create().GetServerNodes();
         timer    = GetRequestParam <int>("timer", 5);
     }
 }
Exemplo n.º 3
0
        static void DoWork1(object state)
        {
            ManualResetEvent are = state as ManualResetEvent;

            are.WaitOne();

            var node = CastleFactory.Create().GetDefaultNode();

            var service = CastleFactory.Create().GetChannel <IUserService>();

            //service = new UserService.UserService();
            //var service1 = CastleFactory.Create().GetChannel<IStatusService>(node);

            while (true)
            {
                try
                {
                    Stopwatch watch = Stopwatch.StartNew();

                    //int length = 1;
                    //UserInfo user;

                    //service.GetUserInfo("maoyong", ref length, out user);

                    //string userid;
                    //Guid guid;
                    //UserInfo user;
                    //UserInfo info = service.GetUserInfo("maoyong_" + Guid.NewGuid(), out userid, out guid, out user);
                    var value = service.GetUsersString();

                    //var users = service.GetUsers();
                    //var str = service.GetUsersString();

                    watch.Stop();

                    Interlocked.Increment(ref counter);

                    Console.WriteLine("【" + counter + "】times => " + value.Length + " timeout: " + watch.ElapsedMilliseconds + " ms.");

                    //var clients = service1.GetClientList();

                    //Console.WriteLine("{0} => {1}", DateTime.Now, clients.Count);
                }
                catch (Exception ex)
                {
                    string msg = ex.Message;
                    Console.WriteLine(msg);
                }

                //Thread.Sleep(1000);
            }
        }
Exemplo n.º 4
0
 public void ClearServerStatus()
 {
     try
     {
         nodelist = CastleFactory.Create().GetServerNodes();
         foreach (var node in nodelist)
         {
             CastleFactory.Create().GetChannel <IStatusService>(node).ClearServerStatus();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 5
0
 private void InitControl()
 {
     try
     {
         nodelist = CastleFactory.Create().GetServerNodes();
         foreach (var node in nodelist)
         {
             var service = CastleFactory.Create().GetChannel <IStatusService>(node);
             statuslist[node.Key] = service.GetServerStatus();
             clientlist[node.Key] = service.GetClientList();
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemplo n.º 6
0
        static void Main(string[] args)
        {
            while (true)
            {
                try
                {
                    var user1 = CastleFactory.Create().GetChannel <IUserService>().GetUsers();
                    Console.WriteLine(user1.Count + "," + user1[0].Description);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                Thread.Sleep(1000);
            }
            Console.ReadLine();
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            //var list = new List<User>();
            //for (int i = 0; i < 1000; i++)
            //{
            //    list.Add(new User { Id = i, Name = "test" + i });
            //}

            //Stopwatch watch = Stopwatch.StartNew();
            //var lb = new List<byte>();
            //for (int i = 0; i < 100; i++)
            //{
            //    var s = SerializationManager.SerializeBin(list);
            //    lb.AddRange(s);
            //}
            //watch.Stop();
            //Console.WriteLine(lb.Count + " - " + watch.ElapsedMilliseconds);

            //watch = Stopwatch.StartNew();

            //var set = new Polenter.Serialization.SharpSerializerBinarySettings();
            //set.Mode = Polenter.Serialization.BinarySerializationMode.SizeOptimized;
            //set.Encoding = Encoding.Default;

            //lb = new List<byte>();
            //var se = new Polenter.Serialization.SharpSerializer(set);
            //for (int i = 0; i < 100; i++)
            //{
            //    var stream = new MemoryStream();
            //    se.Serialize(list, stream);

            //    lb.AddRange(stream.ToArray());
            //}

            //watch.Stop();
            //Console.WriteLine(lb.Count + " - " + watch.ElapsedMilliseconds);


            //CastleFactoryConfiguration config = CastleFactoryConfiguration.GetConfig();

            //LogEventHandler logger = Console.WriteLine;
            //MemoryServiceMQ mq = new MemoryServiceMQ();
            //mq.OnLog += new LogEventHandler(mq_OnLog);
            //mq.OnError += new ErrorLogEventHandler(mq_OnError);

            //CastleServiceHelper cs = new CastleServiceHelper(config);
            //cs.OnLog += logger;
            //cs.PublishWellKnownServiceInstance(mq);

            //Console.WriteLine("Service MQ Server started...");
            //Console.WriteLine("Logger Status: On");
            //Console.WriteLine("Press any key to exit and stop server...");
            //Console.ReadLine();

            //CastleFactory.Create().OnError += new ErrorLogEventHandler(mq_OnError);
            //CastleFactory.Create().OnLog += new LogEventHandler(mq_OnLog);
            //Console.ReadKey();

            //int count = 1;

            //var castle = CastleFactory.Create();
            ////castle.RegisterCacheDependent(DefaultCacheDependent.Create());
            //castle.OnLog += new LogEventHandler(castle_OnLog);
            //castle.OnError += new ErrorLogEventHandler(castle_OnError);
            //IUserService service = castle.GetService<IUserService>();

            //IList<ServiceInfo> list = castle.GetService<IStatusService>().GetServiceInfoList();
            //var str = service.GetUserID();

            //service.GetUsers();
            //service.GetDictUsers();

            //try
            //{
            //    int userid;
            //    var user = service.GetUserInfo("maoyong", out userid);
            //    user = service.GetUserInfo("maoyong", out userid);
            //    user = service.GetUserInfo("maoyong", out userid);
            //    user = service.GetUserInfo("maoyong", out userid);
            //    user = service.GetUserInfo("maoyong", out userid);

            //    service.SetUser(null, ref userid);
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}

            //for (int i = 0; i < count; i++)
            //{
            //    try
            //    {
            //        Thread thread = new Thread(DoWork);
            //        thread.Name = string.Format("Thread-->{0}", i);
            //        thread.IsBackground = true;
            //        thread.Start(service);
            //    }
            //    catch (Exception ex)
            //    {
            //        //WriteMessage(msg);
            //        castle_OnError(ex);
            //    }
            //}

            //var watch = Stopwatch.StartNew();

            //GetRequestString();

            //var dd = watch.ElapsedMilliseconds;

            //Console.WriteLine("耗时: {0} ms", dd);
            //Console.ReadLine();
            //return;

            //var url = "http://openapi.mysoft.com/user.addusers.json?aaa=1&bbb=2";
            //var users = new { users = new[] { new { ID = 1, Name = "test1=aaa" }, new { ID = 2, Name = "test2" } } };
            ////var value = "users=" + SerializationManager.SerializeJson(users, false);

            ////var text = new HttpHelper(120).Poster(url, value);

            //var factory = RESTfulFactory.Create(url, DataFormat.JSON);
            //var token = factory.Invoke("user.addusers", users, HttpMethod.POST);

            //Console.WriteLine(token.ToString());

            //var url = "http://openapi.fund123.cn/post.json/myfund.addopenandfinancialfund?uid=yayiyao&pwd=2";
            //var v = HttpUtility.UrlEncode("[{\"AccountBookId\":\"d269da43-4e80-4c8e-ba69-32fca1fcf6e3\",\"ParentID\":\"\",\"Code\":\"100022\",\"Quotient\":1.26,\"BuyMoney\":1,\"BuyDate\":\"2012-04-24\",\"BonusType\":0,\"FrontOrBack\":1,\"RateType\":0,\"DeductFeeType\":0,\"FrontRate\":0.6,\"BuyRate\":0,\"BuyRate1\":0,\"BuyRate2\":0,\"BuyRate3\":0,\"Rate\":0.5,\"Rate1\":0.25,\"Rate2\":0,\"Rate3\":0,\"ChannelType\":0,\"BuyChannel\":\"\",\"Remark\":\"\"}]");
            //var value = "funds=" + v;

            ////请求服务
            //value = HttpHelper.Default.Poster(url, value);
            //Console.WriteLine(value);
            //Console.ReadLine();

            //return;

            CastleFactory.Create().RegisterLogger(new ServiceLog());
            CastleFactory.Create().RegisterResolver(new ServiceResolver());

            ManualResetEvent are = new ManualResetEvent(false);

            for (int i = 0; i < 100; i++)
            {
                Thread thread = new Thread(DoWork1);
                thread.Start(are);
            }

            are.Set();

            //var node = CastleFactory.Create().GetDefaultNode();
            //var clients = CastleFactory.Create().GetChannel<IStatusService>(node).GetAppClients();

            //DoWork1();

            //string a = SerializationManager.SerializeJson(null);

            //var request = (HttpWebRequest)WebRequest.Create("http://webapi.mysoft.com/user.getuser1");
            //request.Method = "POST";
            //request.ContentType = "application/x-www-form-urlencoded";

            //using (var stream = request.GetRequestStream())
            //{
            //    var user = MySoft.SerializationManager.SerializeJson(new { user = new { Name = "123" } });
            //    stream.Write(Encoding.UTF8.GetBytes(user), 0, Encoding.UTF8.GetByteCount(user));
            //    stream.Flush();
            //}

            //var response = (HttpWebResponse)request.GetResponse();
            //using (var sr = new StreamReader(response.GetResponseStream()))
            //{
            //    var str = sr.ReadToEnd();
            //    Console.WriteLine(str);
            //}

            //var container = new CookieContainer();
            //container.Add(new Cookie("uid", "123", "/", "a.com"));
            //container.Add(new Cookie("pwd", "dafsdf", "/", "a.com"));
            //request.CookieContainer = container;

            //using (var stream = request.GetRequestStream())
            //{
            //    var buffer = Encoding.UTF8.GetBytes("{ user : { Name : \"mmm\" } }");
            //    stream.Write(buffer, 0, buffer.Length);
            //}

            //var response = request.GetResponse();
            //using (var sr = new StreamReader(response.GetResponseStream()))
            //{
            //    var str = sr.ReadToEnd();
            //    Console.WriteLine(str);
            //}

            Console.ReadKey();
        }