Skip to content

Commit

Permalink
Fixing upgrading existing 2.1.1 SQL sites to 3.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
IngvarKofoed committed Dec 7, 2011
1 parent bcf0cb1 commit f82836d
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal static InterfaceConfigurationElement AddNew(string providerName, DataTy
{
var configuration = new SqlDataProviderConfiguration(providerName);

InterfaceConfigurationElement interfaceConfig = BuildInterfaceConfigurationElement(dataTypeDescriptor);
InterfaceConfigurationElement interfaceConfig = BuildInterfaceConfigurationElement(dataTypeDescriptor, null);

if (configuration.Section.Interfaces.ContainsInterfaceType(interfaceConfig) == true)
{
Expand All @@ -43,11 +43,11 @@ internal static InterfaceConfigurationElement AddNew(string providerName, DataTy
}
}

internal static InterfaceConfigurationElement RefreshLocalizationInfo(string providerName, DataTypeDescriptor dataTypeDescriptor)
internal static InterfaceConfigurationElement RefreshLocalizationInfo(string providerName, DataTypeDescriptor dataTypeDescriptor, InterfaceConfigurationElement oldConfigurationElement)
{
var changeDescriptor = new DataTypeChangeDescriptor(dataTypeDescriptor, dataTypeDescriptor);

return Change(providerName, changeDescriptor, true);
return Change(providerName, changeDescriptor, true, oldConfigurationElement);
}

internal static bool ConfigurationExists( string providerName, DataTypeDescriptor dataTypeDescriptor)
Expand All @@ -56,15 +56,23 @@ internal static bool ConfigurationExists( string providerName, DataTypeDescripto
{
var configuration = new SqlDataProviderConfiguration(providerName);

InterfaceConfigurationElement interfaceConfig = BuildInterfaceConfigurationElement(dataTypeDescriptor);
InterfaceConfigurationElement interfaceConfig = BuildInterfaceConfigurationElement(dataTypeDescriptor, null);

return configuration.Section.Interfaces.ContainsInterfaceType(interfaceConfig);
}
}



internal static InterfaceConfigurationElement Change(string providerName, DataTypeChangeDescriptor changeDescriptor, bool localeChanges)
/// <summary>
///
/// </summary>
/// <param name="providerName"></param>
/// <param name="changeDescriptor"></param>
/// <param name="localeChanges"></param>
/// <param name="oldConfigurationElement">If this has a value, any existing tables names will be used instead of defaulting them</param>
/// <returns></returns>
internal static InterfaceConfigurationElement Change(string providerName, DataTypeChangeDescriptor changeDescriptor, bool localeChanges, InterfaceConfigurationElement oldConfigurationElement)
{
lock (_syncRoot)
{
Expand All @@ -86,10 +94,10 @@ internal static InterfaceConfigurationElement Change(string providerName, DataTy

Verify.IsTrue(configuration.Section.Interfaces.ContainsInterfaceType(changeDescriptor.OriginalType),
"Configuration does not contain the original interface named '{0}'".FormatWith(dataTypeId));

configuration.Section.Interfaces.Remove(changeDescriptor.OriginalType);

InterfaceConfigurationElement newInterfaceConfig = BuildInterfaceConfigurationElement(changeDescriptor.AlteredType);
InterfaceConfigurationElement newInterfaceConfig = BuildInterfaceConfigurationElement(changeDescriptor.AlteredType, oldConfigurationElement);

configuration.Section.Interfaces.Add(newInterfaceConfig);

Expand All @@ -115,7 +123,7 @@ internal static void Remove(string providerName, DataTypeDescriptor dataTypeDesc
}


private static InterfaceConfigurationElement BuildInterfaceConfigurationElement(DataTypeDescriptor dataTypeDescriptor)
private static InterfaceConfigurationElement BuildInterfaceConfigurationElement(DataTypeDescriptor dataTypeDescriptor, InterfaceConfigurationElement oldConfigurationElement)
{
var tableConfig = new InterfaceConfigurationElement();

Expand All @@ -141,9 +149,24 @@ private static InterfaceConfigurationElement BuildInterfaceConfigurationElement(
{
foreach (var culture in SqlDataProviderStoreManipulator.GetCultures(dataTypeDescriptor))
{
string tableName = DynamicTypesCommon.GenerateTableName(dataTypeDescriptor, dataScope, culture);
string tableName = null;

if (oldConfigurationElement != null)
{
tableName = oldConfigurationElement.ConfigurationStores.OfType<StoreConfigurationElement>().Where(f => f.CultureName == culture.Name && f.DataScope == dataScope.Name).Select(f => f.TableName).SingleOrDefault();
}

if (tableName == null)
{
tableName = DynamicTypesCommon.GenerateTableName(dataTypeDescriptor, dataScope, culture);
}

tableConfig.ConfigurationStores.Add(new StoreConfigurationElement
{TableName = tableName, DataScope = dataScope.Name, CultureName = culture.Name});
{
TableName = tableName,
DataScope = dataScope.Name,
CultureName = culture.Name
});
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,10 @@ public void AddLocale(CultureInfo cultureInfo)
var typeDesrciptor = DynamicTypeManager.GetDataTypeDescriptor(type);
SqlStoreManipulator.AddLocale(typeDesrciptor, cultureInfo);

InterfaceConfigurationElement newElement = InterfaceConfigurationManipulator.RefreshLocalizationInfo(_dataProviderContext.ProviderName, typeDesrciptor);
InterfaceConfigurationElement oldElement = _interfaceConfigurationElements.Where(f => f.DataTypeId == typeDesrciptor.DataTypeId).Single();

InterfaceConfigurationElement oldElement = _interfaceConfigurationElements.Where(f => f.DataTypeId == newElement.DataTypeId).Single();
InterfaceConfigurationElement newElement = InterfaceConfigurationManipulator.RefreshLocalizationInfo(_dataProviderContext.ProviderName, typeDesrciptor, oldElement);

_interfaceConfigurationElements.Remove(oldElement);
_interfaceConfigurationElements.Add(newElement);
}
Expand All @@ -530,9 +531,10 @@ public void RemoveLocale(CultureInfo cultureInfo)
var typeDesrciptor = DynamicTypeManager.GetDataTypeDescriptor(type);
SqlStoreManipulator.RemoveLocale(_dataProviderContext.ProviderName, typeDesrciptor, cultureInfo);

InterfaceConfigurationElement newElement = InterfaceConfigurationManipulator.RefreshLocalizationInfo(_dataProviderContext.ProviderName, typeDesrciptor);

InterfaceConfigurationElement oldElement = _interfaceConfigurationElements.Where(f => f.DataTypeId == newElement.DataTypeId).Single();
InterfaceConfigurationElement oldElement = _interfaceConfigurationElements.Where(f => f.DataTypeId == typeDesrciptor.DataTypeId).Single();

InterfaceConfigurationElement newElement = InterfaceConfigurationManipulator.RefreshLocalizationInfo(_dataProviderContext.ProviderName, typeDesrciptor, oldElement);

_interfaceConfigurationElements.Remove(oldElement);
_interfaceConfigurationElements.Add(newElement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ public void AlterStore(UpdateDataTypeDescriptor updateDataTypeDescriptor)
bool localizationChanged = dataTypeChangeDescriptor.AlteredType.Localizeable !=
dataTypeChangeDescriptor.OriginalType.Localizeable;

InterfaceConfigurationElement newElement = InterfaceConfigurationManipulator.Change(_dataProviderContext.ProviderName, dataTypeChangeDescriptor, localizationChanged);
InterfaceConfigurationElement oldElement = _interfaceConfigurationElements.Where(f => f.DataTypeId == updateDataTypeDescriptor.OldDataTypeDescriptor.DataTypeId).Single();

InterfaceConfigurationElement newElement = InterfaceConfigurationManipulator.Change(_dataProviderContext.ProviderName, dataTypeChangeDescriptor, localizationChanged, oldElement);
if (newElement != null)
{
InterfaceConfigurationElement oldElement = _interfaceConfigurationElements.Where(f => f.DataTypeId == newElement.DataTypeId).Single();
{
_interfaceConfigurationElements.Remove(oldElement);
_interfaceConfigurationElements.Add(newElement);
}
Expand Down

0 comments on commit f82836d

Please sign in to comment.