public void ReceiverLocation_Clone_Creates_Copy() { var original = new ReceiverLocation() { IsBaseStationLocation = true, Latitude = 1.0, Longitude = 2.0, Name = "A", UniqueId = 1, }; var copy = (ReceiverLocation)original.Clone(); Assert.AreNotSame(original, copy); foreach (var property in typeof(ReceiverLocation).GetProperties()) { switch (property.Name) { case "IsBaseStationLocation": Assert.AreEqual(true, copy.IsBaseStationLocation); break; case "Latitude": Assert.AreEqual(1.0, copy.Latitude); break; case "Longitude": Assert.AreEqual(2.0, copy.Longitude); break; case "Name": Assert.AreEqual("A", copy.Name); break; case "UniqueId": Assert.AreEqual(1, copy.UniqueId); break; default: throw new NotImplementedException(); } } }
private void CheckValidation_Updates_Selected_Line_With_New_Longitude(Action trigger) { foreach (var longitude in new double[] { -180.0, -179.9999, -178, -1, 0, 1, 178, 179.9999, 180.0 }) { TestCleanup(); TestInitialise(); _Presenter.Initialise(_View.Object); var line1 = new ReceiverLocation() { UniqueId = 1, Name = "ABC", Latitude = 1.0, Longitude = 2.0 }; var line2 = new ReceiverLocation() { UniqueId = 2, Name = "XYZ", Latitude = 1.0, Longitude = 2.0 }; _View.Object.ReceiverLocations.AddRange(new ReceiverLocation[] { line1, line2 }); SetupSelectedLocation(line2); _View.Raise(v => v.SelectedLocationChanged += null, EventArgs.Empty); SetupExpectedValidationFields(new ValidationResult[] { }); _View.Object.Longitude = longitude.ToString(); trigger(); _View.Verify(v => v.ShowValidationResults(It.IsAny <IEnumerable <ValidationResult> >()), Times.Exactly(2)); Assert.AreEqual(longitude, line2.Longitude); _View.Verify(v => v.RefreshSelectedLocation(), Times.Once()); } }
/// <summary> /// Configures the polar plotter. /// </summary> /// <param name="receiverLocation"></param> /// <param name="nameChanged"></param> private void ConfigurePolarPlotter(ReceiverLocation receiverLocation, bool nameChanged) { if (receiverLocation == null) { AircraftList.PolarPlotter = null; } else { var existingPlotter = AircraftList.PolarPlotter; if (existingPlotter == null || existingPlotter.Latitude != receiverLocation.Latitude || existingPlotter.Longitude != receiverLocation.Longitude) { var polarPlotter = existingPlotter ?? Factory.Resolve <IPolarPlotter>(); polarPlotter.Initialise(receiverLocation.Latitude, receiverLocation.Longitude); if (existingPlotter == null) { AircraftList.PolarPlotter = polarPlotter; LoadCurrentPolarPlot(); } } if (nameChanged && existingPlotter != null) { LoadCurrentPolarPlot(); } } }
private void CheckValidation_Does_Nothing_If_No_Location_Is_Selected(Action trigger) { _Presenter.Initialise(_View.Object); var line1 = new ReceiverLocation() { UniqueId = 1, Name = "ABC", Latitude = 1.0, Longitude = 2.0 }; var line2 = new ReceiverLocation() { UniqueId = 2, Name = "XYZ", Latitude = 1.0, Longitude = 2.0 }; _View.Object.ReceiverLocations.AddRange(new ReceiverLocation[] { line1, line2 }); SetupSelectedLocation(null); _View.Raise(v => v.SelectedLocationChanged += null, EventArgs.Empty); _View.Object.Location = "New name"; _View.Object.Latitude = (4.0).ToString(); _View.Object.Longitude = (5.0).ToString(); trigger(); _View.Verify(v => v.RefreshSelectedLocation(), Times.Never()); }
private void CheckValidation_Displays_Validation_Message_When_Longitude_Is_Out_Of_Range(Action trigger) { foreach (var badLongitude in new double[] { -182.0, -181.0, -180.00001, 180.00001, 181.0, 182.0 }) { TestCleanup(); TestInitialise(); _Presenter.Initialise(_View.Object); var line1 = new ReceiverLocation() { UniqueId = 1, Name = "ABC", Latitude = 1.0, Longitude = 2.0 }; var line2 = new ReceiverLocation() { UniqueId = 2, Name = "XYZ", Latitude = 1.0, Longitude = 2.0 }; _View.Object.ReceiverLocations.AddRange(new ReceiverLocation[] { line1, line2 }); SetupSelectedLocation(line2); _View.Raise(v => v.SelectedLocationChanged += null, EventArgs.Empty); SetupExpectedValidationFields(new ValidationResult[] { new ValidationResult(ValidationField.Longitude, Strings.LongitudeOutOfBounds) }); _View.Object.Longitude = badLongitude.ToString(); trigger(); _View.Verify(v => v.ShowValidationResults(It.IsAny <IEnumerable <ValidationResult> >()), Times.Exactly(2)); _View.Verify(v => v.RefreshSelectedLocation(), Times.Never()); Assert.AreEqual(2.0, line2.Longitude); } }
private void CheckValidation_Updates_Selected_Line_With_Name(Action trigger) { _Presenter.Initialise(_View.Object); var line1 = new ReceiverLocation() { UniqueId = 1, Name = "ABC", Latitude = 1.0, Longitude = 2.0 }; var line2 = new ReceiverLocation() { UniqueId = 2, Name = "XYZ", Latitude = 1.0, Longitude = 2.0 }; _View.Object.ReceiverLocations.AddRange(new ReceiverLocation[] { line1, line2 }); SetupSelectedLocation(line2); _View.Raise(v => v.SelectedLocationChanged += null, EventArgs.Empty); SetupExpectedValidationFields(new ValidationResult[] { }); _View.Object.Location = "New name"; trigger(); _View.Verify(v => v.ShowValidationResults(It.IsAny <IEnumerable <ValidationResult> >()), Times.Exactly(2)); Assert.AreEqual("New name", line2.Name); _View.Verify(v => v.RefreshSelectedLocation(), Times.Once()); }
private void CheckValidation_Displays_Validation_Message_When_Latitude_Is_Zero(Action trigger) { _Presenter.Initialise(_View.Object); var line1 = new ReceiverLocation() { UniqueId = 1, Name = "ABC", Latitude = 1.0, Longitude = 2.0 }; var line2 = new ReceiverLocation() { UniqueId = 2, Name = "XYZ", Latitude = 1.0, Longitude = 2.0 }; _View.Object.ReceiverLocations.AddRange(new ReceiverLocation[] { line1, line2 }); SetupSelectedLocation(line2); _View.Raise(v => v.SelectedLocationChanged += null, EventArgs.Empty); SetupExpectedValidationFields(new ValidationResult[] { new ValidationResult(ValidationField.Latitude, Strings.LatitudeCannotBeZero) }); _View.Object.Latitude = (0.0).ToString("N1"); trigger(); _View.Verify(v => v.ShowValidationResults(It.IsAny <IEnumerable <ValidationResult> >()), Times.Exactly(2)); _View.Verify(v => v.RefreshSelectedLocation(), Times.Never()); Assert.AreEqual(1.0, line2.Latitude); }
private void CheckValidation_Does_Not_Display_Validation_Message_When_Name_Duplicates_Own_Name(Action trigger) { _Presenter.Initialise(_View.Object); var line1 = new ReceiverLocation() { UniqueId = 1, Name = "ABC" }; var line2 = new ReceiverLocation() { UniqueId = 2, Name = "XYZ" }; _View.Object.ReceiverLocations.AddRange(new ReceiverLocation[] { line1, line2 }); SetupSelectedLocation(line2); _View.Raise(v => v.SelectedLocationChanged += null, EventArgs.Empty); SetupExpectedValidationFields(new ValidationResult[] { }); _View.Object.Location = "XYZ"; _View.Object.Latitude = (0.01).ToString(); trigger(); _View.Verify(v => v.ShowValidationResults(It.IsAny <IEnumerable <ValidationResult> >()), Times.Exactly(2)); }
private void CheckValidation_Displays_Validation_Message_When_Name_Duplicates_Existing_Name(Action trigger) { _Presenter.Initialise(_View.Object); var line1 = new ReceiverLocation() { UniqueId = 1, Name = "ABC" }; var line2 = new ReceiverLocation() { UniqueId = 2, Name = "XYZ" }; _View.Object.ReceiverLocations.AddRange(new ReceiverLocation[] { line1, line2 }); SetupSelectedLocation(line2); _View.Raise(v => v.SelectedLocationChanged += null, EventArgs.Empty); SetupExpectedValidationFields(new ValidationResult[] { new ValidationResult(ValidationField.Location, Strings.PleaseEnterUniqueNameForLocation) }); _View.Object.Location = "ABC"; _View.Object.Latitude = (0.01).ToString(); trigger(); _View.Verify(v => v.ShowValidationResults(It.IsAny <IEnumerable <ValidationResult> >()), Times.Exactly(2)); _View.Verify(v => v.RefreshSelectedLocation(), Times.Never()); Assert.AreEqual("XYZ", line2.Name); }
private ReceiverLocation SetupSelectedLocation() { var result = new ReceiverLocation() { UniqueId = 1, Name = "SELECTED", Latitude = 1, Longitude = 2 }; return(SetupSelectedLocation(result)); }
public void ReceiverLocation_Initialises_To_Known_State_And_Properties_Work() { var location = new ReceiverLocation(); TestUtilities.TestProperty(location, r => r.IsBaseStationLocation, false); TestUtilities.TestProperty(location, r => r.Latitude, 0.0, 123.567); TestUtilities.TestProperty(location, r => r.Longitude, 0.0, -123.456); TestUtilities.TestProperty(location, r => r.Name, null, "Home"); TestUtilities.TestProperty(location, r => r.UniqueId, 0, 123); }
public void ConfigurationListener_Does_Not_Raise_Events_After_ReceiverLocation_Is_Detached() { var record = new ReceiverLocation(); _Configuration.ReceiverLocations.Add(record); _Configuration.ReceiverLocations.Remove(record); record.UniqueId += 1; Assert.IsFalse(RaisedEvent <ReceiverLocation>(ConfigurationListenerGroup.ReceiverLocation, r => r.UniqueId, record, isListChild: true)); Assert.AreEqual(2, _PropertyChanged.CallCount); }
/// <summary> /// Raised when the user asks for a new location to be created. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void View_NewLocationClicked(object sender, EventArgs args) { var location = new ReceiverLocation() { Name = SelectUniqueName("New Location"), UniqueId = _NextUniqueId++, }; _View.ReceiverLocations.Add(location); _View.RefreshLocations(); _View.SelectedReceiverLocation = location; CopySelectedLocationToFields(); _View.FocusOnEditFields(); }
protected void ReceiverPostal_TextChanged(object sender, EventArgs e) { ReceiverCity.Text = ""; ReceiverState.Text = ""; TextBox textbox = sender as TextBox; if (textbox != null) { Repository repository = new Repository(); ArrayList arr = repository.GetAreaFromPostCode(textbox.Text); ReceiverLocation.Items.Clear(); ReceiverLocation.DataSource = arr; ReceiverLocation.DataBind(); ReceiverLocation.Items.Insert(0, new ListItem("")); } }
public void Configuration_ReceiverLocation_Returns_Null_If_Receiver_Cannot_Be_Found() { var home = new ReceiverLocation() { UniqueId = 1, Name = "HOME" }; var away = new ReceiverLocation() { UniqueId = 2, Name = "AWAY" }; _Implementation.ReceiverLocations.AddRange(new ReceiverLocation[] { home, away }); var location = _Implementation.ReceiverLocation(3); Assert.IsNull(location); }
public void Configuration_ReceiverLocation_Returns_ReceiverLocation_From_ReceiverLocations() { var home = new ReceiverLocation() { UniqueId = 1, Name = "HOME" }; var away = new ReceiverLocation() { UniqueId = 2, Name = "AWAY" }; _Implementation.ReceiverLocations.AddRange(new ReceiverLocation[] { home, away }); var location = _Implementation.ReceiverLocation(2); Assert.AreSame(away, location); }
/// <summary> /// Raised when the user wants to copy locations from the BaseStation database. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void View_UpdateFromBaseStationDatabaseClicked(object sender, EventArgs args) { var entriesPreviouslyCopiedFromBaseStationDatabase = _View.ReceiverLocations.Where(r => r.IsBaseStationLocation).ToList(); _View.ReceiverLocations.RemoveAll(r => r.IsBaseStationLocation); var database = Factory.Singleton.Resolve <IAutoConfigBaseStationDatabase>().Singleton.Database; foreach (var location in database.GetLocations()) { var previousEntry = entriesPreviouslyCopiedFromBaseStationDatabase.Where(r => r.Name == location.LocationName).FirstOrDefault(); var newLocation = new ReceiverLocation() { Name = SelectUniqueName(location.LocationName), UniqueId = previousEntry == null ? _NextUniqueId++ : previousEntry.UniqueId, Latitude = location.Latitude, Longitude = location.Longitude, IsBaseStationLocation = true, }; _View.ReceiverLocations.Add(newLocation); } _View.RefreshLocations(); }
private ReceiverLocation SetupSelectedLocation(ReceiverLocation location) { _View.Setup(v => v.SelectedReceiverLocation).Returns(location); return(location); }
/// <summary> /// Creates and configures the object to translate Mode-S messages into BaseStation messages. /// </summary> /// <param name="receiver"></param> /// <param name="receiverLocation"></param> /// <param name="config"></param> /// <param name="isNewSource"></param> /// <returns></returns> private IRawMessageTranslator DetermineRawMessageTranslator(Receiver receiver, ReceiverLocation receiverLocation, Configuration config, bool isNewSource) { var result = isNewSource || Listener.RawMessageTranslator == null?Factory.Resolve <IRawMessageTranslator>() : Listener.RawMessageTranslator; // There's every chance that the translator is in use while we're changing the properties here. In practise I // don't think it's going to make a huge difference, and people won't be changing this stuff very often anyway, // but I might have to add some shared locking code here. I'd like to avoid it if I can though. result.ReceiverLocation = receiverLocation == null ? null : new GlobalCoordinate(receiverLocation.Latitude, receiverLocation.Longitude); result.AcceptIcaoInNonPICount = config.RawDecodingSettings.AcceptIcaoInNonPICount; result.AcceptIcaoInNonPIMilliseconds = config.RawDecodingSettings.AcceptIcaoInNonPISeconds * 1000; result.AcceptIcaoInPI0Count = config.RawDecodingSettings.AcceptIcaoInPI0Count; result.AcceptIcaoInPI0Milliseconds = config.RawDecodingSettings.AcceptIcaoInPI0Seconds * 1000; result.GlobalDecodeAirborneThresholdMilliseconds = config.RawDecodingSettings.AirborneGlobalPositionLimit * 1000; result.GlobalDecodeFastSurfaceThresholdMilliseconds = config.RawDecodingSettings.FastSurfaceGlobalPositionLimit * 1000; result.GlobalDecodeSlowSurfaceThresholdMilliseconds = config.RawDecodingSettings.SlowSurfaceGlobalPositionLimit * 1000; result.IgnoreMilitaryExtendedSquitter = config.RawDecodingSettings.IgnoreMilitaryExtendedSquitter; result.LocalDecodeMaxSpeedAirborne = config.RawDecodingSettings.AcceptableAirborneSpeed; result.LocalDecodeMaxSpeedSurface = config.RawDecodingSettings.AcceptableSurfaceSpeed; result.LocalDecodeMaxSpeedTransition = config.RawDecodingSettings.AcceptableAirSurfaceTransitionSpeed; result.ReceiverRangeKilometres = config.RawDecodingSettings.ReceiverRange; result.SuppressCallsignsFromBds20 = config.RawDecodingSettings.IgnoreCallsignsInBds20; result.SuppressReceiverRangeCheck = config.RawDecodingSettings.SuppressReceiverRangeCheck; result.SuppressTisbDecoding = config.RawDecodingSettings.SuppressTisbDecoding; result.TrackingTimeoutSeconds = config.BaseStationSettings.TrackingTimeoutSeconds; result.UseLocalDecodeForInitialPosition = config.RawDecodingSettings.UseLocalDecodeForInitialPosition; result.IgnoreInvalidCodeBlockInOtherMessages = config.RawDecodingSettings.IgnoreInvalidCodeBlockInOtherMessages; result.IgnoreInvalidCodeBlockInParityMessages = config.RawDecodingSettings.IgnoreInvalidCodeBlockInParityMessages; return(result); }
/// <summary> /// Applies receiver listener settings. /// </summary> /// <param name="reconnect"></param> /// <param name="receiver"></param> /// <param name="configuration"></param> /// <param name="receiverLocation"></param> private void ApplyReceiverListenerSettings(bool reconnect, Receiver receiver, Configuration configuration, ReceiverLocation receiverLocation) { var connector = DetermineConnector(receiver); var bytesExtractor = DetermineBytesExtractor(receiver); var feedSourceHasChanged = connector != Listener.Connector || bytesExtractor != Listener.BytesExtractor; var rawMessageTranslator = DetermineRawMessageTranslator(receiver, receiverLocation, configuration, feedSourceHasChanged); var existingAuthentication = (Listener.Connector == null ? null : Listener.Connector.Authentication) as IPassphraseAuthentication; var passphrase = receiver.Passphrase ?? ""; if ((existingAuthentication != null && existingAuthentication.Passphrase != passphrase) || (existingAuthentication == null && passphrase != "")) { IPassphraseAuthentication authentication = null; if (passphrase != "") { authentication = Factory.Resolve <IPassphraseAuthentication>(); authentication.Passphrase = receiver.Passphrase; } if (!feedSourceHasChanged) { Listener.Connector.Authentication = authentication; } else { connector.Authentication = authentication; } } if (feedSourceHasChanged) { Listener.ChangeSource(connector, bytesExtractor, rawMessageTranslator); if (Listener.Statistics != null) { Listener.Statistics.ResetMessageCounters(); } } Listener.ReceiverName = receiver.Name; Listener.IsSatcomFeed = receiver.IsSatcomFeed; Listener.AssumeDF18CF1IsIcao = configuration.RawDecodingSettings.AssumeDF18CF1IsIcao; SetIsVisible(receiver.ReceiverUsage); }