Example #1
0
        /// <summary>
        /// 传入UserID初始化LabDataCollect
        /// </summary>
        /// <param name="userId"></param>
        public void LabDataCollectInit(Func <string> userId)
        {
            if (_isClientInit)
            {
                return;
            }

            #region 初始化本地存储
            _localSaveDataTimeLayout = LabTools.GetConfig <LabDataConfig>().LocalSaveDataTimeLayout;
            _userId       = userId;
            _saveDataPath = Application.dataPath + "/Output";
            LabTools.CreatSaveDataFolder(_saveDataPath);
            var userStr = _userId.Invoke().PadLeft(2, '0');
            _saveDataPath = string.Join("_", _saveDataPath + "/" + DateTime.Now.ToString(_localSaveDataTimeLayout), userStr);
            _saveDataPath = LabTools.CreatSaveDataFolder(_saveDataPath);
            #endregion

            #region 初始化上传服务

            var options = new DataSyncClientOptions()
            {
                EndpointAddress = "http://localhost:4000/api/data",
                ProjectId       = LabTools.GetConfig <LabDataConfig>().ProjectId,
                LogFilePath     = labDataSavePath + "/ log.txt"
            };

            //Docker
            options.EndpointAddress = "http://localhost/api/data";

            //server
            _sendToServer           = LabTools.GetConfig <LabDataConfig>().SendToServer;
            options.EndpointAddress = LabTools.GetConfig <LabDataConfig>().ServerPath;


            if (!Directory.Exists("TestStore"))
            {
                Directory.CreateDirectory("TestStore");
            }
            _applicationLifecycle = new SimpleApplicationLifecycle();


            _client = new DataSyncClient(new UnityApplicationFolderProvider(labDataSavePath + "/TestStore"),
                                         _applicationLifecycle, options, _userId);

            _client.Init();

            _isClientInit = true;

            StartUpload();

            #endregion

            Application.wantsToQuit += () => !IsClientRunning;
            _dataWriterDic           = new Dictionary <Type, LabDataWriter>();
            _dataQueue   = new ConcurrentQueue <LabDataBase>();
            _writeThread = new Thread(Queue2Send);
            _writeThread.Start();
        }
Example #2
0
        /// <summary>
        /// 传入UserID初始化LabDataCollect
        /// </summary>
        /// <param name="userId"></param>
        public void LabDataCollectInit(string userId)
        {
            _localSaveDataTimeLayout = LabTools.GetConfig <LabDataConfig>().LocalSaveDataTimeLayout;
            if (_isClientInit)
            {
                return;
            }
            _userId = userId;
            //StartAutoDataCollect();
            var options = new DataSyncClientOptions()
            {
                EndpointAddress = "http://localhost:4000/api/data",
                ProjectId       = LabTools.GetConfig <LabDataConfig>().ProjectId,
                LogFilePath     = labDataSavePath + "/ log.txt"
            };

            //Docker
            options.EndpointAddress = "http://localhost/api/data";

            //server

            /*
             * _sendToServer = LabTools.GetConfig<LabDataConfig>().SendToServer;
             * options.EndpointAddress = LabTools.GetConfig<LabDataConfig>().ServerPath;
             * //SendDataToServer(0,0,0);
             */



            if (!Directory.Exists("TestStore"))
            {
                Directory.CreateDirectory("TestStore");
            }
            _applicationLifecycle = new SimpleApplicationLifecycle();


            _client = new DataSyncClient(new UnityApplicationFolderProvider(labDataSavePath + "/TestStore"),
                                         _applicationLifecycle, options, () => _userId);

            _client.Init();

            _isClientInit = true;

            StartUpload();
        }
Example #3
0
        ///connect to wmlab
        ///

        public void SendDataToServer(string finishMinutes, string finishSeconds, int wrongtimes)
        {
            _dataList?.Add(new ATMResultData(finishMinutes, finishSeconds, wrongtimes)
            {
                Tasktype   = finishMinutes,
                Finishtime = finishSeconds,
                Wrongtimes = wrongtimes
            });

            isFinished = false;
            var o = JsonConvert.SerializeObject(_dataList);
            // Debug.Log(o);
            var request = new HTTPRequest(new Uri(LabTools.GetConfig <LabDataConfig>().ServerPath), HTTPMethods.Post, OnRequestFinished) //POST
            {
                RawData = Encoding.UTF8.GetBytes(o)
            };

            if (!request.HasHeader("Content-Type"))
            {
                request.SetHeader("Content-Type", "application/json");
            }
            request.Send();
            Debug.Log("request.Send()");
        }