public virtual void OnHit(FlightNode node, FlightShip ship, Point gridLocation, Vector3 nodeLocation, Section section) { }
public Tuple <Dictionary <string, string>, FlightNode> Next() { if (dataSourceType == "PULSAR") { return(new Tuple <Dictionary <string, string>, FlightNode>(new Dictionary <string, string>(), new FlightNode())); } Dictionary <string, string> data = null; FlightNode flt = null; try { if (dataRecords.Count != 0) { if (index >= dataRecords.Count && abortOnListEnd) { return(null); } data = dataRecords[index % dataRecords.Count]; } if (fltRecords.Count != 0) { if (sequentialFlight) { if (index >= fltRecords.Count && abortOnFlightListEnd) { return(null); } flt = fltRecords[index % fltRecords.Count]; } else { Random rnd = new Random(); flt = fltRecords[rnd.Next(fltRecords.Count)]; } } if (refreshFlight && flt != null) { logger.Info($"Refreshing flight {flt.ToString()} from AMS"); flt = flt.RefeshFlight(executionController.amshost, executionController.token, executionController.apt_code).Result; } index++; } catch (Exception ex) { logger.Error($"Error getting next piece of data {ex.Message}"); } if (expression != null && flt != null && filterTime == "post") { bool pass = expression.Pass(flt.FightXML); if (!pass) { throw new FilterFailException(); } } if (topLevelFilter != null && flt != null && filterTime == "post") { bool pass = topLevelFilter.Pass(flt.FightXML); if (!pass) { throw new FilterFailException(); } } // Return the flight node and data record for this iteration return(new Tuple <Dictionary <string, string>, FlightNode>(data, flt)); }
private bool SetTriggers(List <Dictionary <String, String> > records, string timeStrElement, string timeFormat) { if (records == null || records.Count == 0) { SetSourceLineOutput("No data records available to process"); return(true); } int notSetEvents = 0; int setEvents = 0; int index = 0; foreach (Dictionary <String, String> record in records) { FlightNode flt = null; if (fltRecords.Count > 0) { if (sequentialFlight) { flt = fltRecords[index++ % fltRecords.Count]; } else { Random rnd = new Random(); flt = fltRecords[rnd.Next(fltRecords.Count)]; } } Tuple <Dictionary <string, string>, FlightNode> triggerData = new Tuple <Dictionary <string, string>, FlightNode>(record, flt); foreach (XmlNode trigger in node.SelectNodes("trigger")) { string triggerID = trigger.Attributes["id"].Value; triggersThisLine.Add(triggerID); if (!triggersInUse.Contains(triggerID)) { continue; } if (!relativeTime) { CultureInfo provider = CultureInfo.InvariantCulture; string timeStr = record[timeStrElement]; DateTime triggerTime; try { triggerTime = DateTime.Parse(timeStr); } catch (Exception) { try { triggerTime = DateTime.ParseExact(timeStr, timeFormat, provider); } catch (Exception ex) { sourceLogger.Error(ex, $"Error parsing triggerTime. Unparsed string: {timeStr}"); break; } } //Apply any offset to the trigger time bool hasOffset = Int32.TryParse(trigger.Attributes["delta"]?.Value, out int offset); if (hasOffset) { triggerTime = triggerTime.AddMinutes(offset); } // Add the offset between the client and the server triggerTime = triggerTime.AddMinutes(serverOffset); bool eventSet = eventDistributor.ScheduleEvent(new TriggerRecord(chainedController, triggerTime, timeStr, relativeTime, triggerID, triggerData, uid, refreshFlight)); if (eventSet) { setEvents++; } else { notSetEvents++; } } else { // Time Relative to start CultureInfo provider = CultureInfo.InvariantCulture; string timeStr = record[timeStrElement]; DateTime triggerTime = DateTime.Now; //Apply any offset to the trigger time bool hasOffset = double.TryParse(timeStr, out double offset); if (hasOffset) { triggerTime = triggerTime.AddMilliseconds(offset * 1000); } if (offset < 5) { sourceLogger.Warn("Triggering Event Rejected. Time Relative to start must be > 5 seconds"); continue; } bool eventSet = eventDistributor.ScheduleEvent(new TriggerRecord(chainedController, triggerTime, timeStr, relativeTime, triggerID, triggerData, uid, refreshFlight)); if (eventSet) { setEvents++; } else { notSetEvents++; } } } } foreach (XmlNode trigger in node.SelectNodes("trigger")) { string triggerID = trigger.Attributes["id"].Value; if (!triggersInUse.Contains(triggerID)) { continue; } eventDistributor.AddDispatcher(triggerID); eventDistributor.AddMonitorHandler(triggerID, this); } SetSourceLineOutput($"{setEvents} events set for triggering."); foreach (RateDrivenSourceController chain in chainedController) { chain.Prepare(null, null, null); } return(true); }