Exemplo n.º 1
0
 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);
         }
     }
 }
Exemplo n.º 2
0
 // 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);
         }
     }
 }
Exemplo n.º 3
0
 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);
         }
     }
 }
Exemplo n.º 4
0
    // 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;
        }
    }
Exemplo n.º 5
0
        /// <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));
        }
Exemplo n.º 6
0
    // 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;
        }
    }
Exemplo n.º 7
0
        // 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));
        }
Exemplo n.º 9
0
        // 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."));
                }
            }
        }
Exemplo n.º 10
0
        // 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.");
                }
            }
        }
Exemplo n.º 11
0
 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);
         }
     }
 }
Exemplo n.º 12
0
 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);
         }
     }
 }
Exemplo n.º 13
0
 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));
        }
Exemplo n.º 15
0
 // 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);
         }
     }
 }
Exemplo n.º 16
0
 // 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);
         }
     }
 }
Exemplo n.º 17
0
 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));
 }
Exemplo n.º 19
0
 static BridgeController()
 {
     BridgeLock  = new object();
     BridgeState = BridgeState.Running;
 }
Exemplo n.º 20
0
 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);
         }
     }
 }