Ejemplo n.º 1
0
        public IActionResult Get()
        {
            //TODO delete fake resources
            List <Resource> result = new List <Resource>();

            result.Add(new Light {
                Id = 1, Name = "lampe du salon", OnOff = false
            });
            result.Add(new Music {
                Id = 2, Name = "boombox", OnOff = false, Playing = false
            });

            ((Light)result[0]).Switch();

            try
            {
                Request.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");

                //TODO actual request
                if (result.Count == 0)
                {
                    return(StatusCode(404, "nothing was found"));
                }

                return(Ok(result));
            }
            catch (Exception e)
            {
                ErrorLaucher.Display(e);
                return(StatusCode(500, "Internal Error"));
            }
        }
Ejemplo n.º 2
0
 public void Add(T objectToAdd)
 {
     try
     {
         Set.Add(objectToAdd);
     }
     catch (Exception e)
     {
         throw ErrorLaucher.Launch(e);
     }
 }
Ejemplo n.º 3
0
 public T Find(T searchedObject)
 {
     try
     {
         return(Set.FirstOrDefault <T>(t => t.Equals(searchedObject)));
     }
     catch (Exception e)
     {
         throw ErrorLaucher.Launch(new Exception("you really f****d up..."));
     }
 }
Ejemplo n.º 4
0
 private new void  CloseConnection()
 {
     try
     {
         _connection.Dispose();
         _connection.Close();
     }
     catch (Exception e)
     {
         throw ErrorLaucher.Launch(e);
     }
 }
Ejemplo n.º 5
0
 private new void OpenConnection()
 {
     try
     {
         _connection = new NpgsqlConnection(connectionString);
         _connection.Open();
     }
     catch (Exception e)
     {
         throw ErrorLaucher.Launch(e);
     }
 }
Ejemplo n.º 6
0
 private static Request SplitRequest(string demand)
 {
     try
     {
         Request r = new Request();
         r = JsonUtility.Deserialize <Request>(demand);
         return(r);
     }
     catch (Exception e)
     {
         throw ErrorLaucher.Launch(e);
     }
 }
Ejemplo n.º 7
0
 public void SendRequest(string ip, int port)
 {
     using (_client = new TCPClient(ip, port))
     {
         if (ManagerRequest != null)
         {
             _client.SendContent(ManagerRequest.ToString());
         }
         else
         {
             throw ErrorLaucher.Launch(new EmptyRequestException("you must initialize the request before sending it"));
         }
     }
 }
Ejemplo n.º 8
0
        public override bool ExecuteRequest(string status, string options)
        {
            try
            {
                NetworkTCPManager manager = new NetworkTCPManager();

                manager.SendRequest("127.0.0.1", 501);

                return(true);
            }
            catch (EmptyRequestException e)
            {
                ErrorLaucher.Display(e);
                return(false);
            }
            catch (Exception e)
            {
                ErrorLaucher.Display(e);
                return(false);
            }
        }
Ejemplo n.º 9
0
        public IActionResult Post(string request)
        {
            Request.HttpContext.Response.Headers.Add("Access-Control-Allow-Origin", "*");
            try
            {
                if (request == "" || request == null)
                {
                    return(StatusCode(400, "the request is empty"));
                }

                return(DemandAnalyzer.AnalyzeAndExecute(request) ? StatusCode(200, "Request made") : StatusCode(500, "Network Error"));
            }
            catch (JsonSerializationException jsonex)
            {
                ErrorLaucher.Display(jsonex);
                return(StatusCode(500, "Internal Error. Request format is not valid"));
            }
            catch (Exception e)
            {
                ErrorLaucher.Display(e);
                return(StatusCode(500, "Internal Error"));
            }
        }
Ejemplo n.º 10
0
 public virtual string GetError()
 {
     throw ErrorLaucher.Launch(new ControllerMustBeSpecializedException("You must only execut request from specialized controllers instances"));
 }
Ejemplo n.º 11
0
 public virtual bool ExecuteRequest(string status, string options)
 {
     throw ErrorLaucher.Launch(new ControllerMustBeSpecializedException("You must only execut request from specialized controllers instances"));
 }