Esempio n. 1
0
        /// <summary>
        /// Loads quote summaries for the subscription
        /// </summary>
        public async void LoadQuoteSummariesAsync()
        {
            BusyMessage = Resources.LoadingQuoteSummariesMessage;

            // get the data service url
            var url = new Uri(ConfigurationManager.AppSettings["DataServiceUrl"]);

            // create repository
            var repository = new MarketDataRepository(url);

            // build url to query
            var queryUrl = string.Format("GetQuoteSummaries?subscriptionId={0}", Subscription.ID);

            // get quote summaries
            var quoteSummaries =
                await Task.Factory.StartNew(() =>
                    repository.Execute<SubscriptionQuoteSummary>(new Uri(queryUrl, UriKind.Relative), "GET", false));

            // set quote summaries
            Application.Current.Dispatcher.Invoke(() =>
                {
                    // set quote summaries
                    QuoteSummaries = new ObservableCollection<SubscriptionQuoteSummary>(quoteSummaries);

                    // clear busy message 
                    BusyMessage = null;
                });
        }
Esempio n. 2
0
        /// <summary>
        /// Asynchronously loads subscriptions
        /// </summary>
        public async void LoadAsync()
        {
            // set busy message
            BusyMessage = Resources.LoadingSubscriptionsMessage;

            // get the data service url
            var url = new Uri(ConfigurationManager.AppSettings["DataServiceUrl"]);

            // create repository
            var repository = new MarketDataRepository(url);

            // create collection into which to load data
            IEnumerable<DataProvider> dataProviders = null;
            IEnumerable<StockListProvider> stockListProviders = null;
            IEnumerable<Subscription> subscriptions = null;

            // load data async
            await Task.Factory.StartNew(() =>
                 {
                     dataProviders = repository.DataProviders.Execute();

                     stockListProviders = repository.StockListProviders.Execute();

                     subscriptions = repository.Subscriptions.Expand("DataProvider, StockListProvider").Execute();
                 });

            Application.Current.Dispatcher.Invoke(() =>
            {
                // set subscriptions
                DataProviders = new ObservableCollection<DataProvider>(dataProviders);
                StockListProviders = new ObservableCollection<StockListProvider>(stockListProviders);
                Subscriptions = new ObservableCollection<SubscriptionViewModel>(subscriptions.Select(s => new SubscriptionViewModel(s)));

                // clear busy message
                BusyMessage = string.Empty;
            });
        }