-
Notifications
You must be signed in to change notification settings - Fork 525
/
Copy pathHonorMobileMapPackageExpiration.xaml.cs
85 lines (75 loc) · 3.84 KB
/
HonorMobileMapPackageExpiration.xaml.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Copyright 2022 Esri.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.
// You may obtain a copy of the License at: http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific
// language governing permissions and limitations under the License.
using ArcGIS.Samples.Managers;
using Esri.ArcGISRuntime.Mapping;
namespace ArcGIS.Samples.HonorMobileMapPackageExpiration
{
[ArcGIS.Samples.Shared.Attributes.Sample(
name: "Honor mobile map package expiration date",
category: "Map",
description: "Access the expiration information of an expired mobile map package.",
instructions: "Load the sample. The author of the MMPK used in this sample chose to set the MMPK's map as still readable, even if it's expired. The sample presents expiration information to the user.",
tags: new[] { "expiration", "mmpk" })]
[ArcGIS.Samples.Shared.Attributes.OfflineData("174150279af74a2ba6f8b87a567f480b")]
public partial class HonorMobileMapPackageExpiration : ContentPage
{
public HonorMobileMapPackageExpiration()
{
InitializeComponent();
_ = Initialize();
}
private async Task Initialize()
{
try
{
// Path to the mobile map package.
string mobileMapPackagePath = DataManager.GetDataFolder("174150279af74a2ba6f8b87a567f480b", "LothianRiversAnno.mmpk");
// Create a mobile map package.
MobileMapPackage mobileMapPackage = new MobileMapPackage(mobileMapPackagePath);
// Load the mobile map package.
await mobileMapPackage.LoadAsync();
// Check if the map package is expired.
if (mobileMapPackage.Expiration?.IsExpired == true)
{
// Get the expiration of the mobile map package.
Expiration expiration = mobileMapPackage.Expiration;
// Get the expiration message.
string expirationMessage = expiration.Message;
// Get the expiration date.
string expirationDate = expiration.DateTime.ToString("F");
// Set the expiration message.
ExpirationLabel.Text = $"{expirationMessage}\nExpiration date: {expirationDate}";
// Check if the map is accessible after expiration.
if (expiration.Type == ExpirationType.AllowExpiredAccess && mobileMapPackage.Maps.Count > 0)
{
// Set the mapview to the map from the mobile map package.
MyMapView.Map = mobileMapPackage.Maps[0];
}
else if (expiration.Type == ExpirationType.PreventExpiredAccess)
{
await Application.Current.Windows[0].Page.DisplayAlert("Error", "The author of this mobile map package has disallowed access after the expiration date.", "OK");
}
}
else if (mobileMapPackage.Maps.Any())
{
// Set the mapview to the map from the mobile map package.
MyMapView.Map = mobileMapPackage.Maps[0];
}
else
{
await Application.Current.Windows[0].Page.DisplayAlert("Error", "Failed to load the mobile map package.", "OK");
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
}
}