Exemplo n.º 1
0
        static void Main(string[] args)
        {
            #region 判断当前程序是否启动,如果已启动则退出,保证只有一个实例启动
            Mutex mutexApp = new Mutex(false, Assembly.GetExecutingAssembly().FullName, out bool appIsRunning);
            if (!appIsRunning)
            {
                LogHelper.WriteLog("程序已经运行,请不要重复打开");
                return;
            }
            #endregion

            LogHelper.WriteLog("程序启动");

            Random random = new Random();

            while (true)
            {
                ClientConf clientConf = GetConfInfo();
                string     localIP    = GetLocalIP(clientConf.localDnsAddress);
                if (string.IsNullOrEmpty(localIP))
                {
                    LogHelper.WriteLog("匹配本机IP地址失败,重新获取配置信息");
                    Thread.Sleep(TIME_UNIT);
                    continue;
                }

                // 更新IP地址信息
                UpdateIP(localIP);

                // 产生一个随机睡眠时间
                var sleepTime = random.Next(clientConf.minTime, clientConf.maxTime + 1);
                Thread.Sleep(TIME_UNIT * sleepTime);
            }
        }
        /// <summary>
        /// 构造函数,使用证书创建设备
        /// </summary>
        /// <param name="serverUri"></param>
        /// <param name="port"></param>
        /// <param name="deviceId"></param>
        /// <param name="deviceCert"></param>
        public AbstractDevice(string serverUri, int port, string deviceId, X509Certificate deviceCert)
        {
            ClientConf clientConf = new ClientConf();

            clientConf.ServerUri  = serverUri;
            clientConf.Port       = port;
            clientConf.DeviceId   = deviceId;
            clientConf.DeviceCert = deviceCert;
            this.deviceId         = deviceId;
            this.client           = new DeviceClient(clientConf, this);
            this.InitSysServices();
            Log.Info("create device: " + clientConf.DeviceId);
        }
Exemplo n.º 3
0
    protected override void InitUiOnAwake()
    {
        randomName = new RandomName();
        randomName.LoadRandomNameData();

        Btn_RandomName = GameTool.GetTheChildComponent <Button>(this.gameObject, "Btn_RandomName");
        Btn_RandomName.onClick.AddListener(SetPlayerName);

        Btn_Login = GameTool.GetTheChildComponent <Button>(this.gameObject, "Btn_Login");
        Btn_Login.onClick.AddListener(StartGame);


        inputField      = GameTool.GetTheChildComponent <InputField>(this.gameObject, "InputField");
        inputField.text = randomName.GetRandomName();

        clientConf = MeaninglessJson.LoadJsonFromFile <ClientConf>(MeaninglessJson.Path_StreamingAssets + "ClientConf.json");
    }
 public MqttConnection(ClientConf clientConf, RawMessageListener rawMessageListener, ConnectListener connectListener)
 {
     this.clientConf         = clientConf;
     this.rawMessageListener = rawMessageListener;
     this.connectListener    = connectListener;
 }