/// <summary> /// Posts a message for a new round that is available. /// </summary> /// <param name="round">The round.</param> internal async Task PostNewRoundAvailable(FlightGroup flightGroup, TaskBase task, IEnumerable <Pilot> pilots) { var args = new NewRoundAvailableEventArgs(flightGroup, task, pilots); NewRoundAvailable?.Invoke(this, args); try { if (this.hubConnection != null) { await this.hubConnection.InvokeAsync <object>("NewRoundAvailable", args); } this.logger.LogTrace($"{nameof(PostNewRoundAvailable)}: Sent new round available command to host server."); using (var webClient = new HttpClient()) { // Send the contest data to the server to store webClient.BaseAddress = serverUrl; var content = JsonConvert.SerializeObject(App.ContestEngine.Contest); var byteContent = new ByteArrayContent(Encoding.UTF8.GetBytes(content)); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = await webClient.PostAsync($"{serverUrl.AbsoluteUri}{ContestHostApis.ContestsRoute}", byteContent); if (response.StatusCode != HttpStatusCode.OK) { logger.LogTrace("bad stuff man."); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } }
/// <summary> /// To the time sheet. /// </summary> /// <returns></returns> /// <exception cref="NotImplementedException"></exception> internal TimeSheet ToTimeSheet(string contestId, FlightGroup flightGroup, int roundOrdinal, string taskId) { return(new TimeSheet { ContestId = contestId, FlightGroup = flightGroup, PilotId = this.pilotId, RoundOrdinal = roundOrdinal, Score = this.score, TaskId = taskId, TimeGates = this.Gates.Select(gate => gate.ToTimeGate()).ToList() }); }
string getBuoyText(FlightGroup fg) { string item = fg.Name; item += " (R"; if (fg.Designation1 >= 0xC && fg.Designation1 <= 0xF) { item += (fg.Waypoints[0].Region + 1); item += " From R"; item += (fg.Designation1 - 0xB); } else { item += (fg.Waypoints[0].Region + 1); item += " To R"; item += (fg.Designation1 - 0xF); } item += ")"; return(item); }
/// <summary> /// Initializes the flight group queue. /// </summary> /// <param name="currentRound">The current round.</param> /// <returns></returns> private void InitializeFlightGroupQueue(Round currentRound, FlightGroup currentFlightGroup) { if (currentRound == null) { return; } this.flightGroupQueue.Clear(); // Get the remaining flight groups (any that haven't been scored) and sort them var fgroupsInRound = currentRound?.FlightGroups?.Where(fg => fg.Key >= currentFlightGroup); fgroupsInRound = fgroupsInRound.OrderBy(fg => fg.Key); // Populate the queue foreach (var flightGroup in fgroupsInRound) { this.flightGroupQueue.Enqueue(flightGroup.Key); } // Set the current flight group this.CurrentFlightGroup = this.flightGroupQueue.Dequeue(); }
public async Task <IActionResult> GetFlightProfileGroup(DateTime strtDate, DateTime endDate, string arrival) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } List <FlightGroup> result = new List <FlightGroup>(); string[] ArrivalAirports = arrival.Split(','); foreach (string airport in ArrivalAirports) { var flightProfiles = new List <FlightGroupDetail>(); string constring = _iconfiguraton.GetSection("ConnectionStrings").GetSection("ATSEFEntities").Value; string commandInput = "SELECT count(*),ARRIVAL,RUNWAY_HEADING,AIRCRAFT,SECOND_ENTRY_SECTOR,min(SECOND_TRAVEL_TIME),max(SECOND_TRAVEL_TIME),AVG(SECOND_TRAVEL_TIME),39 as P15, 40 as P20,48 as P80 ,50 as P85 FROM ATSEF_DB.FLIGHT_PROFILE where ARRIVAL = '" + airport + "' and ARRIVAL_TIME between '" + strtDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) + "' and '" + endDate.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) + "' group by AIRCRAFT,RUNWAY_HEADING,SECOND_ENTRY_SECTOR;"; //string commandInput = "SELECT count(*),ARRIVAL,RUNWAY_HEADING,AIRCRAFT,SECOND_ENTRY_SECTOR ,min(SECOND_TRAVEL_TIME),max(SECOND_TRAVEL_TIME),AVG(SECOND_TRAVEL_TIME), 40 as P20,48 as P80 FROM ATSEF_DB.FLIGHT_PROFILE where ARRIVAL='VTBS' and ARRIVAL_TIME between '2018-01-01' and '2018-01-27' group by AIRCRAFT,RUNWAY_HEADING,SECOND_ENTRY_SECTOR ;"; try { using (DbConnection connection = new MySqlConnectorAlias::MySql.Data.MySqlClient.MySqlConnection(constring)) { connection.Open(); using (DbCommand command = new MySqlConnectorAlias::MySql.Data.MySqlClient.MySqlCommand(commandInput, (MySqlConnectorAlias::MySql.Data.MySqlClient.MySqlConnection)connection)) { using (DbDataReader reader = command.ExecuteReader()) { while (reader.Read()) { var groupDetail = new FlightGroupDetail() { Amount = (long)reader["count(*)"], Arrival = reader["ARRIVAL"] == DBNull.Value?"": (string)reader["ARRIVAL"], RunwayHeading = (reader["RUNWAY_HEADING"] == DBNull.Value? "": (string)(reader["RUNWAY_HEADING"])), Aircraft = (reader["AIRCRAFT"] == DBNull.Value? "":(string)(reader["AIRCRAFT"])), SecondEntrySector = (int)reader["SECOND_ENTRY_SECTOR"], Min = (long)reader["min(SECOND_TRAVEL_TIME)"], Max = (long)reader["max(SECOND_TRAVEL_TIME)"], Avg = (decimal)reader["AVG(SECOND_TRAVEL_TIME)"], P15 = (long)reader["P15"], P20 = (long)reader["P20"], P80 = (long)reader["P80"], P85 = (long)reader["P85"] }; flightProfiles.Add(groupDetail); } } } //DbCommand command = new MySql.Data.MySqlClient.MySqlCommand(commandInput, (MySql.Data.MySqlClient.MySqlConnection)connection); } } catch (Exception e) { throw e; } //var flightProfiles = await _context.FlightProfile.Where(m => m.ArrivalTime >= strtDate && m.ArrivalTime <= endDate && m.Arrival == airport) // .GroupBy(a => new { a.Aircraft, a.RunwayHeading, a.SecondEntrySector }) // .Select(group => new FlightGroupDetail // { // Aircraft = group.Key.Aircraft, // RunwayHeading = group.Key.RunwayHeading, // Amount = group.Count(), // Arrival = airport, // SecondEntrySector = group.Key.SecondEntrySector, // }).ToListAsync(); if (flightProfiles == null) { return(NotFound()); } FlightGroup flightGroup = new FlightGroup { Arrival = airport, StartTime = strtDate, EndingTime = endDate, ListFlightGroups = flightProfiles }; result.Add(flightGroup); } return(Ok(result)); }
private void cmdGenerate_Click(object sender, EventArgs e) { if (_mission.FlightGroups.Count > Mission.FlightGroupLimit - (chkReturn.Checked ? 4 : 2)) { MessageBox.Show("Adding buoys will exceed maximum number of allowed Flight Groups in the mission.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FlightGroup to = new FlightGroup(); to.CraftType = 0x55; to.Name = "To " + cboTo.Text; to.IFF = _iff; to.Designation1 = (byte)(0x10 + cboTo.SelectedIndex); to.EnableDesignation1 = true; to.Waypoints[0].Region = (byte)cboFrom.SelectedIndex; to.DepartureTimerSeconds = 5; to.ArrDepTriggers[4].Amount = 9; // Player's Craft of to.ArrDepTriggers[4].VariableType = 1; // Flightgroup to.ArrDepTriggers[4].Variable = _playerFG; to.ArrDepTriggers[4].Condition = 0x30; // must leave Region to.ArrDepTriggers[4].Parameter1 = (byte)(cboFrom.SelectedIndex + 1); _mission.FlightGroups.Add(to); lstBuoys.Items.Add(getBuoyText(to)); FlightGroup from = new FlightGroup(); from.CraftType = 0x55; from.Name = "From " + cboFrom.Text; from.IFF = _iff; from.Designation1 = (byte)(0xC + cboFrom.SelectedIndex); from.EnableDesignation1 = true; from.Waypoints[0].Region = (byte)cboTo.SelectedIndex; from.DepartureTimerSeconds = 5; from.ArrDepTriggers[4].Amount = 9; // Player's Craft of from.ArrDepTriggers[4].VariableType = 1; // Flightgroup from.ArrDepTriggers[4].Variable = _playerFG; from.ArrDepTriggers[4].Condition = 0x2F; // must arrive in Region from.ArrDepTriggers[4].Parameter1 = (byte)(cboTo.SelectedIndex + 1); _mission.FlightGroups.Add(from); lstBuoys.Items.Add(getBuoyText(from)); if (chkReturn.Checked) { to = new FlightGroup(); to.CraftType = 0x55; to.Name = "To " + cboFrom.Text; to.IFF = _iff; to.Designation1 = (byte)(0x10 + cboFrom.SelectedIndex); to.EnableDesignation1 = true; to.Waypoints[0].Region = (byte)cboTo.SelectedIndex; // Arrival T1 to.ArrDepTriggers[0].Amount = 9; // Player's Craft of to.ArrDepTriggers[0].VariableType = 1; // Flightgroup to.ArrDepTriggers[0].Variable = _playerFG; to.ArrDepTriggers[0].Condition = 0x2F; // must arrive in Region to.ArrDepTriggers[0].Parameter1 = (byte)(cboTo.SelectedIndex + 1); // Depart T1 to.DepartureTimerSeconds = 5; to.ArrDepTriggers[4].Amount = 9; // Player's Craft of to.ArrDepTriggers[4].VariableType = 1; // Flightgroup to.ArrDepTriggers[4].Variable = _playerFG; to.ArrDepTriggers[4].Condition = 0x30; // must leave Region to.ArrDepTriggers[4].Parameter1 = (byte)(cboTo.SelectedIndex + 1); _mission.FlightGroups.Add(to); lstBuoys.Items.Add(getBuoyText(to)); from = new FlightGroup(); from.CraftType = 0x55; from.Name = "From " + cboTo.Text; from.IFF = _iff; from.Designation1 = (byte)(0xC + cboTo.SelectedIndex); from.EnableDesignation1 = true; from.Waypoints[0].Region = (byte)cboFrom.SelectedIndex; // Arrival T1 from.ArrDepTriggers[0].Amount = 9; // Player's Craft of from.ArrDepTriggers[0].VariableType = 1; // Flightgroup from.ArrDepTriggers[0].Variable = _playerFG; from.ArrDepTriggers[0].Condition = 0x2F; // must arrive in Region from.ArrDepTriggers[0].Parameter1 = (byte)(cboTo.SelectedIndex + 1); // Depart T1 from.DepartureTimerSeconds = 5; from.ArrDepTriggers[4].Amount = 9; // Player's Craft of from.ArrDepTriggers[4].VariableType = 1; // Flightgroup from.ArrDepTriggers[4].Variable = _playerFG; from.ArrDepTriggers[4].Condition = 0x2F; // must arrive in Region from.ArrDepTriggers[4].Parameter1 = (byte)(cboFrom.SelectedIndex + 1); _mission.FlightGroups.Add(from); lstBuoys.Items.Add(getBuoyText(from)); } }
public async Task <IActionResult> GetFlightGroup(string contestId, int roundOrdinal, FlightGroup flightGroup) { var contestResult = await this.contestQueryInteractor.GetAllContestsAsync(); if (contestResult.IsFaulted) { return(BadRequest()); } var contest = contestResult.Value.Where(c => c.Id == contestId).Single(); if (contest == null) { return(BadRequest()); } var allPilotsResult = await this.pilotQueryInteractor.GetAllPilotsAsync(); if (contestResult.IsFaulted) { return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); } if (contest.Rounds.ContainsKey(roundOrdinal) && contest.Rounds[roundOrdinal].FlightGroups.ContainsKey(flightGroup)) { return(Ok(contest.Rounds[roundOrdinal]?.FlightGroups[flightGroup])); } return(new StatusCodeResult(StatusCodes.Status500InternalServerError)); }
private void cmdGenerate_Click(object sender, EventArgs e) { if (_mission.FlightGroups.Count > Mission.FlightGroupLimit - (chkReturn.Checked ? 4 : 2)) { MessageBox.Show("Adding buoys will exceed maximum number of allowed Flight Groups in the mission.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } FlightGroup to = new FlightGroup(); to.CraftType = 0x55; to.Name = "To " + cboTo.Text; to.IFF = _iff; to.EnableDesignation1 = _team; to.Designation1 = (byte)(0x10 + cboTo.SelectedIndex); to.Waypoints[0].Region = (byte)cboFrom.SelectedIndex; to.DepartureTimerSeconds = 5; to.ArrDepTriggers[4].Amount = 0; // 100% (if multiplayer, wait for all before de-spawning) to.ArrDepTriggers[4].VariableType = 7; // CraftWhen to.ArrDepTriggers[4].Variable = 9; // Player's craft to.ArrDepTriggers[4].Condition = 0x30; // must leave Region to.ArrDepTriggers[4].Parameter1 = (byte)(cboFrom.SelectedIndex + 1); to.Orders[(byte)cboFrom.SelectedIndex, 0].Command = 0x31; //[JB] Set beaconing order. Not required, but looks nice and follows standard convention. _mission.FlightGroups.Add(to); lstBuoys.Items.Add(getBuoyText(to)); FlightGroup from = new FlightGroup(); from.CraftType = 0x55; from.Name = "From " + cboFrom.Text; from.IFF = _iff; from.EnableDesignation1 = _team; from.Designation1 = (byte)(0xC + cboFrom.SelectedIndex); from.Waypoints[0].Region = (byte)cboTo.SelectedIndex; from.DepartureTimerSeconds = 5; from.ArrDepTriggers[4].Amount = 0; // 100% (if multiplayer, wait for all before de-spawning) from.ArrDepTriggers[4].VariableType = 7; // CraftWhen from.ArrDepTriggers[4].Variable = 9; // Player's craft from.ArrDepTriggers[4].Condition = 0x2F; // must arrive in Region from.ArrDepTriggers[4].Parameter1 = (byte)(cboTo.SelectedIndex + 1); from.Orders[(byte)cboTo.SelectedIndex, 0].Command = 0x31; _mission.FlightGroups.Add(from); lstBuoys.Items.Add(getBuoyText(from)); if (chkReturn.Checked) { to = new FlightGroup(); to.CraftType = 0x55; to.Name = "To " + cboFrom.Text; to.IFF = _iff; to.EnableDesignation1 = _team; to.Designation1 = (byte)(0x10 + cboFrom.SelectedIndex); to.Waypoints[0].Region = (byte)cboTo.SelectedIndex; // Arrival T1 to.ArrDepTriggers[0].Amount = 4; // At least one to.ArrDepTriggers[0].VariableType = 7; // CraftWhen to.ArrDepTriggers[0].Variable = 9; // Player's craft to.ArrDepTriggers[0].Condition = 0x2F; // must arrive in Region to.ArrDepTriggers[0].Parameter1 = (byte)(cboTo.SelectedIndex + 1); // Depart T1 to.DepartureTimerSeconds = 5; to.ArrDepTriggers[4].Amount = 0; // 100% (if multiplayer, wait for all before de-spawning) to.ArrDepTriggers[4].VariableType = 7; // CraftWhen to.ArrDepTriggers[4].Variable = 9; // Player's craft to.ArrDepTriggers[4].Condition = 0x30; // must leave Region to.ArrDepTriggers[4].Parameter1 = (byte)(cboTo.SelectedIndex + 1); to.Orders[(byte)cboTo.SelectedIndex, 0].Command = 0x31; _mission.FlightGroups.Add(to); lstBuoys.Items.Add(getBuoyText(to)); from = new FlightGroup(); from.CraftType = 0x55; from.Name = "From " + cboTo.Text; from.IFF = _iff; from.EnableDesignation1 = _team; from.Designation1 = (byte)(0xC + cboTo.SelectedIndex); from.Waypoints[0].Region = (byte)cboFrom.SelectedIndex; // Arrival T1 from.ArrDepTriggers[0].Amount = 4; // At least one from.ArrDepTriggers[0].VariableType = 7; // CraftWhen from.ArrDepTriggers[0].Variable = 9; // Player's craft from.ArrDepTriggers[0].Condition = 0x2F; // must arrive in Region from.ArrDepTriggers[0].Parameter1 = (byte)(cboTo.SelectedIndex + 1); // Depart T1 from.DepartureTimerSeconds = 5; from.ArrDepTriggers[4].Amount = 0; // 100% (if multiplayer, wait for all before de-spawning) from.ArrDepTriggers[4].VariableType = 7; // CraftWhen from.ArrDepTriggers[4].Variable = 9; // Player's craft from.ArrDepTriggers[4].Condition = 0x2F; // must arrive in Region from.ArrDepTriggers[4].Parameter1 = (byte)(cboFrom.SelectedIndex + 1); from.Orders[(byte)cboFrom.SelectedIndex, 0].Command = 0x31; _mission.FlightGroups.Add(from); lstBuoys.Items.Add(getBuoyText(from)); } }
/// <summary> /// Initializes a new instance of the <see cref="NewRoundAvailableEventArgs"/> class. /// </summary> /// <param name="flightGroup">The flight group.</param> /// <param name="task">The task.</param> /// <param name="pilots">The pilots.</param> public NewRoundAvailableEventArgs(FlightGroup flightGroup, TaskBase task, IEnumerable <Pilot> pilots) { this.FlightGroup = flightGroup; this.Task = task; this.Pilots = pilots; }