public FlickrSource(IMetadataStore store, IPlacelessconfig configuration, IUserInteraction userInteraction) { _metadataStore = store; _configuration = configuration; _userInteraction = userInteraction; _flickr = new FlickrNet.Flickr(API_KEY, API_SECRET); _flickr.InstanceCacheDisabled = true; var token = _configuration.GetValue(TOKEN_PATH); var secret = _configuration.GetValue(SECRET_PATH); token = ""; secret = ""; if (string.IsNullOrWhiteSpace(token) || string.IsNullOrWhiteSpace(secret)) { var requestToken = _flickr.OAuthGetRequestToken("oob"); string url = _flickr.OAuthCalculateAuthorizationUrl(requestToken.Token, AuthLevel.Write); _userInteraction.OpenWebPage(url); string approvalCode = _userInteraction.InputPrompt("Please approve access to your Flickr account and enter the key here:"); var accessToken = _flickr.OAuthGetAccessToken(requestToken, approvalCode); token = accessToken.Token; secret = accessToken.TokenSecret; _configuration.SetValue(TOKEN_PATH, token); _configuration.SetValue(SECRET_PATH, secret); } _flickr.OAuthAccessToken = token; _flickr.OAuthAccessTokenSecret = secret; }
private void btnNewDatabase_Click(object sender, RoutedEventArgs e) { string connectionString = getConnectionString(); string rootPath = SqlMetadataStore.GetSqlPath(connectionString); var createDatabaseForm = new CreateDatabase(rootPath); if (createDatabaseForm.ShowDialog().GetValueOrDefault()) { SqlMetadataStore.CreateDatabase(connectionString, createDatabaseForm.DatabaseName, createDatabaseForm.DatabaseFile, createDatabaseForm.LogFile ); _config.SetValue(FileSystemBlobStore.BLOB_ROOT_PATH, System.IO.Path.Combine(rootPath, createDatabaseForm.DatabaseName + "_Files")); } }
private void wizDatabaseCreate_Initialize(object sender, AeroWizard.WizardPageInitEventArgs e) { var createDatabaseTask = new Task(() => { try { using (var localDB = new SqlLocalDbApi()) { ReportStatus("Searching for Localdb instance", 1); ReportStatus("Checking default Instance", 2); var connected = false; string instance = localDB.DefaultInstanceName; List <string> instanceNames = new List <string>(localDB.GetInstanceNames()); instanceNames = instanceNames.Where(n => n != instance).ToList(); // only non-default instances SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(); int iInstance = 0; while (!connected) { builder.DataSource = $"(LocalDb)\\{instance}"; builder.InitialCatalog = "Master"; builder.IntegratedSecurity = true; ReportStatus($"Connecting to {instance}", 2); var con = new SqlConnection(builder.ConnectionString); try { con.Open(); connected = true; } catch { connected = false; if (iInstance >= instanceNames.Count) { ReportStatus("Error: No LocalDb database instances could be connected to.", 0); return; } instance = instanceNames[iInstance]; iInstance++; } } ReportStatus($"Successfully connected to {instance}", 20); string databaseName = "Placeless"; int i = 0; var databaseNames = getDatabaseList(builder.ConnectionString); string mdf = System.IO.Path.Combine(txtDatabasePath.Text, $"{databaseName}.mdf"); string ldf = System.IO.Path.Combine(txtDatabasePath.Text, $"{databaseName}.ldf"); ReportStatus($"Selecting a unique database name", 30); while ( System.IO.File.Exists(mdf) || System.IO.File.Exists(ldf) || databaseNames.Contains(databaseName) ) { i++; databaseName = $"Placeless{i:D2}"; mdf = System.IO.Path.Combine(txtDatabasePath.Text, $"{databaseName}.mdf"); ldf = System.IO.Path.Combine(txtDatabasePath.Text, $"{databaseName}.ldf"); } ReportStatus($"Creating database {databaseName}.", 35); ReportStatus($"Data File: {mdf}", 35); ReportStatus($"Log File: {ldf}", 35); SqlMetadataStore.CreateDatabase(builder.ConnectionString, databaseName, mdf, ldf); builder.InitialCatalog = databaseName; ReportStatus($"Database Created, migrating", 80); var _dbContextOptions = SqlServerDbContextOptionsExtensions.UseSqlServer( new DbContextOptionsBuilder(), builder.ConnectionString, options => options.CommandTimeout(120) ).Options; using (var dbContext = new ApplicationDbContext(_dbContextOptions)) { dbContext.Database.Migrate(); } ReportStatus($"Migrations executed, updating config", 90); _config.SetValue(SqlMetadataStore.CONNECTION_STRING_SETTING, builder.ConnectionString); _config.SetValue(FileSystemBlobStore.BLOB_ROOT_PATH, System.IO.Path.Combine(txtDatabasePath.Text, $"{databaseName}_Files")); ReportStatus($"Configuration Updated", 100); this.Invoke((MethodInvoker) delegate { wizardControl1.NextPage(); }); } } catch (Exception ex) { this.Invoke((MethodInvoker) delegate { txtCreateDatabaseOutput.Text += ex.Message + "\r\n"; txtCreateDatabaseOutput.Text += ex.StackTrace + "\r\n"; }); } }, TaskCreationOptions.LongRunning); createDatabaseTask.Start(); }