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 OnMaximumMapboxTilesReached(NSNotification notification)
        {
            MGLOfflinePack pack = notification.Object as MGLOfflinePack;

            var         maximumCount = notification.UserInfo[MGLOfflinePackKeys.UserInfoKeyMaximumCount] as NSNumber;
            var         hash         = pack.GetNativeHash();
            OfflinePack formsPack;

            if (tempPacks.ContainsKey(hash))
            {
                formsPack       = tempPacks[hash];
                formsPack.State = (OfflinePackState)pack.State;
                tempPacks.Remove(hash);
            }
            else
            {
                formsPack = pack.ToFormsPack();
            }

            MaximumMapboxTilesReached?.Invoke(this, new OSSMaximumMapboxTilesReachedEventArgs()
            {
                OfflinePack  = formsPack,
                MaximumCount = maximumCount.UInt64Value
            });
        }
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
                });
            }
                                    ));
        }