/// <summary> /// Reloads notes from server /// </summary> private void LoadData() { this.IsDataLoaded = false; this.IsUiEnabled = false; // preparing a data context this._context = new NotesDataContext(new Uri(NotesDataServiceUri)); // passing the authentication token obtained from Microsoft Account via the Authorization header this._context.SendingRequest += (sender, args) => { // let our header look a bit custom args.RequestHeaders["Authorization"] = Constants.AuthorizationHeaderPrefix + this._authenticationToken; }; var notes = new DataServiceCollection<Note>(this._context); notes.LoadCompleted += (sender, args) => { if (this.Notes.Continuation != null) { this.Notes.LoadNextPartialSetAsync(); return; } if (args.Error == null) { this.IsDataLoaded = true; } else { this.OnError.FireSafely(args.Error); } this.IsUiEnabled = true; }; // Defining a query var query = from note in this._context.Notes orderby note.TimeCreated descending select note; // Demonstrating LINQ query dynamic generation. notes.LoadAsync ( this._showTodaysNotesOnly ? // This will be translated into DynamoDb Query on the server, like this: // DynamoDb index query: SELECT * FROM Note WHERE TimeCreated GreaterThan <some DateTime> AND UserId Equal <some userId> ORDER BY TimeCreated DESC. Index name: TimeCreatedIndex query.Where(note => note.TimeCreated > DateTime.Today) : query ); this.Notes = notes; this.NotifyPropertyChanged(() => this.Notes); }
/// <summary> /// Stores the user's authentication token internally and reloads notes from server using that token /// </summary> public void SetAuthenticationToken(string token) { this._authenticationToken = token; if (string.IsNullOrEmpty(this._authenticationToken)) { this._context = null; this.Notes = null; this.NotifyPropertyChanged(() => this.Notes); this.IsDataLoaded = false; this.IsUiEnabled = false; } else { this.LoadData(); } }