コード例 #1
0
        /// <summary>
        /// Imports cloudahoy flights for the specified user between the specified dates
        /// </summary>
        /// <param name="szUsername">The user for whom to import flights</param>
        /// <param name="fSandbox">True to use the sandbox</param>
        /// <param name="dtStart">Optional start date</param>
        /// <param name="dtEnd">Optional end date</param>
        /// <returns>Error message if failure, else empty string for success</returns>
        public async static Task <string> ImportCloudAhoyFlights(string szUsername, bool fSandbox, DateTime?dtStart, DateTime?dtEnd)
        {
            Profile         pf     = Profile.GetUser(szUsername);
            CloudAhoyClient client = new CloudAhoyClient(fSandbox)
            {
                AuthState = pf.CloudAhoyToken
            };

            try
            {
                IEnumerable <CloudAhoyFlight> rgcaf = await client.GetFlights(szUsername, dtStart, dtEnd);

                foreach (CloudAhoyFlight caf in rgcaf)
                {
                    if (caf.ToLogbookEntry() is PendingFlight pendingflight)
                    {
                        pendingflight.Commit();
                    }
                }
                return(string.Empty);
            }
            catch (Exception ex) when(ex is MyFlightbookException || ex is MyFlightbookValidationException)
            {
                return(ex.Message);
            }
        }
コード例 #2
0
        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));
            }
        }
コード例 #3
0
        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();
                }
            }
        }