Beispiel #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
                });
            }
                                   ));
        }
        private void OnOfflinePackProgressChanged(NSNotification notification)
        {
            MGLOfflinePack pack      = notification.Object as MGLOfflinePack;
            var            hash      = pack.GetNativeHash();
            var            completed = pack.State == MGLOfflinePackState.Complete || (pack.Progress.countOfResourcesExpected == pack.Progress.countOfResourcesCompleted);
            OfflinePack    formsPack;

            if (tempPacks.ContainsKey(hash))
            {
                formsPack          = tempPacks[hash];
                formsPack.Progress = pack.Progress.ToFormsProgress();
                formsPack.State    = (OfflinePackState)pack.State;
                if (completed)
                {
                    tempPacks.Remove(hash);
                }
            }
            else
            {
                formsPack = pack.ToFormsPack();
                if (!completed)
                {
                    tempPacks.Add(hash, formsPack);
                }
            }
            OfflinePackProgressChanged?.Invoke(this, new OSSEventArgs()
            {
                OfflinePack = formsPack
            });
        }
Beispiel #3
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
                });
            }
                                    ));
        }