Ejemplo n.º 1
0
        private void AskLogin()
        {
            string username;
            string password;

            while (true)
            {
                Console.WriteLine("Enter UserName: {1,2}\n");
                username = Console.ReadLine();
                Console.WriteLine("Enter Password: \n");
                password = Console.ReadLine();

                break;
            }

            LoginService.AskLogin(username, password, MqttAdaptor.GetUuid().ToByteArray()).Callback = askLoginOperation =>
            {
                if (!askLoginOperation.IsComplete)
                {
                    Console.WriteLine("LoginService.AskLogin failed");
                    return;
                }

                ServerList list = askLoginOperation.Result;

                Console.WriteLine(list);

                string prompt = string.Format("Chose one server:\n{0}\n"
                                              , string.Join("\n", list.Servers.ToArray()));

                if (list.Servers.Count == 0)
                {
                    Console.WriteLine("No valid server....");
                    return;
                }
                while (true)
                {
                    Console.WriteLine(prompt);
                    string s = Console.ReadLine();
                    if (list.Servers.Contains(s))
                    {
                        RoutingRule.DistrictsName = s;
                        break;
                    }
                    else if (s == "")
                    {
                        RoutingRule.DistrictsName = list.Servers[0];
                        break;
                    }
                }

                pid = list.Pid;
                Console.WriteLine(string.Format("------------we are in {0}----------------", RoutingRule.DistrictsName));
                LogicService = new Cli2LogicServiceDelegate(MqttAdaptor);
                ServiceImplementStub.Bind <ILogic2CliImpl>(MqttAdaptor, new ClientLogicServiceImpl());
                Interoperate();
            };
        }
Ejemplo n.º 2
0
        static void InitService()
        {
            AutoInit.Init();

            RoutingRule.DistrictsName = "test";

            GateAdaptor = new GateAdaptor("127.0.0.1", 6999);

            ServiceImplementStub.Bind <ICli2SceneImpl>(GateAdaptor, new SceneClientServiceImpl());

            Scene2CliService = new Scene2CliServiceDelegate(GateAdaptor);

            GateAdaptor.BeginReceive();
            //Heartbeat();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            AutoInit.Init();
            AmqpAdaptor AmqpAdaptor = new AmqpAdaptor(ConfigManager.MQIP(), ConfigManager.AMQPPort(),
                                                      ConfigManager.MQUser(), ConfigManager.MQPass());

            ServiceImplementStub.Bind <ICli2LoginImpl>(AmqpAdaptor, new LoginClientServiceImpl());
            ServiceImplementStub.Bind <ILoginNotifyImpl>(AmqpAdaptor, new LoginNotifyImpl());
            AmqpAdaptor.BeginReceive();

            RedisAdaptor     = new RedisAdaptor(ConfigManager.CacheConn());
            CacheDataService = new RedisDataServiceDelegate(RedisAdaptor);

            Console.ReadKey();
        }
Ejemplo n.º 4
0
        static void InitService()
        {
            AutoInit.Init();
            TypeRegister.Init();

            RoutingRule.DistrictsName = ConfigManager.DistrictsName();

            zkAdaptor = new ZkAdaptor();
            //amqpAdaptor = new AmqpAdaptor(ConfigManager.MQIP(), ConfigManager.AMQPPort(),
            //    ConfigManager.MQUser(), ConfigManager.MQPass());

            //ServiceImplementStub.Bind<LogicClientServiceImpl, ILogicClientImpl>(amqpAdaptor, new LogicClientServiceImpl());
            ServiceImplementStub.Bind <IDbClientNotifyImpl>(zkAdaptor, new NotifyServiceImpl());

            //Logic2CliService = new ClientLogicServiceDelegate(amqpAdaptor);
            //loginNotifyDelegate = new LoginNotifyDelegate(amqpAdaptor);
            //SchedulerLogicService = new SchedulerLogicServiceDelegate(amqpAdaptor);

            dbClientNotifyDelegate = new DbClientNotifyDelegate(zkAdaptor);

            //ConfigManager.RegisterParser(new ConfigManager.ConfigParserDelegate<EndPoint>(s =>
            //{
            //    var rets = s.Split(':');
            //    var host = rets[0];
            //    var port = 0;

            //    int.TryParse(rets[1], out port);

            //    IPAddress ip;
            //    if (IPAddress.TryParse(host, out ip))
            //    {
            //        return new IPEndPoint(ip, port);
            //    }

            //    return new DnsEndPoint(host, port);
            //}));

            CacheService = new RedisDataServiceDelegate(new RedisAdaptor(ConfigManager.Instance.Read <List <EndPoint> >("DataService", "CacheConn")));
            //DbService = new MysqlDataServiceDelegate(new MysqlAdaptor(ConfigManager.DbIP(), ConfigManager.DbName(), ConfigManager.DbUser(), ConfigManager.DbPass()));

            zkAdaptor.BeginReceive();
            //amqpAdaptor.BeginReceive();

            zkAdaptor.Identity("Logic");

            //Heartbeat();
        }
Ejemplo n.º 5
0
        public void BeginTest()
        {
            Console.WriteLine(" MQTT connected,  BeginTest....");

            LoginService = new Cli2LoginServiceDelegate(MqttAdaptor);

            AskLogin();

            Console.WriteLine("Gate connected,  BeginTest....");

            RoutingRule.DistrictsName = "test";

            SceneService = new Cli2SceneServiceDelegate(GateAdaptor);
            ServiceImplementStub.Bind <IScene2CliImpl>(GateAdaptor, new SceneServiceImpl());

            Interoperate();
        }
Ejemplo n.º 6
0
        static void InitService()
        {
            AutoInit.Init();

            zkAdaptor   = new ZkAdaptor();
            amqpAdaptor = new AmqpAdaptor(ConfigManager.MQIP(), ConfigManager.AMQPPort(),
                                          ConfigManager.MQUser(), ConfigManager.MQPass());

            ServiceImplementStub.Bind <IWatcherServiceNotifyImpl>(amqpAdaptor, new WatcherServiceImpl());

            //dbClientNotifyDelegate = new DbClientNotifyDelegate(zkAdaptor);
            watcherServiceNotifyDelegate = new WatcherServiceNotifyDelegate(amqpAdaptor);

            amqpAdaptor.BeginReceive();
            zkAdaptor.BeginReceive();

            var toWatch     = ConfigManager.Instance.Read <int>("WatcherService", "WatchNum");
            var watchGroups = new List <WatchGroup>();

            for (int i = 1; i <= toWatch; i++)
            {
                var group = new WatchGroup()
                {
                    GroupName       = ConfigManager.Instance.Read <string>("WatcherService", "WatchName" + i),
                    Quorum          = ConfigManager.Instance.Read <int>("WatcherService", "WatchQuorum" + i),
                    DownAfterPeriod = ConfigManager.Instance.Read <int>("WatcherService", "WatchDownAfter" + i),
                    ParallelSync    = ConfigManager.Instance.Read <int>("WatcherService", "WatchParallelSync" + i),
                    FailoverTime    = ConfigManager.Instance.Read <int>("WatcherService", "WatchFailoverTimeout" + i),
                };

                group.SetCurrentMaster(new MasterInstance(group)
                {
                    EndPoint = ConfigManager.Instance.Read <EndPoint>("WatcherService", "WatchAddr" + i),
                });

                watchGroups.Add(group);
            }

            watcherManager = new WatcherManager(watchGroups);
        }
Ejemplo n.º 7
0
 public void Dispatch(IRpcImplInstnce impl, RpcMethod method, ServiceImplementStub.SendResult cont)
 {
     switch (method.MethodId)
     {
     case 1:
         ((ICli2LogicImpl)impl).AskChangeName((UInt64)(method.Args[0]), (String)(method.Args[1])).ContinueWith(t => DoContinue(t, cont));
         break;
     case 2:
         ((ICli2LogicImpl)impl).AskAddMoney((UInt64)(method.Args[0]), (UInt32)(method.Args[1])).ContinueWith(t => DoContinue(t, cont));
         break;
     case 3:
         ((ICli2LogicImpl)impl).AskLearnSkill((UInt64)(method.Args[0]), (UInt32)(method.Args[1])).ContinueWith(t => DoContinue(t, cont));
         break;
     case 4:
         ((ICli2LogicImpl)impl).TestEnum((UInt64)(method.Args[0]), (TowerState)(method.Args[1])).ContinueWith(t => DoContinue(t, cont));
         break;
     case 5:
         ((ICli2LogicImpl)impl).TestArray((UInt64[])(method.Args[0]), (TowerState)(method.Args[1])).ContinueWith(t => DoContinue(t, cont));
         break;
     case 6:
         ((ICli2LogicImpl)impl).TestList((List<Boolean>)(method.Args[0]), (TowerState)(method.Args[1])).ContinueWith(t => DoContinue(t, cont));
         break;
     case 7:
         ((ICli2LogicImpl)impl).TestDict((Dictionary<Boolean, PlayerInfo>)(method.Args[0]), (TowerState)(method.Args[1])).ContinueWith(t => DoContinue(t, cont));
         break;
     case 8:
         ((ICli2LogicImpl)impl).RequestPlayerInfo((UInt64)(method.Args[0])).ContinueWith(t => DoContinue(t, cont));
         break;
     case 9:
         ((ICli2LogicImpl)impl).TestHierarchy((TestBaseClass)(method.Args[0]), (TestDerived1Class)(method.Args[1]), (TestDerived11Class)(method.Args[2])).ContinueWith(t => DoContinue(t, cont));
         break;
     case 10:
         ((ICli2LogicImpl)impl).TestHierarch2y((TestBaseClass)(method.Args[0]), (TestDerived1Class)(method.Args[1]), (TestDerived11Class)(method.Args[2])).ContinueWith(t => DoContinue(t, cont));
         break;
     }
 }
Ejemplo n.º 8
0
 public void Dispatch(IRpcImplInstnce impl, RpcMethod method, ServiceImplementStub.SendResult cont)
 {
     switch (method.MethodId)
     {
     case 1:
         ((IWatcherServiceNotifyImpl)impl).NotifyWatchingMaster((Byte[])(method.Args[0]), (String)(method.Args[1]));
         break;
     case 2:
         ((IWatcherServiceNotifyImpl)impl).NotifyInstanceSubjectiveDown((Byte[])(method.Args[0]), (String)(method.Args[1]));
         break;
     }
 }
Ejemplo n.º 9
0
 public void Dispatch(IRpcImplInstnce impl, RpcMethod method, ServiceImplementStub.SendResult cont)
 {
     switch (method.MethodId)
     {
     case 1:
         ((IDbClientNotifyImpl)impl).NotifyConnectionInfo((String)(method.Args[0]), (Int32)(method.Args[1]));
         break;
     }
 }
Ejemplo n.º 10
0
 public void Dispatch(IRpcImplInstnce impl, RpcMethod method, ServiceImplementStub.SendResult cont)
 {
     switch (method.MethodId)
     {
     case 1:
         ((ILoginNotifyImpl)impl).NotifyLogicServerWorking((String)(method.Args[0]));
         break;
     }
 }
Ejemplo n.º 11
0
 public void Dispatch(IRpcImplInstnce impl, RpcMethod method, ServiceImplementStub.SendResult cont)
 {
     switch (method.MethodId)
     {
     case 1:
         ((ILogic2SchedulerImpl)impl).RequestScheduleJob((Int32)(method.Args[0])).ContinueWith(t => DoContinue(t, cont));
         break;
     }
 }
Ejemplo n.º 12
0
 public void Dispatch(IRpcImplInstnce impl, RpcMethod method, ServiceImplementStub.SendResult cont)
 {
     switch (method.MethodId)
     {
     case 1:
         ((ICli2LoginImpl)impl).AskLogin((String)(method.Args[0]), (String)(method.Args[1]), (Byte[])(method.Args[2])).ContinueWith(t => DoContinue(t, cont));
         break;
     }
 }
Ejemplo n.º 13
0
 public void Dispatch(IRpcImplInstnce impl, RpcMethod method, ServiceImplementStub.SendResult cont)
 {
     switch (method.MethodId)
     {
     case 1:
         ((ICli2SceneImpl)impl).AskMoveTo((Int32)(method.Args[0]), (Int32)(method.Args[1])).ContinueWith(t => DoContinue(t, cont));
         break;
     }
 }
Ejemplo n.º 14
0
 public void Dispatch(IRpcImplInstnce impl, RpcMethod method, ServiceImplementStub.SendResult cont)
 {
     switch (method.MethodId)
     {
     case 1:
         ((ILogic2CliImpl)impl).ServerMessageOk();
         break;
     }
 }
Ejemplo n.º 15
0
 public void Dispatch(IRpcImplInstnce impl, RpcMethod method, ServiceImplementStub.SendResult cont)
 {
     switch (method.MethodId)
     {
     case 1:
         ((IScene2CliImpl)impl).SyncPosition((Int32)(method.Args[0]), (Int32)(method.Args[1]));
         break;
     }
 }