private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            //Get setting from the app config
            _AppId = Properties.Settings.Default.AppId;
            _DomainUrl = Properties.Settings.Default.DomainUrl;
            _PageId = Properties.Settings.Default.PageId;
            _LoginUrl = string.Format(URL_TEMPLATE, _AppId, _DomainUrl);
            _LoginForm = new Login(LoginCallback, _LoginUrl , "");

            //Plugin the view model
            _ViewModel = new MainWindowViewModel { CsvFileLocation = string.Empty };
            DataContext = _ViewModel;

            //Disable app buttons until after the user has settings and is logged in
            LoginMenu.IsEnabled = false;
            BrowseForFiles.IsEnabled = false;

            //Make sure that there are settings in place
            if (string.IsNullOrEmpty(_AppId) || string.IsNullOrEmpty(_DomainUrl) || string.IsNullOrEmpty(_PageId))
            {
                var settingsForm = new Settings(SaveSettingsCallback);
                settingsForm.ShowDialog();

                DisableLogin();
            }
            else
            {
                //Make sure that the user is logged in.
                _LoginForm.LoginUser();
                _LoginForm.ShowDialog();
                LoginMenu.Visibility = Visibility.Visible;
                EnableLogin();
            }

            DisableBrowse();
        }
        private void LoginMenu_OnClick(object sender, RoutedEventArgs e)
        {
            var fb = new FacebookClient();
            var parameters = new Dictionary<string, object>();
            parameters.Add("access_token", _AccessToken);
            parameters.Add("next", _LoginUrl);
            var logoutUrl = fb.GetLogoutUrl(parameters).ToString();

            if (_ViewModel.IsAuthenticated)
            {
                _ViewModel.IsAuthenticated = false;

                _AppId = Properties.Settings.Default.AppId;
                _DomainUrl = Properties.Settings.Default.DomainUrl;
                _PageId = Properties.Settings.Default.PageId;
                _LoginForm = new Login(LoginCallback, _LoginUrl, logoutUrl);
                _LoginForm.LogoutUser();
                _LoginForm.ShowDialog();

                DisableBrowse();
            }
            else
            {
                _AppId = Properties.Settings.Default.AppId;
                _DomainUrl = Properties.Settings.Default.DomainUrl;
                _PageId = Properties.Settings.Default.PageId;
                _LoginForm = new Login(LoginCallback, _LoginUrl, "");
                _LoginForm.LoginUser();
                _LoginForm.ShowDialog();
            }

            LoginMenu.Header = _ViewModel.IsAuthenticated ? "Logout" : "Login";
        }