using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace ODataOLAP
{
    using System.Data.Services.Client;
    using ODataOLAP.ServiceReference1;

    public partial class MainPage : UserControl
    {
        static Uri _svcRoot = new Uri("http://services.odata.org/Northwind/Northwind.svc/");
        NorthwindEntities _context = new NorthwindEntities(_svcRoot);

        public MainPage()
        {
            InitializeComponent();
            Loaded += MainPage_Loaded;
        }

        void MainPage_Loaded(object sender, RoutedEventArgs e)
        {
            // load invoices
            var invoices = new DataServiceCollection<Invoice>();
            invoices.LoadCompleted += (s, ee) =>
            {
                if (invoices.Continuation == null)
                {
                    // done loading
                    _lblStatus.Text = string.Format("Ready. {0:n0} invoices loaded.", invoices.Count);
                }
                else
                {
                    // continue loading...
                    _lblStatus.Text = string.Format("Loading, {0:n0} invoices so far...", invoices.Count);
                    invoices.LoadNextPartialSetAsync();
                }
            };
            invoices.LoadAsync(_context.Invoices);

            // bind olap page to invoices
            _c1OlapPage.DataSource = invoices;
        }
    }
}
