public async static Task <bool> PushCloudAhoyFlight(string szUsername, LogbookEntryCore flight, FlightData fd, bool fSandbox) { if (szUsername == null) { throw new ArgumentNullException(nameof(szUsername)); } if (flight == null) { throw new ArgumentNullException(nameof(flight)); } if (fd == null) { throw new ArgumentNullException(nameof(fd)); } Profile pf = Profile.GetUser(szUsername); CloudAhoyClient client = new CloudAhoyClient(fSandbox) { AuthState = pf.CloudAhoyToken }; bool fUseRawData = (flight.Telemetry.TelemetryType == DataSourceType.FileType.GPX || flight.Telemetry.TelemetryType == DataSourceType.FileType.KML); using (MemoryStream ms = fUseRawData ? new MemoryStream(Encoding.UTF8.GetBytes(flight.Telemetry.RawData)) : new MemoryStream()) { if (!fUseRawData) { fd.WriteGPXData(ms); } ms.Seek(0, SeekOrigin.Begin); return(await client.PutStream(ms, flight)); } }
public async static Task <bool> PushCloudAhoyFlight(string szUsername, LogbookEntryCore flight, FlightData fd, bool fSandbox) { if (szUsername == null) { throw new ArgumentNullException(nameof(szUsername)); } if (flight == null) { throw new ArgumentNullException(nameof(flight)); } if (fd == null) { throw new ArgumentNullException(nameof(fd)); } Profile pf = Profile.GetUser(szUsername); CloudAhoyClient client = new CloudAhoyClient(fSandbox) { AuthState = pf.CloudAhoyToken }; MemoryStream ms = null; try { switch (flight.Telemetry.TelemetryType) { default: ms = new MemoryStream(); fd.WriteGPXData(ms); break; case DataSourceType.FileType.GPX: case DataSourceType.FileType.KML: ms = new MemoryStream(Encoding.UTF8.GetBytes(flight.Telemetry.RawData)); break; } ms.Seek(0, SeekOrigin.Begin); await client.PutStream(ms, flight).ConfigureAwait(false); return(true); } finally { if (ms != null) { ms.Dispose(); } } }