Ejemplo n.º 1
0
        public SafeResponse Check([FromBody] SimpleData simpleData)
        {
            try {
                DA.Check();

                if ((simpleData != null) && (!string.IsNullOrEmpty(simpleData.Data)))
                {
                    apiUser = new ApiUser()
                    {
                        User_ID   = 0,
                        PublicKey = string.IsNullOrEmpty(simpleData.PublicKey) ? Globals.key_public : simpleData.PublicKey
                    };
                    using (SafeData sd = Encrypt_Data(simpleData.Data)) {
                        apiResponse = new SafeResponse(sd, CodeStatus.Ok);
                    }
                }
                else
                {
                    apiResponse = new SafeResponse(CodeStatus.Ok);
                }
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
                HttpContext.Response.StatusCode = 204; // No content - no connection to DataBase
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
                HttpContext.Response.StatusCode = 418; // I'm teapot
            }

            return(apiResponse);
        }
Ejemplo n.º 2
0
        public SafeResponse Check(string probe = "health")
        {
            try {
                DA.Check();
                apiResponse = new SafeResponse(CodeStatus.Ok);
            } catch (ApiException ae) {
                apiResponse.Status = ae.Status;
                Print(ae, Tool.GetCurrentMethod());
                HttpContext.Response.StatusCode = 500; // No content - no connection to DataBase
            } catch (Exception e) {
                apiResponse.Status = new ResponseStatus(CodeStatus.Unhandled_Exception);
                Print(e, Tool.GetCurrentMethod());
                HttpContext.Response.StatusCode = 418; // I'm teapot
            }

            Console.Out.WriteLine($"Probe {probe}: {apiResponse.Status.Detail}");

            return(apiResponse);
        }