Offline users can need to work where network access is unavailable or unreliable. The device documentation gives examples including shielded work areas, tunnels, underground construction sites, and radio-shielded buildings.
Device-local persistence
The documented device example starts with a Xamarin Forms template application, removes manually written code, and makes data persistent on the device.
The example creates and activates an EcoSpace, initializes the application's ViewModel definitions, and assigns the EcoSpace to the application's data store:
_es = new EcoProject1EcoSpace();
_es.PMapperXml.OnLoadAsXML += Pm_OnLoadAsXML;
_es.PMapperXml.OnSaveAsXML += Pm_OnSaveAsXML;
ViewModelDefinitionsInApplication.Init(_es);
_es.Active = true;
BaseViewModel.DataStore.SetEcoSpace(_es);
In the Android example, persistence mapper events are used to save XML data to a file in external storage and to reload that file when it exists:
private void Pm_OnSaveAsXML(object sender, Eco.Persistence.OnSaveAsXMLArgs e)
{
var path = global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
var filename = System.IO.Path.Combine(path.ToString(), e.FileName);
e.XDocumentToSave.Save(filename);
e.ContinueWithDefault = false;
}
private void Pm_OnLoadAsXML(object sender, Eco.Persistence.OnLoadAsXMLArgs e)
{
var path = global::Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
var filename = System.IO.Path.Combine(path.ToString(), e.FileName);
if (System.IO.File.Exists(filename))
{
using (var fileStream = System.IO.File.OpenRead(filename))
using (var streamReader = new System.IO.StreamReader(fileStream))
{
e.LoadedDataAsXml = streamReader.ReadToEnd();
e.ContinueWithDefault = false;
}
}
}
Synchronizing when connectivity is available
The device documentation identifies synchronization of locally changed data to a Turnkey server through REST APIs as a possible extension. Design the exchanged data and synchronization behavior for the specific application.
The source material does not define a general synchronization protocol, conflict-resolution policy, or automatic synchronization behavior.
Related deployment options
The MDriven Developer's Guide lists Progressive Web Apps with offline capabilities among deployment options. Consult the applicable deployment documentation before treating PWA offline behavior as equivalent to the device-local persistence example on this page.
