public IResponse Execute(string payload) { JObject o = JsonConvert.DeserializeObject<JObject>(payload); int id; if (!Int32.TryParse(o[ZoneIdKey].ToString(), out id)) { return new ResponseFailure(Name, "Int32 parse error"); } RoadplusData data = new RoadplusData(); data.Schools.Where( s => s.ZoneId == id).Delete(); data.RoadConstructions.Where( rc => rc.ZoneId == id).Delete(); data.Edges.Where( e => e.ZoneId == id).Delete(); data.Vertices.Where( v => v.ZoneId == id).Delete(); data.Schools.Where( s => s.ZoneId == id).Delete(); data.RoadConstructions.Where( rc => rc.ZoneId == id).Delete(); data.Zones.Where( z => z.ZoneId == id).Delete(); return new RemoveResponse() { Command = Name, RemovedObjectId = id }; }
public IResponse Execute(string payload) { RoadplusData data = new RoadplusData(); return new GetMapResponse() { Vertices = data.Vertices.ToArray(), Edges = data.Edges.ToArray() }; }
public IResponse Execute(string payload) { JObject o = JsonConvert.DeserializeObject<JObject>(payload); int id; int vertexId; if (!Int32.TryParse(o[ZoneIdKey].ToString(), out id) || !Int32.TryParse(o[VertexIdKey].ToString(), out vertexId)) { return new ResponseFailure(Name, "Parse error"); } List<string> ports = new List<string>(); foreach (Link l in Source.Links) { ports.Add(l.Address); } if (!ports.Contains(o[PortNameKey].ToString())) { return new ResponseFailure(Name, "Port not available"); } RoadplusData data = new RoadplusData(); Zone target; try { target = data.Zones.Single(z => z.ZoneId == id); } catch (InvalidOperationException) { return new ResponseFailure(Name, "Zone not found"); } target.ArduinoPort = o[PortNameKey].ToString(); target.RadarVertexId = vertexId; data.Update<Zone>(target); Link link = Source.GetLinkByAddress(o[PortNameKey].ToString()); if (link is RoadLink) { RoadLink rlink = link as RoadLink; Service.Checker = new ZoneChecker(rlink, 5); return new ConnectRoadToZoneResponse() { ZoneId = id, RoadPort = o[PortNameKey].ToString() }; } return new ResponseFailure(Name, "port not found or connected"); }
public IResponse Execute(string payload) { RoadplusData data = new RoadplusData(); Zone[] zones = data.Zones.ToList().ToArray(); return new GetResponse() { Command = Name, RequestedObjects = zones }; }
public IResponse Execute(string payload) { JObject o = JsonConvert.DeserializeObject<JObject>(payload); int zoneId; int locationId; DateTime startDate = DateTime.ParseExact( o[StartDateKey].ToString(), "yyyy-MM-dd", CultureInfo.InvariantCulture); DateTime endDate = DateTime.ParseExact( o[EndDateKey].ToString(), "yyyy-MM-dd", CultureInfo.InvariantCulture); if (!Int32.TryParse(o[ZoneIdKey].ToString(), out zoneId) || !Int32.TryParse(o[LocationKey].ToString(), out locationId)) { return new ResponseFailure(Name, "Parse error"); } RoadplusData data = new RoadplusData(); if (!data.Zones.Any(z => z.ZoneId == zoneId)) { return new ResponseFailure(Name, "Zone does not exist"); } else if (!data.Edges.Any(e => e.EdgeId == locationId)) { return new ResponseFailure(Name, "Edge does not exist"); } RoadConstruction newRC = new RoadConstruction() { Name = o[NameKey].ToString(), ZoneId = zoneId, EdgeId = locationId, DateStart = startDate, DateEnd = endDate }; int id = Convert.ToInt32( data.InsertWithIdentity<RoadConstruction>(newRC)); newRC.RoadConstructionId = id; return new CreateResponse() { Command = Name, CreatedObject = newRC }; }
public IResponse Execute(string payload) { JObject o = JsonConvert.DeserializeObject<JObject>(payload); int zoneId; int locationId; DateTime openTime; DateTime closeTime; if (!Int32.TryParse(o[ZoneIdKey].ToString(), out zoneId) || !Int32.TryParse(o[LocationKey].ToString(), out locationId) || !DateTime.TryParseExact( o[OpenTimeKey].ToString(), "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out openTime) || !DateTime.TryParseExact( o[CloseTimekey].ToString(), "HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out closeTime)) { return new ResponseFailure(Name, "Parse error"); } RoadplusData data = new RoadplusData(); if (!data.Vertices.Any(v => v.VertexId == locationId) || !data.Zones.Any(z => z.ZoneId == zoneId)) { return new ResponseFailure(Name, "Nonexisting parent"); } School newSchool = new School() { Name = o[NameKey].ToString(), ZoneId = zoneId, VertexId = locationId, OpenTime = openTime, CloseTime = closeTime }; int id = Convert.ToInt32( data.InsertWithIdentity<School>(newSchool)); newSchool.SchoolId = id; return new CreateResponse() { Command = Name, CreatedObject = newSchool }; }
public IResponse Execute(string payload) { JObject o = JsonConvert.DeserializeObject<JObject>(payload); int id; if (!Int32.TryParse(o[idKey].ToString(), out id)) { return new ResponseFailure(Name, "Parse error"); } RoadplusData data = new RoadplusData(); data.Schools.Where(s => s.SchoolId == id).Delete(); return new RemoveResponse() { Command = Name, RemovedObjectId = id }; }
public IResponse Execute(string payload) { JObject json = JsonConvert.DeserializeObject<JObject>(payload); string name = json[NameKey].ToString(); RoadplusData data = new RoadplusData(); Zone newZone = new Zone() { Name = name, StartVertexId = 0, RadarVertexId = 0 }; int newZoneId = Convert.ToInt32( data.InsertWithIdentity<Zone>(newZone)); Vertex startVertex = new Vertex() { X = 0, Y = 0, ZoneId = newZoneId }; int startVertexId = Convert.ToInt32( data.InsertWithIdentity<Vertex>(startVertex)); newZone.ZoneId = newZoneId; newZone.StartVertexId = startVertexId; data.Update<Zone>(newZone); CreateResponse response = new CreateResponse() { Command = Name, CreatedObject = newZone }; return response; }
public IResponse Execute(string payload) { JObject o = JsonConvert.DeserializeObject<JObject>(payload); int zoneId, startVertexX, startVertexY, endVertexX, endVertexY; if (!Int32.TryParse(o[ZoneIdKey].ToString(), out zoneId) || !Int32.TryParse(o[startVertexXKey].ToString(), out startVertexX) || !Int32.TryParse(o[startVertexYKey].ToString(), out startVertexY) || !Int32.TryParse(o[endVertexXKey].ToString(), out endVertexX) || !Int32.TryParse(o[endVertexYKey].ToString(), out endVertexY)) { return new ResponseFailure( Name, "Int32 Parse error"); } RoadplusData data = new RoadplusData(); if (!data.Zones.Any(z => z.ZoneId == zoneId)) { return new ResponseFailure( Name, "Zone does not exist"); } Vertex startVertex = new Vertex() { ZoneId = zoneId, X = startVertexX, Y = startVertexY }; Vertex endVertex = new Vertex() { ZoneId = zoneId, X = endVertexX, Y = endVertexY }; int startVertexId = Convert.ToInt32( data.InsertWithIdentity<Vertex>(startVertex)); int endVertexId = Convert.ToInt32( data.InsertWithIdentity<Vertex>(endVertex)); startVertex.VertexId = startVertexId; endVertex.VertexId = endVertexId; Edge newEdge = new Edge() { ZoneId = zoneId, StartVertexId = startVertexId, EndVertexId = endVertexId, Weight = 0.0, MaxSpeed = 0 }; int edgeId = Convert.ToInt32( data.InsertWithIdentity<Edge>(newEdge)); newEdge.EdgeId = edgeId; return new EdgeSetResponse() { ZoneId = zoneId, CreatedEdge = newEdge, StartVertex = startVertex, EndVertex = endVertex }; }