/// <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(ServiceUri + "/Services/NotesDataService.svc"));

            Debug.Assert(!string.IsNullOrEmpty(this.AuthSchema), "The AuthSchema property should be initialized!");

            // 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"] = this.AuthSchema + " " + 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);
        }
예제 #2
0
 public BaseBOLNotes()
 {
     dataContext = new NotesDataContext();
 }