private static void MakeConfigRequest() { using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(BridgeBaseAddress); var content = new StringContent( CreateConfigRequestContentAsJson(), Encoding.UTF8, "application/json"); try { var response = httpClient.PostAsync("/config/", content).GetAwaiter().GetResult(); if (!response.IsSuccessStatusCode) { string reason = String.Format("{0}Bridge returned unexpected status code='{1}', reason='{2}'", Environment.NewLine, response.StatusCode, response.ReasonPhrase); if (response.Content != null) { string contentAsString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); reason = String.Format("{0}, content:{1}{2}", reason, Environment.NewLine, contentAsString); } throw new Exception(reason); } _BridgeStatus = BridgeState.Started; } catch (Exception exc) { _BridgeStatus = BridgeState.Faulted; throw new Exception("Bridge is not running", exc); } } }
// Issues a GET request to the Bridge base address to determine // whether it is running. This method also sets state to indicate // whether the bridge is running or unavailable. private static void PingBridge() { using (HttpClient httpClient = new HttpClient()) { try { var response = httpClient.GetAsync(BridgeBaseAddress).GetAwaiter().GetResult(); if (!response.IsSuccessStatusCode) { string reason = String.Format("{0}Bridge returned unexpected status code='{1}', reason='{2}'", Environment.NewLine, response.StatusCode, response.ReasonPhrase); if (response.Content != null) { string contentAsString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); if (contentAsString.Length > 1000) { contentAsString = contentAsString.Substring(0, 999) + "..."; } reason = String.Format("{0}, content:{1}{2}", reason, Environment.NewLine, contentAsString); } throw new Exception(reason); } _BridgeStatus = BridgeState.Started; } catch (Exception exc) { _BridgeStatus = BridgeState.Faulted; throw new Exception("Bridge is not running", exc); } } }
private static void MakeConfigRequest() { using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(BridgeBaseAddress); string resourceFolder = TestProperties.GetProperty(TestProperties.BridgeResourceFolder_PropertyName); string contentPayload = "{ resourcesDirectory : \"" + resourceFolder + "\" }"; var content = new StringContent( contentPayload, Encoding.UTF8, "application/json"); try { var response = httpClient.PostAsync("/config/", content).Result; if (!response.IsSuccessStatusCode) throw new Exception("Unexpected status code: " + response.StatusCode); _BridgeStatus = BridgeState.Started; } catch (Exception exc) { _BridgeStatus = BridgeState.Faulted; throw new Exception("Bridge is not running", exc); } } }
// Update is called once per frame void Update() { _Time += Time.deltaTime; switch (State) { case BridgeState.Open: if (_Time > OpenTime) { _Time = 0; State = BridgeState.Close; anim.SetTrigger("OpenTrigger"); } break; case BridgeState.Close: if (_Time > ClosedTime) { _Time = 0; anim.SetTrigger("OpenTrigger"); State = BridgeState.Open; } break; } }
/// <summary> /// Get bridge info /// </summary> /// <returns></returns> public async Task <Bridge> GetBridgeAsync() { CheckInitialized(); HttpClient client = await GetHttpClient().ConfigureAwait(false); var stringResult = await client.GetStringAsync(new Uri(ApiBase)).ConfigureAwait(false); BridgeState jsonResult = DeserializeResult <BridgeState>(stringResult); return(new Bridge(jsonResult)); }
// Activate the whole bridge IEnumerator ActivateBridgeCoroutine() { for (int i = 0; i < blocks.Length; i++) { blockController[i].ActivateBlock(transitionTime / blockCount); yield return(new WaitForSeconds(0.5f)); } if (currentPosition == BridgeState.ACTIVATED) { currentPosition = BridgeState.DEACTIVATED; } else { currentPosition = BridgeState.ACTIVATED; } }
// Issues a GET request to the Bridge base address to determine // whether it is running. This method also sets state to indicate // whether the bridge is running or unavailable. private static void PingBridge() { using (HttpClient httpClient = new HttpClient()) { try { var response = httpClient.GetAsync(BridgeEndpointAddress).GetAwaiter().GetResult(); EnsureSuccessfulResponse(response); s_BridgeStatus = BridgeState.Started; } catch (Exception exc) { s_BridgeStatus = BridgeState.Faulted; s_BridgeFaultReason = String.Format("A GET request was issued to '{0}' but encountered exception {1}", BridgeEndpointAddress, exc.Message); throw new Exception(s_BridgeFaultReason, exc); } } }
public JsonResult EditBridgeState(BridgeState bridgeState) { if (bridgeState.Time == null || bridgeState.TopPart == null || bridgeState.BottomPart == null || bridgeState.LeftPart == null || bridgeState.RightPart == null)//输入框为空 { return(Json(new { code = 401 }, JsonRequestBehavior.AllowGet)); } var getBridgeId = db.Queryable <BridgeState>().Where(it => it.Id == bridgeState.Id).ToList(); BridgeState newBridgeState = new BridgeState { Id = bridgeState.Id, BridgeId = getBridgeId[0].Id, Time = bridgeState.Time, TopPart = bridgeState.TopPart, BottomPart = bridgeState.BottomPart, LeftPart = bridgeState.LeftPart, RightPart = bridgeState.RightPart }; db.Updateable(newBridgeState).ExecuteCommand(); return(Json(new { code = 200 }, JsonRequestBehavior.AllowGet)); }
// The DELETE Http verb means stop the Bridge cleanly public HttpResponseMessage Delete(HttpRequestMessage request) { Trace.WriteLine(String.Format("{0:T} - received DELETE request", DateTime.Now), typeof(BridgeController).Name); lock (BridgeLock) { if (BridgeState == BridgeState.Running) { // 'Stopping' is the Bridge's terminal state because // the process itself will terminate during this response. BridgeState = BridgeState.Stopping; try { HttpResponseMessage response = request.CreateResponse(HttpStatusCode.OK); response.Content = new ExitOnDisposeStringContent("\"The Bridge has closed.\""); response.Content.Headers.ContentType = new MediaTypeHeaderValue(JsonSerializer.JsonMediaType); return(response); } catch (Exception ex) { var exceptionResponse = ex.Message; Trace.WriteLine(String.Format("{0:T} - DELETE config exception:{1}{2}", DateTime.Now, Environment.NewLine, ex), typeof(BridgeController).Name); return(request.CreateResponse(HttpStatusCode.BadRequest, exceptionResponse)); } } else { // Multiple concurrent DELETE requests are blocked by the monitor. // But in case the process has not yet terminated from the first request, // send back BADREQUEST for any others. return(request.CreateResponse(HttpStatusCode.BadRequest, "Bridge is already stopping.")); } } }
// The DELETE Http verb means stop the Bridge cleanly public HttpResponseMessage Delete(HttpRequestMessage request) { Trace.WriteLine(String.Format("{0:T} - received DELETE request", DateTime.Now), typeof(BridgeController).Name); lock (BridgeLock) { if (BridgeState == BridgeState.Running) { // 'Stopping' is the Bridge's terminal state because // the process itself will terminate during this response. BridgeState = BridgeState.Stopping; try { HttpResponseMessage response = request.CreateResponse(HttpStatusCode.OK); response.Content = new ExitOnDisposeStringContent("\"The Bridge has closed.\""); response.Content.Headers.ContentType = new MediaTypeHeaderValue(JsonSerializer.JsonMediaType); return response; } catch (Exception ex) { var exceptionResponse = ex.Message; Trace.WriteLine(String.Format("{0:T} - DELETE config exception:{1}{2}", DateTime.Now, Environment.NewLine, ex), typeof(BridgeController).Name); return request.CreateResponse(HttpStatusCode.BadRequest, exceptionResponse); } } else { // Multiple concurrent DELETE requests are blocked by the monitor. // But in case the process has not yet terminated from the first request, // send back BADREQUEST for any others. return request.CreateResponse(HttpStatusCode.BadRequest, "Bridge is already stopping."); } } }
private static void MakeConfigRequest() { using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(BridgeBaseAddress); var content = new StringContent( @"{ resourcesDirectory : ""WcfService"" }", Encoding.UTF8, "application/json"); try { var response = httpClient.PostAsync("/config/", content).Result; if (!response.IsSuccessStatusCode) throw new Exception("Unexpected status code: " + response.StatusCode); _BridgeStatus = BridgeState.Started; } catch (Exception exc) { _BridgeStatus = BridgeState.Faulted; throw new Exception("Bridge is not running", exc); } } }
private static void MakeConfigRequest() { using (HttpClient httpClient = new HttpClient()) { var content = new StringContent( CreateConfigRequestContentAsJson(), Encoding.UTF8, "application/json"); try { var response = httpClient.PostAsync(BridgeConfigEndpointAddress, content).GetAwaiter().GetResult(); EnsureSuccessfulResponse(response); s_BridgeStatus = BridgeState.Started; } catch (Exception exc) { s_BridgeStatus = BridgeState.Faulted; s_BridgeFaultReason = String.Format("A POST request was issued to '{0}' but encountered exception {1}", BridgeConfigEndpointAddress, exc.Message); throw new Exception(s_BridgeFaultReason, exc); } } }
private static void MakeConfigRequest() { using (HttpClient httpClient = new HttpClient()) { httpClient.BaseAddress = new Uri(BridgeBaseAddress); var content = new StringContent( CreateConfigRequestContentAsJson(), Encoding.UTF8, "application/json"); try { var response = httpClient.PostAsync("/config/", content).GetAwaiter().GetResult(); if (!response.IsSuccessStatusCode) { string reason = String.Format("{0}Bridge returned unexpected status code='{1}', reason='{2}'", Environment.NewLine, response.StatusCode, response.ReasonPhrase); if (response.Content != null) { string contentAsString = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); if (contentAsString.Length > 1000) { contentAsString = contentAsString.Substring(0, 999) + "..."; } reason = String.Format("{0}, content:{1}{2}", reason, Environment.NewLine, contentAsString); } throw new Exception(reason); } _BridgeStatus = BridgeState.Started; } catch (Exception exc) { _BridgeStatus = BridgeState.Faulted; throw new Exception("Bridge is not running", exc); } } }
public ActionResult Submit(BridgeStateDTO inform) { if (inform.BridgeName == null || inform.Time == null)//输入框为空 { return(Json(new { code = 401 }, JsonRequestBehavior.AllowGet)); } var bridgeId = Convert.ToInt32(inform.BridgeName.Split(' ')[0]); var ifExist = db.Queryable <BridgeState>().Where(it => it.BridgeId == bridgeId && it.Time == inform.Time).ToList(); if (ifExist.Count != 0)//已存在同桥梁同时间的记录 { return(Json(new { code = 404 }, JsonRequestBehavior.AllowGet)); } var list = db.Queryable <BridgeState>().ToList(); int id = 0; if (list != null) { id = list[list.Count - 1].Id + 1; } BridgeState bridgeState = new BridgeState { Id = id, BridgeId = bridgeId, Time = inform.Time, LeftPart = inform.LeftPart, RightPart = inform.RightPart, TopPart = inform.TopPart, BottomPart = inform.BottomPart }; db.Insertable(bridgeState).ExecuteCommand(); return(Json(new { code = 200 }, JsonRequestBehavior.AllowGet)); }
static BridgeController() { BridgeLock = new object(); BridgeState = BridgeState.Running; }
public JsonResult DeleteBridgeState(BridgeState bridgeState) { db.Deleteable <BridgeState>().In(bridgeState.Id).ExecuteCommand(); return(Json(new { code = 200 }, JsonRequestBehavior.AllowGet)); }