private void bt_LR_Start_Click(object sender, EventArgs e) { var LRSession = new CBLRItem(); LRSession.sensor_id = sensorID; var client = new RestClient(iCrt_01.Properties.Resources.CBMasServer); var request = new RestRequest(Method.POST); lbl_LR_Status.Text = "Attempting to connect. Please wait. "; request.AddHeader("X-Auth-Token", iCrt_01.Properties.Resources.CBApiKey); request.Resource = "/v1/cblr/session"; request.RequestFormat = DataFormat.Json; request.AddBody(LRSession); //We'll loop this portion until we get the session status of active back. This could take a bit as in some environments there are a lot //of old sessions. Not sure when CB does the old session clean up. while (status != "active") { var response = client.Execute <List <CBLRItem> >(request); try { foreach (CBLRItem item in response.Data) { sessionID = item.id; status = item.status; lbl_CWD.Text = item.current_working_directory; //answer = item; } lbl_LR_Status.Text = "Connected, Session ID: " + sessionID.ToString(); } catch { //Look for existing sensor ID if this is thrown. //Assuming we got here due to an existing session. Starting new request. var request_existingsession = new RestRequest(); request_existingsession.AddHeader("X-Auth-Token", iCrt_01.Properties.Resources.CBApiKey); request_existingsession.Resource = "/v1/cblr/session"; var response_exist = client.Execute <List <CBLRItem> >(request_existingsession); foreach (CBLRItem item in response_exist.Data) { if (item.sensor_id == sensorID) { sessionID = item.id; if (item.status != "active") { continue; } status = item.status; lbl_CWD.Text = item.current_working_directory; } //answer = item; } lbl_LR_Status.Text = "Connected, Session ID: " + sessionID.ToString(); } } }
private void bt_LR_End_Click(object sender, EventArgs e) { var LRSession = new CBLRItem(); LRSession.status = "close"; var client = new RestClient(iCrt_01.Properties.Resources.CBMasServer); var request = new RestRequest(Method.PUT); request.AddHeader("X-Auth-Token", iCrt_01.Properties.Resources.CBApiKey); request.Resource = "/v1/cblr/session/" + sessionID; request.RequestFormat = DataFormat.Json; request.AddBody(LRSession); var response = client.Execute <List <CBLRItem> >(request); lbl_LR_Status.Text = "Disconnected"; }