protected override Task <IObservable <LocalisationData> > InitializeCore() { return(Task.Run( () => { IObservable <byte[]> packets; switch (this.ConnectionType) { case ConnectionType.Serial: packets = ToNcomPacket(SerialConnection.CreateByteListener(this.SerialPortName, this.SerialBaudRate, Parity.None, 8, StopBits.One)); break; case ConnectionType.Udp: packets = UdpConnection.CreateListener(this.RemoteAddress, this.UdpListenerPort).Select(udpResult => udpResult.Buffer); break; default: throw new NotSupportedException(string.Format("Connection type '{0}' is not supported.", this.ConnectionType)); } return ( from geoData in ToGeoData(packets) select new LocalisationData { RawData = geoData, GpsStatus = (IsInitializing(geoData) ? GpsStatus.Initializing : geoData.PositionData.Longitude == 0 && geoData.PositionData.Latitude == 0 ? GpsStatus.SignalLost : GpsStatus.Reliable) }).Publish().RefCount(); })); }