private void SaveSettings(SqlAzureCredentials sqlAzureCredentials, string database)
 {
     Settings.Default.database       = database;
     Settings.Default.servername     = sqlAzureCredentials.ServerName;
     Settings.Default.storagekey     = sqlAzureCredentials.StorageKey;
     Settings.Default.username       = sqlAzureCredentials.Username;
     Settings.Default.password       = sqlAzureCredentials.Password;
     Settings.Default.localfolder    = LocalFolder;
     Settings.Default.storageaccount = StorageAccount;
     Settings.Default.Save();
 }
        protected override void OnViewLoaded(object view)
        {
            DisplayName                    = "SQLAzureBacpac";
            SqlAzureCredentials            = new SqlAzureCredentials();
            SqlAzureCredentials.ServerName = Settings.Default.servername;
            SqlAzureCredentials.StorageKey = Settings.Default.storagekey;
            SqlAzureCredentials.Password   = Settings.Default.password;
            SqlAzureCredentials.Username   = Settings.Default.username;
            StorageAccount                 = Settings.Default.storageaccount;
            LocalFolder                    = Settings.Default.localfolder;
            Database = Settings.Default.database;

            base.OnViewLoaded(view);
        }
        public async Task ExportAsync()
        {
            try
            {
                SaveSettings(SqlAzureCredentials, Database);
                Progress = 1;
                var progress = new Progress <int>(i => Progress = i);

                if (SqlAzureCredentials.IsValid() && !string.IsNullOrEmpty(Database) && !string.IsNullOrEmpty(StorageAccount))
                {
                    var ieHelper = new ImportExportHelper
                    {
                        EndPointUri  = @"https://am1prod-dacsvc.azure.com/DACWebService.svc/",
                        ServerName   = SqlAzureCredentials.ServerName,
                        StorageKey   = SqlAzureCredentials.StorageKey,
                        DatabaseName = Database,
                        UserName     = SqlAzureCredentials.Username,
                        Password     = SqlAzureCredentials.Password
                    };

                    string bacpacName = string.Format("{0}{1}", Database, DateTime.Now.Ticks);

                    await
                    ieHelper.DoExportAsync(
                        String.Format(@"http://{0}.blob.core.windows.net/bacpac/{1}.bacpac", StorageAccount,
                                      bacpacName), progress);

                    await SaveBacpac(bacpacName);

                    Progress = 90;
                    DeleteBacpacInCloud(bacpacName);
                    Progress = 100;
                }
            }
            catch (AggregateException aggregateException)
            {
                foreach (Exception innerException in aggregateException.InnerExceptions)
                {
                    ExceptionViewModel.Message = innerException.ToString();
                    _windowManager.ShowDialog(ExceptionViewModel);
                }
            }
            catch (Exception exception)
            {
                ExceptionViewModel.Message = exception.ToString();
                _windowManager.ShowDialog(ExceptionViewModel);
            }
        }