|
namespace RegiRide.Views
{
using System;
using System.Windows;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using RegiRide.Resources;
using RegiRide.Utils;
using RegiRide.ViewModels;
public partial class Dropbox : PhoneApplicationPage
{
private readonly NetworkConnection networkConnection;
public Dropbox()
{
InitializeComponent();
networkConnection = new NetworkConnection();
LoadDropbox();
}
private void LoadDropbox()
{
bool isConnected = networkConnection.IsAvailable();
if (isConnected)
{
var viewModel = DataContext as DropboxViewModel;
BusyIndicator.Visibility = Visibility.Visible;
viewModel.DropNetClient.GetTokenAsync(
userToken =>
{
var tokenUrl = viewModel.DropNetClient.BuildAuthorizeUrl("http://www.semanticarchitecture.net/regiride.html");
loginBrowser.LoadCompleted += this.loginBrowser_LoadCompleted;
loginBrowser.Navigate(new Uri(tokenUrl));
},
error =>
Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(error.Response.ErrorMessage)));
}
else
{
MessageBox.Show(AppResources.NoNetworkAvailable);
}
}
private void loginBrowser_LoadCompleted(object sender, NavigationEventArgs e)
{
BusyIndicator.Visibility = Visibility.Collapsed;
bool isConnected = networkConnection.IsAvailable();
if (isConnected)
{
if (e.Uri.AbsolutePath == "/regiride.html")
{
var viewModel = DataContext as DropboxViewModel;
viewModel.DropNetClient.GetAccessTokenAsync(
response =>
{
viewModel.StoreToken(response.Token);
viewModel.StoreSecret(response.Secret);
viewModel.AuthenticatedSuccessfully();
},
error =>
Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show(error.Response.ErrorMessage)));
}
}
else
{
MessageBox.Show(AppResources.NoNetworkAvailable);
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Patrick Kalkman is a senior Software Architect with more than 20 years professional development experience. He works for
SimpleTechture where he helps teams develop state of the art web applications.
Patrick enjoys writing his
blog. It discusses agile software development. Patrick can be reached at patrick@simpletechture.nl.
Published Windows 8 apps:
Published Windows Phone apps:
Awards:
Best Mobile article of March 2012
Best Mobile article of June 2012