Exemplo n.º 1
0
        public TrajectoryResponse GetTrajectory(TrajectoryRequest request)
        {
            TrajectoryMapper trajectoryMapper = new TrajectoryMapper(request.Map);
            IReader          reader           = new CSVReader(request.FilePath);

            // Get the data
            trajectoryMapper.GetData(reader);

            // Get the mapped trajectories
            var trajectories = trajectoryMapper.GetTrajectories();

            return(new TrajectoryResponse()
            {
                Trajectories = trajectories.ToArray()
            });
        }
Exemplo n.º 2
0
        public async Task <HttpResponseMessage> PlotTrajectory()
        {
            try
            {
                HttpRequestMessage requestMessage = this.Request;

                if (!requestMessage.Content.IsMimeMultipartContent())
                {
                    throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
                }

                TrajectoryRequest request = new TrajectoryRequest();

                string root     = System.Web.HttpContext.Current.Server.MapPath(FILE_UPLOAD_PATH);
                var    provider = new MultipartFormDataStreamProvider(root);

                var result = await Request.Content.ReadAsMultipartAsync(provider);

                var map = result.FormData["map"];

                SOM som = JsonConvert.DeserializeObject <SOM>(map);

                string file = provider.FileData.Last().LocalFileName;

                IReader reader = new CSVReader(file);

                TrajectoryMapper trajectoryMapper = new TrajectoryMapper(som);
                trajectoryMapper.GetData(reader);

                TrajectoryResponse trajectoryResponse = new TrajectoryResponse()
                {
                    Trajectories = trajectoryMapper.GetTrajectories().ToArray()
                };

                File.Delete(result.FileData.First().LocalFileName);

                return(Request.CreateResponse(HttpStatusCode.OK, trajectoryResponse));
            } catch (Exception ex)
            {
                return(Request.CreateErrorResponse(HttpStatusCode.InternalServerError, ex));
            }
        }