Exemple #1
0
        public virtual IActionResult ExportCsvFile([FromBody] ExportCsv exportSettings, [FromHeader][Required] string Authorization)
        {
            if (!ModelState.IsValid)
            {
                var error = ModelState.SelectMany(x => x.Value.Errors).First();
                if (error.ErrorMessage != null && error.ErrorMessage != String.Empty)
                {
                    return(BadRequest(error.ErrorMessage));
                }
                else if (error.Exception?.Message != null)
                {
                    return(BadRequest("Faulty input"));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            if (Authorization != settings.testToken)
            {
                return(BadRequest("Not allowed"));
            }
            string errorMessage   = "";
            string dataStreamInfo = "";

            try
            {
                ExportCsvResult res              = new ExportCsvResult();
                string          filename         = System.Guid.NewGuid().ToString() + ".csv";
                string          filenameWithPath = "." + Path.DirectorySeparatorChar + "wwwroot" + Path.DirectorySeparatorChar + filename;


                DatabaseInterface.DBObservation dBo = new DatabaseInterface.DBObservation();
                if (!dBo.FindDataStreamId(int.Parse(exportSettings.ThingId), exportSettings.ObservationType, ref errorMessage, ref dataStreamInfo))
                {
                    return(BadRequest("Internal Server Error:" + errorMessage));
                }
                // PArse out the ID
                string tmp = dataStreamInfo.Substring(dataStreamInfo.IndexOf("(") + 1);
                tmp = tmp.Substring(0, tmp.IndexOf(")"));
                string url = "http://monappdwp3.monica-cloud.eu:8088/gost_wdom/" + tmp + "?from=" + exportSettings.StartTime.ToString("o") + "&to=" + exportSettings.EndTime.ToString("o");
                try
                {
                    WebClient wc = new WebClient();
                    wc.DownloadFile(url, filenameWithPath);
                }
                catch (WebException we)
                {
                    // add some kind of error processing

                    BadRequest("Internal Server Error:" + we.ToString());
                }
                res.Path = filename;
                return(new ObjectResult(res));
            }
            catch (Exception e)
            {
                return(BadRequest("Internal Server Error:" + e.Message));
            }
        }
Exemple #2
0
        public virtual IActionResult ObservationPost([FromBody] Observation thingid, [FromHeader] string Authorization)
        {
            if (!ModelState.IsValid)
            {
                var error = ModelState.SelectMany(x => x.Value.Errors).First();
                if (error.ErrorMessage != null && error.ErrorMessage != String.Empty)
                {
                    return(BadRequest(error.ErrorMessage));
                }
                else if (error.Exception?.Message != null)
                {
                    return(BadRequest("Faulty input"));
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            long   newWearableID = 0;
            string errorMessage  = "";

            try
            {
                DatabaseInterface.DBObservation dBObservation = new DatabaseInterface.DBObservation();
                if (!dBObservation.AddUpdateObservation(thingid.ThingId, thingid.DatastreamId, thingid.PhenomenTime, thingid.ObservationResult, thingid.Personid, thingid.Zoneid, ref errorMessage, ref newWearableID))
                {
                    return(BadRequest("Internal Server Error:" + errorMessage));
                }
            }
            catch (Exception e)
            {
                return(BadRequest("Internal Server Error:" + e.Message));
            }


            //TODO: Uncomment the next line to return response 200 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(200, default(GeneralResponse));

            //TODO: Uncomment the next line to return response 0 or use other options such as return this.NotFound(), return this.BadRequest(..), ...
            // return StatusCode(0, default(ErrorResponse));


            string exampleJson = null;

            exampleJson = "{\n  \"success\" : true,\n  \"newid\" : " + newWearableID.ToString() + "\n}";

            var example = exampleJson != null
            ? JsonConvert.DeserializeObject <GeneralPostResponse>(exampleJson)
            : default(GeneralPostResponse);

            //TODO: Change the data returned
            return(new ObjectResult(example));
        }