Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            HproseClassManager.Register(typeof(User), "User");
            client = new HproseHttpClient("http://localhost:2012/");
            List <User> users = new List <User>();
            User        user1 = new User();

            user1.name    = "李雷";
            user1.age     = 32;
            user1.male    = true;
            user1.friends = new List <User>();
            User user2 = new User();

            user2.name    = "韩梅梅";
            user2.age     = 31;
            user2.male    = false;
            user2.friends = new List <User>();
            user1.friends.Add(user2);
            user2.friends.Add(user1);
            users.Add(user1);
            users.Add(user2);
            Func <List <User>, List <User> > SendUsers = userList => client.Invoke <List <User> >("sendUsers", new object[] { userList });

            Hello();
            MemoryStream stream = (MemoryStream)HproseFormatter.Serialize(SendUsers(users));

            Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray()));
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            HproseClassManager.Register(typeof(User), "User");
            HproseHttpListenerServer server = new HproseHttpListenerServer("http://localhost:2012/");
            TestService ts = new TestService();

            server.Add("Hello", ts, true);
            server.Add("SendUsers", ts);
            server.IsCrossDomainEnabled = true;
            //server.CrossDomainXmlFile = "crossdomain.xml";
            server.Start();
            Console.WriteLine("Server started.");
            Console.ReadLine();
            Console.WriteLine("Server stopped.");
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            HproseClassManager.Register(typeof(User), "User");
            client           = new HproseHttpClient(" http://localhost:2012/");
            client.KeepAlive = true;

/*
 *          List<User> users = new List<User>();
 *          User user1 = new User();
 *          user1.name = "李雷";
 *          user1.age = 32;
 *          user1.male = true;
 *          user1.friends = new List<User>();
 *          User user2 = new User();
 *          user2.name = "韩梅梅";
 *          user2.age = 31;
 *          user2.male = false;
 *          user2.friends = new List<User>();
 *          user1.friends.Add(user2);
 *          user2.friends.Add(user1);
 *          users.Add(user1);
 *          users.Add(user2);
 *          Func<List<User>, List<User>> SendUsers = userList => client.Invoke<List<User>>("sendUsers", new object[] { userList });
 *          Hello();
 *          MemoryStream stream = (MemoryStream)HproseFormatter.Serialize(SendUsers(users));
 *          Console.WriteLine(Encoding.UTF8.GetString(stream.ToArray()));
 */
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            var ts = new List <Thread>();

            for (int i = 0; i < 200; i++)
            {
                ts.Add(new Thread(() => {
                    for (int j = 1; j < 10; j++)
                    {
                        client.Invoke <String>("hello", new Object[] { "abc123" + j });
                    }
                }));
            }
            ts.ForEach(a => a.Start());
            ts.ForEach(a => a.Join());
            stopwatch.Stop();
            Console.WriteLine(stopwatch.ElapsedMilliseconds);
            Console.WriteLine(stopwatch.ElapsedMilliseconds / 2000.0);
            Console.ReadLine();
        }
Ejemplo n.º 4
0
 private void Application_Startup(object sender, StartupEventArgs e)
 {
     this.RootVisual = new MainPage();
     HproseClassManager.Register(typeof(User), "User");
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
#if !DEBUG
            server = new HproseHttpListenerServer("http://114.215.253.25:22012/");
#else
            server = new HproseHttpListenerServer("http://127.0.0.1:22012/");
#endif
            Mongo Db = new Mongo("TaiDong");
            //Db.DeleteMany<User>(add=>true);
            // Db.Delete<Content>(a=>a.type=="about");
            //var add= Db.FindList<Content>(a => true);
            var AddDomian = new string[] { "TaiDong" };

            if (Db.Count <User>(a => true) == 0)
            {
                Db.Insert <User>(new User {
                    name = "admin", pass = "******", level = "管理员"
                });
            }

            var fs = Directory.GetFiles(dPath, "*.dll");
            foreach (var f in fs)
            {
                var fn = Path.GetFileName(f);
                try
                {
                    var aes = Assembly.LoadFile(f);
                    var ts  = aes.GetTypes();
                    foreach (var t in ts)
                    {
                        if (t.IsNotPublic)
                        {
                            continue;
                        }
                        if (t.Name.ToLower().EndsWith("model"))
                        {
                            HproseClassManager.Register(t, t.Name);
                        }
                        else
                        {
                            AddClass(t);
                        }
                    }
                }
                catch { }
            }

            try
            {
                var aes = Assembly.GetExecutingAssembly();
                var ts  = aes.GetTypes();
                foreach (var t in ts)
                {
                    if (t.IsNotPublic || AddDomian.All(a => !t.FullName.Contains(a)))
                    {
                        continue;
                    }
                    if (t.Name.ToLower().EndsWith("model"))
                    {
                        HproseClassManager.Register(t, t.Name);
                    }
                    else
                    {
                        AddClass(t);
                    }
                }
            }
            catch { }

            server.OnBeforeInvoke += (name, arg, byRef, context) =>
            {
                if (SaveFunc.Contains(name))
                {
                    if (arg.Length <= 0 || Token != arg[0] as string)
                    {
                        throw new Exception("验证失败!");
                    }
                }
                else if (UserSaveFunc.Contains(name))
                {
                    if (arg.Length <= 0 || !UserToken.ContainsValue(arg[0] as string))
                    {
                        throw new Exception("验证失败!");
                    }
                }
            };
            server.IsCrossDomainEnabled = true;
            //server.CrossDomainXmlFile = "crossdomain.xml";
            server.Start();
            Console.WriteLine("Server started.");
            Console.ReadLine();
            Console.WriteLine("Server stopped.");
        }