public void SaveActiveAnswer(string email, string ans, string tim) { Stack <ConidAndAnswer> usersAtLocation = new Stack <ConidAndAnswer>(); ConidAndAnswer data = new ConidAndAnswer(); try { LogMsg("SaveActiveAnswer", "Top "); LogMsg("email", email); LogMsg("ans", ans); LogMsg("time", tim.ToString()); string conString = ConfigurationManager.ConnectionStrings["Easypassworld2017ConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(); con.ConnectionString = conString; string strr = "execute [insertAnwer]" + "'" + email + "'" + "," + "'" + ans + "'" + "," + "'" + tim + "'"; SqlDataAdapter da = new SqlDataAdapter(strr, con); DataTable dtt = new DataTable(); da.Fill(dtt); LogMsg("SaveActiveAnswer", "Bottom"); } catch (Exception e) { LogMsg("SaveActiveAnswer", "Failed " + e.ToString()); } }
public Stack <ConidAndAnswer> getUserByLocatnAndTimeForTraffic(double minlat, double maxlat, double minlon, double maxlon, string tim) { Stack <ConidAndAnswer> usersAtLocation = new Stack <ConidAndAnswer>(); ConidAndAnswer data = new ConidAndAnswer(); try { LogMsg("Block 6 Time", tim); LogMsg("Block 6", "I entered Block 6"); string conString = ConfigurationManager.ConnectionStrings["Easypassworld2017ConnectionString"].ConnectionString; SqlConnection con = new SqlConnection(); con.ConnectionString = conString; string strr = "execute getUserByLocatnForTraffic2" + "'" + minlat + "'" + "," + "'" + maxlat + "'" + "," + "'" + minlon + "'" + "," + "'" + maxlon + "'" + "," + "'" + tim + "'"; SqlDataAdapter da = new SqlDataAdapter(strr, con); DataTable dtt = new DataTable(); da.Fill(dtt); LogMsg("Block 7", "I entered Block 7"); if (dtt.Rows.Count > 0) { for (int i = 0; i < 10; i++) { data.conid = dtt.Rows[i]["conId"].ToString(); data.answer = dtt.Rows[i]["answer"].ToString(); LogMsg("Block 7 answer", data.answer); LogMsg("Block 7 Conid", data.conid); usersAtLocation.Push(data); } } } catch (Exception e) { LogMsg("Block 8", e.ToString()); } return(usersAtLocation); }
public void onTrafficQuestion(PrivateMessage data) { //Get the connectionid of the user from the database string fromConn = GetConnection(data.From); LogMsg("From", data.From); //Select the connectionid of all users at the specified location from the database //Add the selected connectionIds to a new group //Send the request to all of them LogMsg("Traffic", "I entered traffic block"); Stack <string> usersAtLocation = new Stack <string>(); Stack <ConidAndAnswer> usersAtLocation2 = new Stack <ConidAndAnswer>(); usersAtLocation2 = getUserByLocatnAndTimeForTraffic(data.MinLat, data.MaxLat, data.MinLongi, data.MaxLongi, data.tim); ConidAndAnswer ConnectionIds = null; if (usersAtLocation2.Count > 0) { LogMsg("Level1", "inside level1"); LogMsg("Count", usersAtLocation2.Count.ToString()); int veryfree = 0; int movinslowly = 0; int standstill = 0; //Analyse the data while (usersAtLocation2.Count > 0) { LogMsg("Level2", "inside level2"); ConnectionIds = usersAtLocation2.Pop(); if (ConnectionIds.answer == "Very Free") { veryfree += 1; } else if (ConnectionIds.answer == "Moving Slowly") { movinslowly += 1; } else if (ConnectionIds.answer == "Standstill") { standstill += 1; } } //Find the highest answer String result = "Very Free"; int high = veryfree; if (high < movinslowly) { LogMsg("Level3", "inside level3"); high = movinslowly; result = "Moving Slowly"; } else if (high < standstill) { high = standstill; result = "Standstill"; } //Send anawer back PrivateMessage trafficData = new PrivateMessage(); trafficData.type = "trafficAnswer"; trafficData.trafficAnswer = result; trafficData.From = "activeAnswer"; trafficData.To = fromConn; trafficData.msgId = data.msgId; Clients.Client(fromConn).TrafficAnswer(trafficData); } else { LogMsg("Level4", "inside level4"); usersAtLocation = getUserByLocatnForTraffic(data.MinLat, data.MaxLat, data.MinLongi, data.MaxLongi); PrivateMessage trafficData = new PrivateMessage(); trafficData.type = data.type; trafficData.msgId = data.msgId; trafficData.From = data.From; // Clients.Client(Context.ConnectionId).TrafficQuestion(trafficData);//Remove later---------------- while (usersAtLocation.Count > 0) { LogMsg("Level5", "inside level5"); LogMsg("TrafficCon", usersAtLocation.Count.ToString()); string ConnectionIdss = usersAtLocation.Pop(); trafficData.ToConn = ConnectionIdss; LogMsg("TrafficCon", ConnectionIdss); Clients.Client(ConnectionIdss).TrafficQuestion(trafficData); } } }