public void RestoreState(IDictionary <string, object> storedState) { object stateAsString; Dictionary <string, object> collections; if (storedState.TryGetValue("DataServiceState", out stateAsString)) { var dsState = DataServiceState.Deserialize((string)stateAsString); this._context = dsState.Context as OratorEntities; collections = dsState.RootCollections; if (collections != null) { if (collections.ContainsKey("Events")) { this.Events = collections["Events"] as DataServiceCollection <Event>; if (collections.ContainsKey("Sessions")) { this.Sessions = collections["Sessions"] as DataServiceCollection <Session>; if (collections.ContainsKey("Speakers")) { this.Speakers = collections["Speakers"] as DataServiceCollection <SessionSpeaker>; } if (collections.ContainsKey("SessionFiles")) { this.SessionFiles = collections["SessionFiles"] as DataServiceCollection <SessionFile>; } } } } // Restore entity properties from the stored URI. _context.TryGetEntity <Session>(storedState["CurrentSession"] as Uri, out _currentSession); _context.TryGetEntity <Event>(storedState["CurrentEvent"] as Uri, out _currentEvent); _context.TryGetEntity <SessionSpeaker>(storedState["SingleSpeaker"] as Uri, out _singleSpeaker); // Restore other non-entity properties. this.TotalSessionCount = (int)storedState["TotalSessionCount"]; this.Message = (string)storedState["Message"]; this.CountMessage = (string)storedState["CountMessage"]; this.QueryInfo = (QueryHelper)storedState["QueryInfo"]; this.SessionCategories = (List <string>)storedState["SessionCategories"]; this.SessionDates = (List <string>)storedState["SessionDates"]; this.SessionTracks = (List <string>)storedState["SessionTracks"]; } }
void Deserialize(string contextDataString) { var contextData = DataServiceState.Deserialize(contextDataString); context = contextData.Context as OrlandoCodeCampEntities; var collections = contextData.RootCollections; Announcements = GetCollection <Announcement>(collections, "announcements"); Sessions = GetCollection <Session>(collections, "sessions"); Tracks = GetCollection <Track>(collections, "tracks"); Speakers = GetCollection <Person>(collections, "speakers"); Sponsors = GetCollection <Sponsor>(collections, "sponsors"); Timeslots = GetCollection <Timeslot>(collections, "timeslots"); IsDataLoaded = true; }
// Restores the view model state from the supplied state serialization. public void RestoreState(string appState) { // Create a dictionary to hold any stored binding collections. Dictionary <string, object> collections; if (!string.IsNullOrEmpty(appState)) { // Deserialize the DataServiceState object. DataServiceState state = DataServiceState.Deserialize(appState); // Restore the context and binding collections. var context = state.Context as NorthwindEntities; collections = state.RootCollections; // Get the binding collection of Customer objects. DataServiceCollection <Customer> customers = collections["Customers"] as DataServiceCollection <Customer>; // Initialize the application with stored data. App.ViewModel.LoadData(context, customers); } }
// Restores the view model state from the supplied state dictionary. public void RestoreState(IDictionary <string, object> dictionary) { // Create a dictionary to hold any stored binding collections. object titles; object stateAsString; if (dictionary.TryGetValue("DataServiceState", out stateAsString)) { // Rehydrate the DataServiceState object from the serialization. DataServiceState state = DataServiceState.Deserialize((string)stateAsString); if (state.RootCollections.TryGetValue("Titles", out titles)) { // Initialize the application with data from the DataServiceState. App.ViewModel.LoadData((NetflixCatalog)state.Context, (DataServiceCollection <Title>)titles); // Restore other view model data. _currentPage = (int)dictionary["CurrentPage"]; _totalCount = (int)dictionary["TotalCount"]; } } }