コード例 #1
0
        /// <summary>
        /// Retrieves latest info about a live waypoint, including new coordinates and
        /// description.
        /// </summary>
        /// <param name="liveWaypointId">live waypoint ID</param>
        /// <returns>query result for live waypoint</returns>
        public async Task <LiveWaypointQueryResult> GetLiveWaypointDataAsync(string liveWaypointId)
        {
            LiveWaypointQueryResult result = await this.backendWebApi.GetLiveWaypointDataAsync(liveWaypointId);

            result.Data.ID = System.Net.WebUtility.UrlDecode(result.Data.ID);

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Called when page requests an update for a live waypoint
        /// </summary>
        /// <param name="data">update live waypoint data</param>
        /// <returns>
        /// JSON result of query, either a LiveWaypointQueryResult or an exception text
        /// </returns>
        public async Task <JsonResult> OnGetUpdateLiveWaypointAsync(UpdateLiveWaypointData data)
        {
            string liveWaypointId = data.Uri;

            try
            {
                LiveWaypointQueryResult queryResult = await this.backendWebApi.GetLiveWaypointDataAsync(liveWaypointId);

                return(new JsonResult(queryResult));
            }
            catch (Exception ex)
            {
                return(new JsonResult(ex.Message));
            }
        }
コード例 #3
0
        /// <summary>
        /// Retrieves current live waypoint map location
        /// </summary>
        /// <param name="waypointName">waypoint name to use</param>
        /// <param name="appResourceUri">app resource uri to use</param>
        /// <returns>map location, or invalid location when it couldn't be retrieved</returns>
        private static async Task <Location> GetLiveWaypointLocation(string waypointName, AppResourceUri appResourceUri)
        {
            var dataService = DependencyService.Get <IDataService>();

            LiveWaypointQueryResult result = await dataService.GetLiveWaypointDataAsync(appResourceUri.ToString());

            var mapPoint = new MapPoint(result.Data.Latitude, result.Data.Longitude, result.Data.Altitude);

            return(new Location
            {
                Id = result.Data.ID,
                Name = waypointName ?? result.Data.Name,
                MapLocation = mapPoint,
                Description = result.Data.Description.Replace("\n", "<br/>"),
                Type = LocationType.LiveWaypoint,
                InternetLink = appResourceUri.ToString()
            });
        }
コード例 #4
0
        /// <summary>
        /// Updates live waypoint by getting live waypoint data and notify all event subjects.
        /// </summary>
        /// <param name="liveWaypointId">live waypoint ID to update</param>
        /// <returns>task to wait on</returns>
        private async Task UpdateLiveWaypointAsync(string liveWaypointId)
        {
            Debug.WriteLine($"LiveWaypointRefreshService: updating live waypoint for {liveWaypointId}");

            LiveWaypointQueryResult data = null;

            try
            {
                data = await this.DataService.GetLiveWaypointDataAsync(liveWaypointId);
            }
            catch (Exception ex)
            {
                // ignore exception
                Debug.WriteLine($"LiveWaypointRefreshService: exception occured: {ex.ToString()}");
            }

            if (data == null)
            {
                // try again in a minute
                lock (this.dataLock)
                {
                    this.nextPossibleUpdateMap[liveWaypointId] = DateTimeOffset.Now + TimeSpan.FromMinutes(1.0);
                }

                return;
            }

            if (data.Data != null)
            {
                this.UpdateLiveWaypoint?.Invoke(
                    this,
                    new LiveWaypointUpdateEventArgs
                {
                    Data = data.Data,
                });
            }

            var nextUpdate = data.NextRequestDate;

            lock (this.dataLock)
            {
                this.nextPossibleUpdateMap[liveWaypointId] = nextUpdate;
            }
        }
コード例 #5
0
        /// <summary>
        /// Returns live waypoint data for given live waypoint ID. May throw an exception when the
        /// data is not readily available and must be fetched.
        /// </summary>
        /// <param name="rawId">live waypoint ID (maybe urlencoded)</param>
        /// <returns>live waypoint query result</returns>
        public async Task <LiveWaypointQueryResult> GetLiveWaypointData(string rawId)
        {
            AppResourceUri uri = GetAndCheckLiveWaypointId(rawId);

            LiveWaypointQueryResult result = this.CheckCache(uri);

            if (result != null)
            {
                return(result);
            }

            result = await this.GetLiveWaypointQueryResult(uri);

            if (result != null)
            {
                this.CacheLiveWaypointData(result.Data);
            }

            return(result);
        }