public TripDetailPageViewModel() { if (DesignMode.DesignModeEnabled) { CurrentTrip = SeedDataFactory.CreateDesignTrip(); CurrentSight = CurrentTrip.Sights[0]; Sights = new ObservableCollection <Sight>( CurrentTrip.Sights.OrderBy(s => s.RankInDestination)); BuildSightGroups(); Debug.WriteLine("Debug mode for the model"); } }
// this is different from Disable, example: during updates where we only want to unload -> reload // Enable is user intention. Load respects enable, but unload doesn't care public async void Unload() { // This is broken in 14291 - worked in 14273! //StorageFolder folder = await _extension.GetPublicFolderAsync(); // HACK - temporarily set folder to the Models folder in the package - have put a copy of the SanFranciscoSights.json in there StorageFolder folder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Models"); if (folder == null) { return; //nothing to unload } // load file from extension package string fileName = @"SanFranciscoSights.json"; StorageFile file = await folder.GetFileAsync(fileName); var extensionsTrip = await SeedDataFactory.CreateSampleTrip(file); var modelService = DataModelServiceFactory.CurrentDataModelService(); var currentTrip = await modelService.LoadTripAsync(AppSettings.LastTripId); // unload it lock (_sync) { if (Loaded) { foreach (var sight in extensionsTrip.Sights) { var importedSight = currentTrip.Sights.Single(s => s.Name == sight.Name); if (!importedSight.IsMySight) { modelService.DeleteSightAsync(importedSight); } } // see if package is offline if (!_extension.Package.Status.VerifyIsOK() && !_extension.Package.Status.PackageOffline) { _offline = true; } Loaded = false; } } }
public async void CreateTrip() { #if !SQLITE await AppShell.Current.SetBusyAsync("Synchronising"); await SeedDataFactory.LoadDataAsync(); await AppShell.Current.ClearBusyAsync(); #endif // NOTE: SeedDatafactory sets AppSettings.LastTripId to the trip Id value generated from the Seed Data AppShell.Current.AddTrip("San Francisco", AppSettings.LastTripId); AppSettings.HasRun = true; // the following will launch directly to the detail view of the closest sight //var parameter = new TripNavigationParameter { TripId = AppSettings.LastTripId, DisplayClosestSight = true }.GetJson(); var parameter = new TripNavigationParameter { TripId = AppSettings.LastTripId }.GetJson(); AppShell.Current.NavigateToPage(typeof(TripDetailPage), parameter); AppShell.Current.Frame?.BackStack.Clear(); }
// this controls loading of the extension public async Task Load() { // if it's not enabled or already loaded, don't load it if (!Enabled || Loaded) { return; } // make sure package is OK to load if (!_extension.Package.Status.VerifyIsOK()) { return; } // Extension is not loaded and enabled - load it StorageFolder folder = await _extension.GetPublicFolderAsync(); if (folder != null) { // load file from extension package String fileName = @"SanFranciscoSights.json"; StorageFile file = await folder.GetFileAsync(fileName); var extensionsTrip = await SeedDataFactory.CreateSampleTrip(file); foreach (var sight in extensionsTrip.Sights) { sight.TripId = AppSettings.LastTripId; } var dataModelService = DataModelServiceFactory.CurrentDataModelService(); await dataModelService.InsertSights(extensionsTrip.Sights); } Loaded = true; _offline = false; }