Пример #1
0
        public async void RequestPackProgress(OfflinePack pack)
        {
            var regions = await GetRegions();

            var region = regions.FirstOrDefault(d => d.ID == pack.Id);

            if (region == null)
            {
                return;
            }
            region.SetDownloadState(OfflineRegion.StateActive);
            region.SetObserver(new OfflineRegionObserver(
                                   (status) =>
            {
                pack.Progress = new OfflinePackProgress()
                {
                    CountOfResourcesExpected  = (ulong)status.RequiredResourceCount,
                    CountOfResourcesCompleted = (ulong)status.CompletedResourceCount,
                    CountOfTilesCompleted     = (ulong)status.CompletedTileCount,
                    CountOfTileBytesCompleted = (ulong)status.CompletedTileSize,
                    CountOfBytesCompleted     = (ulong)status.CompletedResourceSize,
                    MaximumResourcesExpected  = (ulong)status.RequiredResourceCount
                };
                if (status.IsComplete)
                {
                    pack.State = OfflinePackState.Completed;
                }
                else if (status.DownloadState == OfflineRegion.StateActive)
                {
                    pack.State = OfflinePackState.Active;
                }
                else
                {
                    pack.State = OfflinePackState.Inactive;
                }

                OfflinePackProgressChanged?.Invoke(this, new OSSEventArgs()
                {
                    OfflinePack = pack
                });
            },
                                   (error) =>
            {
                System.Diagnostics.Debug.WriteLine($"[ERROR] {error.Message} {error.Reason}");
                OfflinePackGotError?.Invoke(pack,
                                            new OSSErrorEventArgs()
                {
                    ErrorMessage = error.Message
                });
            },
                                   (maximumCount) =>
            {
                MaximumMapboxTilesReached?.Invoke(this, new OSSMaximumMapboxTilesReachedEventArgs()
                {
                    OfflinePack  = pack,
                    MaximumCount = (ulong)maximumCount
                });
            }
                                   ));
        }
Пример #2
0
        public void RequestPackProgress(OfflinePack pack)
        {
            var obj    = new Java.Lang.Object(pack.Handle, Android.Runtime.JniHandleOwnership.TransferGlobalRef);
            var region = Android.Runtime.Extensions.JavaCast <OfflineRegion>(obj);

            region?.SetObserver(new OfflineRegionObserver(
                                    (status) =>
            {
                pack.Progress = new OfflinePackProgress()
                {
                    CountOfResourcesExpected  = (ulong)status.RequiredResourceCount,
                    CountOfResourcesCompleted = (ulong)status.CompletedResourceCount,
                    CountOfTilesCompleted     = (ulong)status.CompletedTileCount,
                    CountOfTileBytesCompleted = (ulong)status.CompletedTileSize,
                    CountOfBytesCompleted     = (ulong)status.CompletedResourceSize,
                    MaximumResourcesExpected  = (ulong)status.RequiredResourceCount
                };
                if (status.IsComplete)
                {
                    pack.State = OfflinePackState.Completed;
                }
                else if (status.DownloadState == OfflineRegion.StateActive)
                {
                    pack.State = OfflinePackState.Active;
                }
                else
                {
                    pack.State = OfflinePackState.Inactive;
                }

                OfflinePackProgressChanged?.Invoke(this, new OSSEventArgs()
                {
                    OfflinePack = pack
                });
            },
                                    (error) =>
            {
                System.Diagnostics.Debug.WriteLine($"[ERROR] {error.Message} {error.Reason}");
                OfflinePackGotError?.Invoke(pack,
                                            new OSSErrorEventArgs()
                {
                    ErrorMessage = error.Message
                });
            },
                                    (maximumCount) =>
            {
                MaximumMapboxTilesReached?.Invoke(this, new OSSMaximumMapboxTilesReachedEventArgs()
                {
                    OfflinePack  = pack,
                    MaximumCount = (ulong)maximumCount
                });
            }
                                    ));
        }
        private void OnOfflinePackError(NSNotification notification)
        {
            MGLOfflinePack pack  = notification.Object as MGLOfflinePack;
            NSError        error = notification.UserInfo[MGLOfflinePackKeys.UserInfoKeyError] as NSError;
            OfflinePack    formsPack;
            var            hash = pack.GetNativeHash();

            if (tempPacks.ContainsKey(hash))
            {
                formsPack       = tempPacks[hash];
                formsPack.State = (OfflinePackState)pack.State;
                tempPacks.Remove(hash);
            }
            else
            {
                formsPack = pack.ToFormsPack();
            }
            OfflinePackGotError?.Invoke(this, new OSSErrorEventArgs()
            {
                OfflinePack  = formsPack,
                ErrorMessage = error.LocalizedFailureReason
            });
        }