public IHttpActionResult GetSituation([FromBody] SourceAndId sai) { Situation selectedSituation; if (sai.sourceType) { selectedSituation = OwlWorker.GetSituation(sai.id); var gw = new GraphWorker(); selectedSituation = gw.FillCoordinates(selectedSituation, gw.MakeGraph(gw.SituationToGraph(selectedSituation.participants))); } else { var noSqlWorker = new NoSqlWorker(); noSqlWorker.Initialization(); selectedSituation = noSqlWorker.GetSituation(sai.id); if ((selectedSituation.coordinates == null) || (selectedSituation.coordinates.Count == 0)) { selectedSituation.coordinates = new List <Coordinate>(); var gw = new GraphWorker(); selectedSituation = gw.FillCoordinates(selectedSituation, gw.MakeGraph(gw.SituationToGraph(selectedSituation.participants))); } } if (selectedSituation == null) { return(NotFound()); } return(Ok(selectedSituation)); }
public void ToGraphWithCoordinatesTest() { //load situation var noSqlWorker = new NoSqlWorker(); noSqlWorker.Initialization(); var selectedSituation = noSqlWorker.GetSituation(13500410); //graph var gw = new GraphWorker(); var output = gw.SituationToGraph(selectedSituation.participants); var outputWithCoordinates = gw.MakeGraph(output); }
public string GetOneSituationNewCoordinate(string idInJson) { var noSqlWorker = new NoSqlWorker(); noSqlWorker.Initialization(); var id = JsonConvert.DeserializeObject <int>(idInJson); var selectedSituation = noSqlWorker.GetSituation(id); //graph var gw = new GraphWorker(); var output = gw.SituationToGraph(selectedSituation.participants); var outputWithCoordinates = gw.MakeGraph(output); var outputSituation = gw.FillCoordinates(selectedSituation, outputWithCoordinates); return(new JavaScriptSerializer().Serialize(outputSituation)); }
public async Task <IHttpActionResult> PostFromConstructor() { if (!Request.Content.IsMimeMultipartContent()) { return(BadRequest()); } var provider = new MultipartMemoryStreamProvider(); // путь к папке на сервере string root = HttpContext.Current.Server.MapPath("~/App_Data/"); await Request.Content.ReadAsMultipartAsync(provider); Situation newSit = null; foreach (var file in provider.Contents) { var filename = file.Headers.ContentDisposition.FileName.Trim('\"'); var owlString = file.ReadAsStringAsync(); ImportFromConstructor ifc = new ImportFromConstructor(); newSit = ifc.load_pps(owlString.Result); newSit.create_date = DateTime.Today; newSit.coordinates = new List <Coordinate>(); var gw = new GraphWorker(); newSit = gw.FillCoordinates(newSit, gw.MakeGraph(gw.SituationToGraph(newSit.participants))); var noSqlWorker = new NoSqlWorker(); noSqlWorker.Initialization(); noSqlWorker.Insert(newSit); //byte[] fileArray = await file.ReadAsByteArrayAsync(); //using (System.IO.FileStream fs = new System.IO.FileStream(root + filename, System.IO.FileMode.Create)) //{ // await fs.WriteAsync(fileArray, 0, fileArray.Length); //} } if (newSit == null) { return(NotFound()); } return(Ok(newSit)); }