/// <summary> /// Determines whether the web.config file contains entries for the selected data provider for the membership, role, /// and gallery data providers. Note that this does not verify the provider is selected (that is, is specified in the /// defaultProvider attribute); it only verifies that the entry exists within those sections. Use the method /// AreProvidersSpecifiedInWebConfig to determine whether the selected provider is selected as the currently active /// provider. /// </summary> /// <param name="providerName">The provider to check for in web.config (e.b. SqlCe or SqlServer).</param> /// <returns>Returns <c>true</c> if the membership, role, and gallery data providers in web.config contain entries /// corresponding to the data provider selected by the user; otherwise returns <c>false</c>.</returns> /// <remarks>Unfortunately, we cannot use WebConfigurationManager.GetSection, as that works only in Full Trust.</remarks> public static bool AreProvidersAvailableInWebConfig(ProviderDataStore providerName) { if (providerName == ProviderDataStore.SQLite) { throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "WebConfigController.AreProvidersAvailableInWebConfig() does not accept parameter 'providerName' set to {0}.", providerName)); } string membershipProviderName = (providerName == ProviderDataStore.SqlCe ? "SqlCeMembershipProvider" : "SqlMembershipProvider"); string roleProviderName = (providerName == ProviderDataStore.SqlCe ? "SqlCeRoleProvider" : "SqlRoleProvider"); string galleryDataProviderName = (providerName == ProviderDataStore.SqlCe ? "SqlCeGalleryServerProProvider" : "SqlServerGalleryServerProProvider"); XmlDocument webConfig = GetWebConfigXmlDoc(); XPathNavigator xpathNav = webConfig.CreateNavigator(); string xpathQuery = String.Format(CultureInfo.InvariantCulture, "/configuration/system.web/membership/providers/add[@name=\"{0}\"]", membershipProviderName); bool membershipProviderIsAvailable = (xpathNav.SelectSingleNode(xpathQuery) != null); xpathQuery = String.Format(CultureInfo.InvariantCulture, "/configuration/system.web/roleManager/providers/add[@name=\"{0}\"]", roleProviderName); bool roleProviderIsAvailable = (xpathNav.SelectSingleNode(xpathQuery) != null); xpathQuery = String.Format(CultureInfo.InvariantCulture, "/configuration/system.web/galleryServerPro/dataProvider/providers/add[@name=\"{0}\"]", galleryDataProviderName); bool galleryDataProviderIsAvailable = (xpathNav.SelectSingleNode(xpathQuery) != null); return(membershipProviderIsAvailable && roleProviderIsAvailable && galleryDataProviderIsAvailable); }
/// <summary> /// Upgrades the <paramref name="ds" /> from the 2.6 schema to the current schema. This is done by creating a new set of tables in the /// dataset that match the current schema, then populating them with data from the 2.6 tables that are already present. As the data /// is copied, it is converted into the required format. The <paramref name="dataStore" />, <paramref name="cn" />, and /// <paramref name="tran" /> are used only for updating the UI templates to point to the template gallery in the data to be imported. /// </summary> /// <param name="ds">The DataSet.</param> /// <param name="targetSchema">The schema version to convert to. An <see cref="ArgumentException" /> if the value does not match /// the current schema of this application.</param> /// <param name="dataStore">The current data store.</param> /// <param name="cn">The connection being used to import the data.</param> /// <param name="tran">The transaction being used to import the data.</param> /// <exception cref="System.ArgumentException">Thrown when <paramref name="targetSchema" /> does not match the current schema of /// this application.</exception> /// <exception cref="System.Exception">Thrown when the existing schema of the data in the <paramref name="ds" /> is not /// <see cref="GalleryDataSchemaVersion.V2_6_0" />.</exception> public static void UpgradeData(DataSet ds, GalleryDataSchemaVersion targetSchema, ProviderDataStore dataStore, IDbConnection cn, IDbTransaction tran) { if (targetSchema != GalleryDb.DataSchemaVersion) { throw new ArgumentException(String.Format("This method is designed to upgrade only to version {0}.", GalleryDb.DataSchemaVersion), "targetSchema"); } if (BackupFileController.GetDataSchemaVersion(ds) != GalleryDataSchemaVersion.V2_6_0) { throw new Exception(String.Format("This method is designed to upgrade from version {0} only.", GalleryDataSchemaVersion.V2_6_0)); } var asm = Assembly.GetExecutingAssembly(); using (var stream = asm.GetManifestResourceStream("GalleryServerPro.Data.Schema.GalleryServerProSchema.xml")) { // Read in the current schema. This creates new, empty tables we'll populate from the existing data. ds.ReadXmlSchema(stream); } MigrateApplications(ds); // Don't import profiles. Several columns have changed data types and GSP doesn't use it anyway. //ds.Tables["Profiles"].Merge(ds.Tables["aspnet_Profile"]); MigrateAspNetRoles(ds); MigrateUsers(ds); MigrateMemberships(ds); MigrateUsersInRoles(ds); MigrateAppSettings(ds); MigrateGalleries(ds); MigrateGallerySettings(ds); MigrateAlbums(ds); MigrateRoles(ds); MigrateRoleAlbums(ds); MigrateMediaObjects(ds); MigrateMetadata(ds); MigrateMimeTypeGalleries(ds, dataStore, cn, tran); MigrateTags(ds); MigrateUserGalleryProfiles(ds); MigrateGalleryControlSettings(ds); MigrateUiTemplates(ds, dataStore, cn, tran); }
/// <summary> /// Update database values as required for the current version. Typically this is used to apply bug fixes /// that require updates to database settings (such as media and UI templates). /// </summary> /// <param name="ctx">Context to be used for updating data.</param> /// <param name="galleryDataStore">The type of database used for the gallery data.</param> /// <remarks>This function detects the current app schema version as defined in the AppSetting table and applies /// all relevant updates to bring it up to the current version. By the time this method exits, the app schema version /// in the AppSetting table will match the current schema version as defined in <see cref="GalleryDb.DataSchemaVersion" />. /// </remarks> /// <exception cref="System.Exception"></exception> public static void ApplyDbUpdates(GalleryDb ctx, ProviderDataStore galleryDataStore) { if (!ctx.AppSettings.Any()) { SeedController.InsertSeedData(ctx); } var curSchema = GetCurrentSchema(ctx); while (curSchema < GalleryDb.DataSchemaVersion) { var oldSchema = curSchema; switch (curSchema) { case GalleryDataSchemaVersion.V3_0_0: UpgradeTo301(ctx); break; case GalleryDataSchemaVersion.V3_0_1: UpgradeTo302(ctx); break; case GalleryDataSchemaVersion.V3_0_2: UpgradeTo303(ctx); break; case GalleryDataSchemaVersion.V3_0_3: UpgradeTo310(ctx); break; case GalleryDataSchemaVersion.V3_1_0: UpgradeTo320(ctx); break; case GalleryDataSchemaVersion.V3_2_0: UpgradeTo321(ctx); break; case GalleryDataSchemaVersion.V3_2_1: UpgradeTo400(ctx, galleryDataStore); break; case GalleryDataSchemaVersion.V4_0_0: UpgradeTo401(ctx); break; case GalleryDataSchemaVersion.V4_0_1: UpgradeTo410(ctx); break; case GalleryDataSchemaVersion.V4_1_0: UpgradeTo420(ctx); break; case GalleryDataSchemaVersion.V4_2_0: UpgradeTo421(ctx); break; case GalleryDataSchemaVersion.V4_2_1: UpgradeTo430(ctx); break; case GalleryDataSchemaVersion.V4_3_0: UpgradeTo440(ctx); break; case GalleryDataSchemaVersion.V4_4_0: UpgradeTo441(ctx); break; case GalleryDataSchemaVersion.V4_4_1: UpgradeTo442(ctx); break; case GalleryDataSchemaVersion.V4_4_2: UpgradeTo443(ctx); break; case GalleryDataSchemaVersion.V4_4_3: UpgradeTo450(ctx); break; } curSchema = GetCurrentSchema(ctx); if (curSchema == oldSchema) { throw new Exception(String.Format("The migration function for schema {0} should have incremented the data schema version in the AppSetting table, but it did not.", curSchema)); } } }
/// <summary> /// Gets the schema-qualified name for the specified <paramref name="rawName" />. For SQL Server, the name is prefixed with the schema "gsp.". /// For SQL CE, the value is returned without any changes. An exception is thrown for all other data providers. /// </summary> /// <param name="rawName">Name of the table.</param> /// <param name="galleryDataStore">The data provider for the gallery data.</param> /// <param name="schema">The schema. Defaults to "gsp" if not specified.</param> /// <returns>Returns the schema qualified name for <paramref name="rawName" />.</returns> /// <exception cref="System.ComponentModel.InvalidEnumArgumentException"></exception> public static string GetSqlName(string rawName, ProviderDataStore galleryDataStore, string schema = "gsp") { switch (galleryDataStore) { case ProviderDataStore.SqlServer: return(String.Concat(schema, ".", rawName)); case ProviderDataStore.SqlCe: return(rawName); default: throw new System.ComponentModel.InvalidEnumArgumentException(string.Format("This function is not designed to handle the enum value {0}.", galleryDataStore)); } }
/// <summary> /// Adds the missing metadata that must be added for a 2.6 => 3 migration. This includes captions for all /// media objects and tags/people for albums and media objects. No tags or people are assigned to the root album. /// All values are set to empty strings. /// </summary> /// <param name="dataStore">The data store.</param> /// <param name="cn">The connection.</param> /// <param name="tran">The transaction.</param> public static void AddMissingMeta(ProviderDataStore dataStore, IDbConnection cn, IDbTransaction tran) { // Add blank captions for all media objects and blank tags/people for albums and media objects. if (dataStore == ProviderDataStore.SqlCe) { ResetSqlCeIdentityColumn("Metadata", cn, tran); } var metaTableName = Utils.GetSqlName("Metadata", dataStore); var sqls = new[] { String.Format("INSERT INTO {0} (MetaName,FKMediaObjectId,FKAlbumId,Value) SELECT {1}, MediaObjectId, null, '' FROM {2};", metaTableName, (int)MetadataItemName.Caption, Utils.GetSqlName("MediaObject", dataStore)), String.Format("INSERT INTO {0} (MetaName,FKMediaObjectId,FKAlbumId,Value) SELECT {1}, MediaObjectId, null, '' FROM {2} WHERE MediaObjectId NOT IN (SELECT FKMediaObjectId FROM {0} WHERE MetaName={1});", metaTableName, (int)MetadataItemName.Tags, Utils.GetSqlName("MediaObject", dataStore)), String.Format("INSERT INTO {0} (MetaName,FKMediaObjectId,FKAlbumId,Value) SELECT {1}, MediaObjectId, null, '' FROM {2};", metaTableName, (int)MetadataItemName.People, Utils.GetSqlName("MediaObject", dataStore)), String.Format("INSERT INTO {0} (MetaName,FKMediaObjectId,FKAlbumId,Value) SELECT {1}, null, AlbumId, '' FROM {2} WHERE FKAlbumParentId IS NOT NULL;", metaTableName, (int)MetadataItemName.Tags, Utils.GetSqlName("Album", dataStore)), String.Format("INSERT INTO {0} (MetaName,FKMediaObjectId,FKAlbumId,Value) SELECT {1}, null, AlbumId, '' FROM {2} WHERE FKAlbumParentId IS NOT NULL;", metaTableName, (int)MetadataItemName.People, Utils.GetSqlName("Album", dataStore)), }; using (var cmd = cn.CreateCommand()) { cmd.Transaction = tran; foreach (var sql in sqls) { cmd.CommandText = sql; try { cmd.ExecuteNonQuery(); } catch (Exception ex) { if (!ex.Data.Contains("SQL")) { ex.Data.Add("SQL", sql); } throw; } } } }
private static ProviderDataStore GetDataProvider(WebConfigEntity wce) { // Update the data provider. Each provider (membership, roles, and gallery data) could theoretically use a different // database technology, but we are most interested in where the gallery data is stored, so use that one. ProviderDataStore dataProvider = ProviderDataStore.Unknown; switch (wce.GalleryDataDefaultProvider) { case GalleryDataProvider.SQLiteGalleryServerProProvider: dataProvider = ProviderDataStore.SQLite; break; case GalleryDataProvider.SqlCeGalleryServerProProvider: dataProvider = ProviderDataStore.SqlCe; break; case GalleryDataProvider.SqlServerGalleryServerProProvider: dataProvider = ProviderDataStore.SqlServer; break; } return(dataProvider); }
/// <summary> /// Upgrades the 3.2.1 data to the 4.0.0 data. Applies to data such as app settings, gallery settings, templates, etc. /// Does not contain data structure changes such as new columns. /// </summary> /// <param name="ctx">Context to be used for updating data.</param> /// <param name="galleryDataStore">The type of database used for the gallery data.</param> public static void UpgradeTo400(GalleryDb ctx, ProviderDataStore galleryDataStore) { UpgradeAppSettings(ctx); UpgradeGallerySettings(ctx); UpgradeUiTemplates(ctx); UpgradeGalleryControlSettings(ctx); UpdateMetadata(ctx); UpdateMediaTemplates(ctx); UpgradeMimeTypes(ctx); if (galleryDataStore == ProviderDataStore.SqlCe) { RevertCeEfBugWorkAround(); } // Update data schema version to 4.0.0 var asDataSchema = ctx.AppSettings.First(a => a.SettingName == "DataSchemaVersion"); asDataSchema.SettingValue = "4.0.0"; ctx.SaveChanges(); }
/// <summary> /// Determines whether the web.config file contains entries for the selected data provider for the membership, role, /// and gallery data providers. Note that this does not verify the provider is selected (that is, is specified in the /// defaultProvider attribute); it only verifies that the entry exists within those sections. Use the method /// AreProvidersSpecifiedInWebConfig to determine whether the selected provider is selected as the currently active /// provider. /// </summary> /// <param name="providerName">The provider to check for in web.config (e.b. SqlCe or SqlServer).</param> /// <returns>Returns <c>true</c> if the membership, role, and gallery data providers in web.config contain entries /// corresponding to the data provider selected by the user; otherwise returns <c>false</c>.</returns> /// <remarks>Unfortunately, we cannot use WebConfigurationManager.GetSection, as that works only in Full Trust.</remarks> public static bool AreProvidersAvailableInWebConfig(ProviderDataStore providerName) { if (providerName == ProviderDataStore.SQLite) throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "WebConfigController.AreProvidersAvailableInWebConfig() does not accept parameter 'providerName' set to {0}.", providerName)); string membershipProviderName = (providerName == ProviderDataStore.SqlCe ? "SqlCeMembershipProvider" : "SqlMembershipProvider"); string roleProviderName = (providerName == ProviderDataStore.SqlCe ? "SqlCeRoleProvider" : "SqlRoleProvider"); string galleryDataProviderName = (providerName == ProviderDataStore.SqlCe ? "SqlCeGalleryServerProProvider" : "SqlServerGalleryServerProProvider"); XmlDocument webConfig = GetWebConfigXmlDoc(); XPathNavigator xpathNav = webConfig.CreateNavigator(); string xpathQuery = String.Format(CultureInfo.InvariantCulture, "/configuration/system.web/membership/providers/add[@name=\"{0}\"]", membershipProviderName); bool membershipProviderIsAvailable = (xpathNav.SelectSingleNode(xpathQuery) != null); xpathQuery = String.Format(CultureInfo.InvariantCulture, "/configuration/system.web/roleManager/providers/add[@name=\"{0}\"]", roleProviderName); bool roleProviderIsAvailable = (xpathNav.SelectSingleNode(xpathQuery) != null); xpathQuery = String.Format(CultureInfo.InvariantCulture, "/configuration/system.web/galleryServerPro/dataProvider/providers/add[@name=\"{0}\"]", galleryDataProviderName); bool galleryDataProviderIsAvailable = (xpathNav.SelectSingleNode(xpathQuery) != null); return (membershipProviderIsAvailable && roleProviderIsAvailable && galleryDataProviderIsAvailable); }
/// <summary> /// Update database values that are affected by changing the name from Gallery Server Pro to Gallery Server. Specifically, (1) Change the /// ContextKey in the __MigrationHistory table from "GalleryServerPro.Data.Migrations.GalleryDbMigrationConfiguration" to /// "GalleryServer.Data.Migrations.GalleryDbMigrationConfiguration" (required because the namespace was updated). (2) Change the Membership /// application name. This is required because of the update to the applicationName attribute in the membership and roleManager sections of web.config. /// </summary> /// <param name="providerDataStore">The provider data store.</param> /// <param name="v4SchemaUpdateRequiredFilePath">The full path to the semaphore whose presence indicates that this function must run. /// This file is deleted at the end of this method. Example: "C:\Dev\GS\Dev-Main\Website\App_Data\v4_schema_update_required.txt"</param> /// <remarks>WARNING: If the membership points to a different database than the one the gallery data is in, or the current application name is something /// other than "Gallery Server Pro", the upgrade will fail to change the application name in the database. In this case, the admin should /// manually update the text in the Applications.ApplicationName column or update the applicationName attribute in web.config to match the DB value. /// </remarks> public static void ChangeNamespaceForVersion4Upgrade(ProviderDataStore providerDataStore, string v4SchemaUpdateRequiredFilePath) { //throw new NotImplementedException(); //Data.Interfaces.IDbController sqlController = null; //switch (providerDataStore) //{ // case ProviderDataStore.SqlCe: // sqlController = new SqlCeController(); // break; // case ProviderDataStore.SqlServer: // sqlController = new SqlServerController(); // break; //} //if (sqlController != null) //{ // using (var cn = sqlController.GetDbConnection()) // { // using (var cmd = cn.CreateCommand()) // { // cmd.CommandText = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='__MigrationHistory' AND COLUMN_NAME='ContextKey'"; // try // { // cn.Open(); // } // catch // { // // We'll typically get here when a user is installing Gallery Server since at that point the database may not exist. In this scenario // // we don't want to run this upgrade script anyway, so just exit. We don't delete the semaphore file, though, because it's possible // // the user *is* upgrading and got the connection string wrong. In that case, we want the error to bubble up to the user so she can // // fix it. Eventually this function will run again and succeed, and the file will be deleted at the end of the function. // return; // } // var hasContextKey = Convert.ToInt32(cmd.ExecuteScalar()) > 0; // GS 3.0-3.1 won't have a ContextKey column because EF 5 didn't have it // if (hasContextKey) // { // // Change the EF context key to reflect the namespace change from GalleryServerPro to GalleryServer. // cmd.CommandText = $"UPDATE {Utils.GetSqlName("__MigrationHistory", providerDataStore, "dbo")} SET ContextKey='GalleryServer.Data.Migrations.GalleryDbMigrationConfiguration' WHERE ContextKey='GalleryServerPro.Data.Migrations.GalleryDbMigrationConfiguration'"; // cmd.ExecuteNonQuery(); // } // cmd.CommandText = "SELECT COUNT(*) from INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='Applications'"; // var hasAppTable = Convert.ToInt32(cmd.ExecuteScalar()) > 0; // if (hasAppTable) // { // // Change the application name from "Gallery Server Pro" to "Gallery Server" in the Membership system. // cmd.CommandText = $"UPDATE {Utils.GetSqlName("Applications", providerDataStore, "dbo")} SET ApplicationName='Gallery Server' WHERE ApplicationName='Gallery Server Pro'"; // cmd.ExecuteNonQuery(); // } // // We need a workaround for the issue described at https://entityframework.codeplex.com/workitem/2659. If user is coming from a // // version of GS that used EF 5 (GS 3.0-3.1), then rename the primary key on __MigrationHistory. Later in the Seed override, // // we'll revert this change (Migrate40Controller.RevertCeEfBugWorkAround()). Without this, we'll get the error // // "The foreign key constraint does not exist. [ PK___MigrationHistory ]" in DbMigrator.Update() method. // if (providerDataStore == ProviderDataStore.SqlCe) // { // cmd.CommandText = "SELECT COUNT(*) FROM __MigrationHistory WHERE ProductVersion LIKE '6%'"; // var comingFromEf5 = Convert.ToInt32(cmd.ExecuteScalar()) == 0; // if (comingFromEf5) // { // cmd.CommandText = "SELECT COUNT(*) FROM Information_SCHEMA.KEY_COLUMN_USAGE WHERE CONSTRAINT_NAME='PK_dbo.__MigrationHistory' AND TABLE_NAME='__MigrationHistory';"; // var hasKeyName = Convert.ToInt32(cmd.ExecuteScalar()) > 0; // if (hasKeyName) // { // cmd.CommandText = "ALTER TABLE __MigrationHistory DROP CONSTRAINT [PK_dbo.__MigrationHistory];"; // cmd.ExecuteNonQuery(); // cmd.CommandText = "ALTER TABLE __MigrationHistory ADD CONSTRAINT [PK___MigrationHistory] PRIMARY KEY (MigrationId);"; // cmd.ExecuteNonQuery(); // } // } // } // } // } //} //// Delete the semaphore file App_Data\v4_schema_update_required.txt so that this never runs again. //System.IO.File.Delete(v4SchemaUpdateRequiredFilePath); }
/// <summary> /// Update the UITemplate table to work with the new data. We don't have any templates from a previous version, but we have the current ones for 3 in /// the database, so what we do is find the UI templates that map to the template gallery and update the FKGalleryId value to the template gallery ID /// in the data we are importing, then we'll delete any UI templates not belonging to the template gallery. /// </summary> /// <param name="ds">The DataSet.</param> /// <param name="dataStore">The data store currently being used for gallery data.</param> /// <param name="cn">The connection.</param> /// <param name="tran">The transaction.</param> private static void MigrateUiTemplates(DataSet ds, ProviderDataStore dataStore, IDbConnection cn, IDbTransaction tran) { // Get the template gallery ID for the gallery we'll be importing. At this moment this info is in the dataset because we haven't yet // imported it into the table. var tmplGalleryId = Convert.ToInt32(ds.Tables["Gallery"].Select("IsTemplate = true").First()["GalleryId"]); using (var cmd = cn.CreateCommand()) { // Get the UI templates belonging to the template gallery. We have to do a join here because the data // model doesn't have a relationship. (Doing so would conflict with the relationship between // the UITemplateAlbum and Album tables.) var uiTmplTableName = Utils.GetSqlName("UiTemplate", dataStore); using (var repo = new UiTemplateRepository()) { var ctx = repo.Context; var tmplForTmplGallery = from uiTmpl in ctx.UiTemplates join g in ctx.Galleries on uiTmpl.FKGalleryId equals g.GalleryId where g.IsTemplate select uiTmpl; // For each UI template, make sure one exists in the gallery cmd.Transaction = tran; foreach (var uiTmpl in tmplForTmplGallery) { var sql = String.Format(CultureInfo.InvariantCulture, "UPDATE {0} SET FKGalleryId = {1} WHERE UiTemplateId = {2};", uiTmplTableName, tmplGalleryId, uiTmpl.UiTemplateId); cmd.CommandText = sql; cmd.ExecuteNonQuery(); } } using (var cmdDr = cn.CreateCommand()) { cmdDr.Transaction = tran; cmdDr.CommandText = String.Format(CultureInfo.InvariantCulture, "SELECT UiTemplateId FROM {0} WHERE FKGalleryId <> {1};", uiTmplTableName, tmplGalleryId); using (var dr = cmdDr.ExecuteReader()) { while (dr != null && dr.Read()) { var sql = String.Format(CultureInfo.InvariantCulture, "DELETE FROM {0} WHERE UiTemplateId = {1};", uiTmplTableName, dr[0]); cmd.CommandText = sql; cmd.ExecuteNonQuery(); } } } } }
/// <summary> /// Migrates the IsEnabled property from the gs_MimeTypeGallery table. It's OK if there are new MIME types in later versions that /// aren't present in the old table - validation code during app startup verifies there is a record in MimeTypeGallery for each /// gallery and MIME type. /// </summary> /// <param name="ds">The DataSet.</param> /// <param name="dataStore">The data store currently being used for gallery data.</param> /// <param name="cn">The connection.</param> /// <param name="tran">The transaction.</param> private static void MigrateMimeTypeGalleries(DataSet ds, ProviderDataStore dataStore, IDbConnection cn, IDbTransaction tran) { var dtSource = ds.Tables["gs_MimeTypeGallery"]; var dtDest = ds.Tables["MimeTypeGallery"]; var mimeType26 = ds.Tables["gs_MimeType"]; var colsToSkip = new[] { "MimeTypeGalleryId" }; using (var cmd = cn.CreateCommand()) { cmd.Transaction = tran; foreach (DataRow rSource in dtSource.Rows) { var rDest = dtDest.NewRow(); var fileExt = mimeType26.Select(String.Concat("MimeTypeId = ", rSource["FKMimeTypeId"])).First()["FileExtension"]; // Get the MimeTypeId from the MimeType table. We can't use the ID from gs_MimeType because we aren't migrating that // data and the ID values in MimeType might be different. cmd.CommandText = String.Format(CultureInfo.InvariantCulture, @"SELECT MimeTypeId FROM {0} WHERE FileExtension='{1}'", Utils.GetSqlName("MimeType", dataStore), fileExt); var mimeTypeId = cmd.ExecuteScalar(); if (mimeTypeId == null) continue; foreach (DataColumn col in dtSource.Columns) { if (Array.IndexOf(colsToSkip, col.ColumnName) >= 0) continue; switch (col.ColumnName) { case "FKMimeTypeId": rDest[col.ColumnName] = mimeTypeId; break; default: rDest[col.ColumnName] = rSource[col]; break; } } dtDest.Rows.Add(rDest); } } }
/// <summary> /// Upgrades the 3.2.1 data to the 4.0.0 data. Applies to data such as app settings, gallery settings, templates, etc. /// Does not contain data structure changes such as new columns. /// </summary> /// <param name="ctx">Context to be used for updating data.</param> /// <param name="galleryDataStore">The type of database used for the gallery data.</param> private static void UpgradeTo400(GalleryDb ctx, ProviderDataStore galleryDataStore) { Migrate40Controller.UpgradeTo400(ctx, galleryDataStore); }