Exemplo n.º 1
0
        public static void Init(Net2Config net2_config, DelegateGetResponse response_callback = null)
        {
            if (net2_config == null || string.IsNullOrEmpty(net2_config.name_space) ||
                string.IsNullOrEmpty(net2_config.consul_network_address) ||
                string.IsNullOrEmpty(net2_config.consul_network_mask) ||
                net2_config.consul_network_port == 0 ||
                string.IsNullOrEmpty(net2_config.ntp_server_host_name) ||
                net2_config.ntp_server_port == 0)
            {
                throw new ArgumentException();
            }

            Instance.Initialize(net2_config, response_callback);
        }
Exemplo n.º 2
0
        private void Initialize(Net2Config net2_config, DelegateGetResponse response_callback)
        {
            lock (padlock)
            {
                if (state == Net2State.STOPPED)
                {
                    channels_list = new Dictionary <ulong, Net2HandlerBase>();

                    if (response_callback == null)
                    {
                        GetResponse = ResponseCallback;
                    }
                    else
                    {
                        GetResponse = response_callback;
                    }

                    this.net2_config      = net2_config;
                    local_network_address = net2_config.local_network_address;

                    Net2NTPClient.delegateNewLogx += delegateNewLog;
                    net2_ntp = new Net2NTPClient(net2_config.ntp_server_host_name, true);


                    delegateNewLog("test", LogType.INFO, "test");

                    net2_consul = new Net2Consul("http://" + net2_config.consul_network_address + ":" + net2_config.consul_network_port, net2_config.consul_mode);

                    main_timer          = new System.Timers.Timer();
                    main_timer.Interval = 1000;
                    main_timer.Elapsed += Main_timer_Elapsed;
                    main_timer.Enabled  = true;
                    main_timer.Start();

                    state = Net2State.STARTED;
                }
                else
                {
                    throw new Exception("Already inited");
                }
            }
        }