/// <summary> /// Serialize to string /// </summary> /// <returns>Serialized as string</returns> public string Serialize() { IDataId dataId = EnsureDataIdType(_dataId); if ((_serializedData == null) || (dataId != _dataId)) { string s = SerializationFacade.Serialize(this.DataId); System.Text.StringBuilder sb = new System.Text.StringBuilder(); StringConversionServices.SerializeKeyValuePair(sb, "_dataId_", s); StringConversionServices.SerializeKeyValuePair(sb, "_dataIdType_", TypeManager.SerializeType(this.DataId.GetType())); if (_providerName != DataProviderRegistry.DefaultDynamicTypeDataProviderName) { StringConversionServices.SerializeKeyValuePair(sb, "_providerName_", _providerName); } StringConversionServices.SerializeKeyValuePair(sb, "_interfaceType_", TypeManager.SerializeType(_interfaceType)); StringConversionServices.SerializeKeyValuePair(sb, "_dataScope_", DataScopeIdentifier.Serialize()); StringConversionServices.SerializeKeyValuePair(sb, "_localeScope_", LocaleScope.Name); _serializedData = sb.ToString(); } return(_serializedData); }
internal static string MakeFileName(DataTypeDescriptor dataTypeDescriptor, DataScopeIdentifier dataScopeIdentifier, string cultureName) { string typeFullName = StringExtensionMethods.CreateNamespace(dataTypeDescriptor.Namespace, dataTypeDescriptor.Name, '.'); string publicationScopePart = ""; switch (dataScopeIdentifier.Name) { case DataScopeIdentifier.PublicName: break; case DataScopeIdentifier.AdministratedName: publicationScopePart = "_" + PublicationScope.Unpublished; break; default: throw new InvalidOperationException("Unsupported data scope identifier: '{0}'".FormatWith(dataScopeIdentifier.Name)); } string cultureNamePart = ""; if (cultureName != "") { cultureNamePart = "_" + cultureName; } return typeFullName + publicationScopePart + cultureNamePart + ".xml"; }
private void CreateScopeData(DataTypeDescriptor typeDescriptor, DataScopeIdentifier dataScope) { foreach (var cultureInfo in GetCultures(typeDescriptor)) { CreateStore(typeDescriptor, dataScope, cultureInfo); } }
/// <summary> /// This is for internal use only! /// </summary> public DataSourceId(IDataId dataId, string providerName, Type interfaceType, DataScopeIdentifier dataScope, CultureInfo localeScope) { // This constructor has to be extremely fast, we have up to 100.000 objects related while some requests if (dataId == null) { throw new ArgumentNullException("dataId"); } if (string.IsNullOrEmpty(providerName)) { throw new ArgumentNullException("providerName"); } if (interfaceType == null) { throw new ArgumentNullException("interfaceType"); } if (dataScope == null) { throw new ArgumentNullException("dataScope"); } if (localeScope == null) { throw new ArgumentNullException("localeScope"); } this.DataId = dataId; ProviderName = providerName; InterfaceType = interfaceType; _dataScopeIdentifier = dataScope; _localeScope = localeScope; this.ExistsInStore = true; }
/// <exclude /> public bool IsPendingForDeletionData(Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale, DataKeyPropertyCollection dataKeyPropertyCollection) { Verify.ArgumentNotNull(interfaceType, "interfaceType"); Verify.ArgumentNotNull(dataScopeIdentifier, "dataScopeIdentifier"); Verify.ArgumentNotNull(dataKeyPropertyCollection, "dataKeyPropertyCollection"); List<DataKeyPropertyCollection> dataKeyPropertyCollections = GetDataKeyPropertyCollection(interfaceType, dataScopeIdentifier, locale); return dataKeyPropertyCollections.Contains(dataKeyPropertyCollection); }
/// <summary> /// This is for internal use only! /// </summary> public DataSourceId(IDataId dataId, string providerName, Type interfaceType) { if (null == dataId) throw new ArgumentNullException("dataId"); if (string.IsNullOrEmpty(providerName)) throw new ArgumentNullException("providerName"); if (null == interfaceType) throw new ArgumentNullException("interfaceType"); this.DataId = dataId; _providerName = providerName; _interfaceType = interfaceType; _dataScopeIdentifier = DataScopeManager.MapByType(interfaceType); _localeScope = LocalizationScopeManager.MapByType(interfaceType); this.ExistsInStore = true; }
/// <exclude /> public static IEnumerable <IData> GetMetaData(this IPage page, DataScopeIdentifier dataScopeIdentifier) { using (new DataScope(dataScopeIdentifier)) { foreach (IPageMetaDataDefinition pageMetaDataDefinition in page.GetAllowedMetaDataDefinitions()) { IData data = page.GetMetaData(pageMetaDataDefinition.Name, pageMetaDataDefinition.MetaDataTypeId); if (data != null) { yield return(data); } } } }
/// <exclude /> public static DataScopeIdentifier MapByType(Type interfaceType) { if (interfaceType == null) { throw new ArgumentNullException("interfaceType"); } var currentScope = CurrentDataScope; if (DataFacade.GetSupportedDataScopes(interfaceType).Any(f => f.Equals(currentScope))) { return(currentScope); } return(DataScopeIdentifier.GetDefault()); }
/// <exclude /> public void AddPendingForDeletionData(Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale, DataKeyPropertyCollection dataKeyPropertyCollection) { Verify.ArgumentNotNull(interfaceType, "interfaceType"); Verify.ArgumentNotNull(dataScopeIdentifier, "dataScopeIdentifier"); Verify.ArgumentNotNull(dataKeyPropertyCollection, "dataKeyPropertyCollection"); List<DataKeyPropertyCollection> dataKeyPropertyCollections = GetDataKeyPropertyCollection(interfaceType, dataScopeIdentifier, locale); if (dataKeyPropertyCollections.Contains(dataKeyPropertyCollection)) { throw new ArgumentException(string.Format("The data item of type '{0}' with the key '{1}' has already been added", interfaceType, dataKeyPropertyCollection)); } dataKeyPropertyCollections.Add(dataKeyPropertyCollection); }
/// <summary> /// This is for internal use only! /// </summary> public DataSourceId(IDataId dataId, string providerName, Type interfaceType, DataScopeIdentifier dataScope, CultureInfo localeScope) { // This constructor has to be extremely fast, we have up to 100.000 objects reated while some requests if (dataId == null) throw new ArgumentNullException("dataId"); if (string.IsNullOrEmpty(providerName)) throw new ArgumentNullException("providerName"); if (interfaceType == null) throw new ArgumentNullException("interfaceType"); if (dataScope == null) throw new ArgumentNullException("dataScope"); if (localeScope == null) throw new ArgumentNullException("localeScope"); this.DataId = dataId; _providerName = providerName; _interfaceType = interfaceType; _dataScopeIdentifier = dataScope; _localeScope = localeScope; this.ExistsInStore = true; }
/// <summary> /// /// </summary> /// <param name="dataScope"></param> /// <param name="cultureInfo">null for default culture</param> public DataScope(DataScopeIdentifier dataScope, CultureInfo cultureInfo) { DataScopeManager.PushDataScope(dataScope); _dataScopePushed = true; if (cultureInfo != null) { LocalizationScopeManager.PushLocalizationScope(cultureInfo); _cultureInfoPushed = true; } else if (LocalizationScopeManager.IsEmpty) { LocalizationScopeManager.PushLocalizationScope(DataLocalizationFacade.DefaultLocalizationCulture); _cultureInfoPushed = true; } }
/// <summary> /// /// </summary> /// <param name="dataScope"></param> /// <param name="cultureInfo">null for default culture</param> public DataScope(DataScopeIdentifier dataScope, CultureInfo cultureInfo) { DataScopeManager.PushDataScope(dataScope); _dataScopePushed = true; if (cultureInfo != null) { LocalizationScopeManager.PushLocalizationScope(cultureInfo); _cultureInfoPushed = true; } else if (LocalizationScopeManager.IsEmpty) { LocalizationScopeManager.PushLocalizationScope(DataLocalizationFacade.DefaultLocalizationCulture); _cultureInfoPushed = true; } }
internal void CreateStore(DataTypeDescriptor typeDescriptor, DataScopeIdentifier dataScope, CultureInfo cultureInfo, Action<string> existingTablesValidator = null) { string tableName = DynamicTypesCommon.GenerateTableName(typeDescriptor, dataScope, cultureInfo); var tables = GetTablesList(); if (tables.Contains(tableName)) { if (existingTablesValidator != null) { existingTablesValidator(tableName); return; } throw new InvalidOperationException("Database already contains a table named {0}".FormatWith(tableName)); } var sql = new StringBuilder(); var sqlColumns = typeDescriptor.Fields.Select(fieldDescriptor => GetColumnInfo(tableName, fieldDescriptor.Name, fieldDescriptor, true, false) ).ToList(); sql.AppendFormat("CREATE TABLE dbo.[{0}]({1});", tableName, string.Join(",", sqlColumns)); sql.Append(SetPrimaryKey(tableName, typeDescriptor.PhysicalKeyPropertyNames, typeDescriptor.PrimaryKeyIsClusteredIndex)); try { ExecuteNonQuery(sql.ToString()); } catch (Exception ex) { throw MakeVerboseException(ex); } foreach (var index in typeDescriptor.Indexes) { CreateIndex(tableName, index); } SqlTableInformationStore.ClearCache(_connectionString, tableName); }
internal static string GenerateTableName(DataTypeDescriptor dataTypeDescriptor, DataScopeIdentifier dataScope, CultureInfo cultureInfo) { string tableName = dataTypeDescriptor.GetFullInterfaceName().Replace('.', '_'); switch (dataScope.Name) { case DataScopeIdentifier.PublicName: break; case DataScopeIdentifier.AdministratedName: tableName += "_Unpublished"; break; default: throw new InvalidOperationException("Unsupported data scope identifier: '{0}'".FormatWith(dataScope.Name)); } if (!cultureInfo.Name.IsNullOrEmpty()) { tableName += "_" + cultureInfo.Name.Replace('-', '_').Replace(' ', '_'); } return tableName; }
/// <summary> /// This is for internal use only! /// </summary> public DataSourceId(IDataId dataId, string providerName, Type interfaceType) { if (null == dataId) { throw new ArgumentNullException("dataId"); } if (string.IsNullOrEmpty(providerName)) { throw new ArgumentNullException("providerName"); } if (null == interfaceType) { throw new ArgumentNullException("interfaceType"); } this.DataId = dataId; ProviderName = providerName; InterfaceType = interfaceType; _dataScopeIdentifier = DataScopeManager.MapByType(interfaceType); _localeScope = LocalizationScopeManager.MapByType(interfaceType); this.ExistsInStore = true; }
internal static void PushDataScope(DataScopeIdentifier dataScope) { DataScopeStack.Push(dataScope); }
private static void IncrementVersion(DataScopeIdentifier dataScopeIdentifier) { var publicationScope = dataScopeIdentifier.ToPublicationScope(); ClearCachedData(key => key.Item1 == publicationScope); }
private bool KeyRegistered(DataScopeIdentifier publicationScope, string languageName, KeyValuePair<string, object> keyValuePair) { HashSet<KeyValuePair<string, object>> hashset; if (languageName != AllLocalesKey && _isLocalized) { hashset = GetDataset(publicationScope, languageName); if (hashset != null && hashset.Contains(keyValuePair)) { return true; } } hashset = GetDataset(publicationScope, AllLocalesKey); return hashset != null && hashset.Contains(keyValuePair); }
private static bool Deserialize(string serializedDataSourceId, out DataSourceId dataSourceId, bool throwException) { dataSourceId = null; Dictionary <string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedDataSourceId); if ((dic.ContainsKey("_dataIdType_") == false) || (dic.ContainsKey("_dataId_") == false) || (dic.ContainsKey("_interfaceType_") == false) || (dic.ContainsKey("_dataScope_") == false) || (dic.ContainsKey("_localeScope_") == false)) { if (throwException) { throw new ArgumentException("The serializedDataSourceId is not a serialized data source id", "serializedDataSourceId"); } else { return(false); } } string serializedDataId = StringConversionServices.DeserializeValueString(dic["_dataId_"]); string dataIdType = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]); string providerName; if (dic.ContainsKey("_providerName_")) { providerName = StringConversionServices.DeserializeValueString(dic["_providerName_"]); } else { providerName = DataProviderRegistry.DefaultDynamicTypeDataProviderName; } string interfaceTypeName = StringConversionServices.DeserializeValueString(dic["_interfaceType_"]); string dataScope = StringConversionServices.DeserializeValueString(dic["_dataScope_"]); string localeScope = StringConversionServices.DeserializeValueString(dic["_localeScope_"]); Type type = TypeManager.TryGetType(dataIdType); if (type == null) { if (throwException) { throw new InvalidOperationException(string.Format("The type {0} could not be found", dataIdType)); } return(false); } IDataId dataId = SerializationFacade.Deserialize <IDataId>(type, serializedDataId); Type interfaceType = TypeManager.TryGetType(interfaceTypeName); if (interfaceType == null) { if (throwException) { throw new InvalidOperationException(string.Format("The type {0} could not be found", interfaceType)); } return(false); } CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(localeScope); dataSourceId = new DataSourceId(dataId, providerName, interfaceType, DataScopeIdentifier.Deserialize(dataScope), cultureInfo); return(true); }
private string GetConfiguredTableName(DataTypeDescriptor dataTypeDescriptor, DataScopeIdentifier dataScope, string cultureName) { var stores = (from dataInterface in _generatedInterfaces where dataInterface.DataTypeId == dataTypeDescriptor.DataTypeId select dataInterface.Stores).FirstOrDefault(); if (stores == null) { return null; } var tableName = (from store in stores where store.CultureName == cultureName && store.DataScope == dataScope.Name select store.TableName).FirstOrDefault(); return tableName; }
private string GetDataScopeKey(DataScopeIdentifier publicationScope, string languageName) { string publicationScopeKey = _isPublishable ? publicationScope.Name : string.Empty; string languageScopeKey = _isLocalized ? languageName : string.Empty; return publicationScopeKey + languageScopeKey; }
private void AlterScopeData(UpdateDataTypeDescriptor updateDataTypeDescriptor, DataTypeChangeDescriptor changeDescriptor, DataScopeIdentifier dataScope) { var culturesToDelete = new List<CultureInfo>(); var culturesToChange = new List<CultureInfo>(); var oldCultures = GetCultures(changeDescriptor.OriginalType).Evaluate(); var newCultures = GetCultures(changeDescriptor.AlteredType).Evaluate(); foreach (var culture in oldCultures) { if (newCultures.Contains(culture)) { culturesToChange.Add(culture); } else { culturesToDelete.Add(culture); } } var culturesToAdd = newCultures.Where(culture => !oldCultures.Contains(culture)).ToList(); culturesToAdd.ForEach(culture => CreateStore(changeDescriptor.AlteredType, dataScope, culture)); culturesToChange.ForEach(culture => AlterStore(updateDataTypeDescriptor, changeDescriptor, dataScope, culture)); if (updateDataTypeDescriptor.LocalesToCopyTo != null) { StringBuilder fieldList = GetCommonFields(changeDescriptor); string fromTableName = GetConfiguredTableName(changeDescriptor.OriginalType, dataScope, ""); foreach (CultureInfo locale in updateDataTypeDescriptor.LocalesToCopyTo) { string toTableName = DynamicTypesCommon.GenerateTableName(changeDescriptor.AlteredType, dataScope, locale); string copyCommandText = string.Format(@" INSERT INTO [{0}] ({2}) SELECT {2} FROM [{1}];", toTableName, fromTableName, fieldList); ExecuteNonQuery(copyCommandText); string updateCommandText = string.Format("UPDATE [{0}] SET [{1}] = '{2}'", toTableName, "SourceCultureName", locale.Name); ExecuteNonQuery(updateCommandText); } string removeCommandText = string.Format(@"DELETE FROM [{0}];", fromTableName); ExecuteNonQuery(removeCommandText); } if (updateDataTypeDescriptor.LocaleToCopyFrom != null) { StringBuilder fieldList = GetCommonFields(changeDescriptor); string fromTableName = GetConfiguredTableName(changeDescriptor.OriginalType, dataScope, updateDataTypeDescriptor.LocaleToCopyFrom.Name); string toTableName = DynamicTypesCommon.GenerateTableName(changeDescriptor.AlteredType, dataScope, CultureInfo.InvariantCulture); string copyCommandText = string.Format(@" INSERT INTO [{0}] ({2}) SELECT {2} FROM [{1}];", toTableName, fromTableName, fieldList); ExecuteNonQuery(copyCommandText); } culturesToDelete.ForEach(culture => DropStore(changeDescriptor.OriginalType, dataScope, culture)); }
private void CheckForPotentialBrokenReferences(IData data, List<PackageFragmentValidationResult> validationResult, Type type, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale, DataKeyPropertyCollection dataKeyPropertyCollection) { var pagesReferencingPageTypes = new HashSet<string>(); var dataReferencingDataToBeUninstalled = new HashSet<string>(); List<IData> referees = data.GetReferees(); bool addToDelete = true; foreach (IData referee in referees) { if (this.UninstallerContext.IsPendingForDeletionData(referee)) { continue; } addToDelete = false; if (referee is IPage && data is IPageType) { string pathToPage; using (new DataScope(referee.DataSourceId.PublicationScope, referee.DataSourceId.LocaleScope)) { pathToPage = GetPathToPage(referee as IPage); } if (!pagesReferencingPageTypes.Contains(pathToPage)) { validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_PageTypeIsReferenced( data.GetLabel(), pathToPage)); pagesReferencingPageTypes.Add(pathToPage); } } else { var refereeType = referee.DataSourceId.InterfaceType; string label = referee.GetLabel(); string key = label + refereeType.FullName; if (!dataReferencingDataToBeUninstalled.Contains(key)) { validationResult.AddFatal(Texts.DataPackageFragmentUninstaller_DataIsReferenced( data.GetLabel(), type.FullName, label, refereeType.FullName)); dataReferencingDataToBeUninstalled.Add(key); } } } if (addToDelete) { AddDataToDelete(type, dataScopeIdentifier, locale, dataKeyPropertyCollection); } }
private static bool Deserialize(string serializedDataSourceId, out DataSourceId dataSourceId, bool throwException) { dataSourceId = null; var dic = StringConversionServices.ParseKeyValueCollection(serializedDataSourceId); if (!dic.ContainsKey("_dataIdType_") || !dic.ContainsKey("_dataId_") || !dic.ContainsKey("_interfaceType_") || !dic.ContainsKey("_dataScope_") || !dic.ContainsKey("_localeScope_")) { if (throwException) { throw new ArgumentException("The argument is not a serialized " + nameof(DataSourceId), nameof(serializedDataSourceId)); } return(false); } string serializedDataId = StringConversionServices.DeserializeValueString(dic["_dataId_"]); string dataIdTypeName = StringConversionServices.DeserializeValueString(dic["_dataIdType_"]); string providerName = dic.ContainsKey("_providerName_") ? StringConversionServices.DeserializeValueString(dic["_providerName_"]) : DataProviderRegistry.DefaultDynamicTypeDataProviderName; string interfaceTypeName = StringConversionServices.DeserializeValueString(dic["_interfaceType_"]); string dataScope = StringConversionServices.DeserializeValueString(dic["_dataScope_"]); string localeScope = StringConversionServices.DeserializeValueString(dic["_localeScope_"]); Type interfaceType = TypeManager.TryGetType(interfaceTypeName); if (interfaceType == null) { if (throwException) { throw new InvalidOperationException($"The type '{interfaceTypeName}' could not be found"); } return(false); } Type dataIdType = TypeManager.TryGetType(dataIdTypeName); if (dataIdType == null) { if (throwException) { throw new InvalidOperationException($"The type '{dataIdTypeName}' could not be found"); } return(false); } serializedDataId = FixSerializedDataId(serializedDataId, interfaceType); IDataId dataId = SerializationFacade.Deserialize <IDataId>(dataIdType, serializedDataId); CultureInfo cultureInfo = CultureInfo.CreateSpecificCulture(localeScope); dataSourceId = new DataSourceId(dataId, providerName, interfaceType, DataScopeIdentifier.Deserialize(dataScope), cultureInfo); return(true); }
/// <exclude /> public static IEnumerable<IData> GetMetaData(this IPage page, DataScopeIdentifier dataScopeIdentifier) { using (new DataScope(dataScopeIdentifier)) { foreach (IPageMetaDataDefinition pageMetaDataDefinition in page.GetAllowedMetaDataDefinitions()) { IData data = page.GetMetaData(pageMetaDataDefinition.Name, pageMetaDataDefinition.MetaDataTypeId); if (data != null) { yield return data; } } } }
private DataSourceId(IDataId dataId, string providerName, Type interfaceType, DataScopeIdentifier dataScopeIdentifier, string localeScope) { // This constructor has to be extremely fast, we have up to 100.000 objects related while some requests this.DataId = dataId ?? throw new ArgumentNullException(nameof(dataId)); ProviderName = providerName ?? DataProviderRegistry.DefaultDynamicTypeDataProviderName; InterfaceType = interfaceType ?? throw new ArgumentNullException(nameof(interfaceType)); DataScopeIdentifier = dataScopeIdentifier ?? throw new ArgumentNullException(nameof(dataScopeIdentifier)); LocaleScope = CultureInfo.CreateSpecificCulture(localeScope); this.ExistsInStore = true; }
/// <exclude /> public override int GetHashCode() => DataId.GetHashCode() ^ InterfaceType.GetHashCode() ^ ProviderName.GetHashCode() ^ DataScopeIdentifier.GetHashCode() ^ LocaleScope.GetHashCode();
internal DataMoveEventArgs(Type dataType, IData data, DataScopeIdentifier targetDataScopeIdentifier) : base(dataType, data) { this.TargetDataScopeIdentifier = targetDataScopeIdentifier; }
/// <exclude /> public DataScope(DataScopeIdentifier dataScope) : this(dataScope, null) { }
private void DropScopeData(DataTypeDescriptor typeDescriptor, DataScopeIdentifier dataScope) { foreach (var culture in GetCultures(typeDescriptor)) { DropStore(typeDescriptor, dataScope, culture); } }
/// <exclude /> public bool Equals(DataScopeIdentifier dataScope) { return(!ReferenceEquals(dataScope, null) && this.Name == dataScope.Name); }
private void AddDataToDelete(Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale, DataKeyPropertyCollection dataKeyPropertyCollection) { DataType dataType = _dataToDelete.SingleOrDefault(dt => dt.InterfaceType == interfaceType && dt.DataScopeIdentifier.Equals(dataScopeIdentifier) && ((dt.Locale == null && locale == null) || (dt.Locale != null && dt.Locale.Equals(locale)))); if (dataType == null) { dataType = new DataType { InterfaceType = interfaceType, DataScopeIdentifier = dataScopeIdentifier, Locale = locale }; _dataToDelete.Add(dataType); } dataType.DataKeys.Add(dataKeyPropertyCollection); this.UninstallerContext.AddPendingForDeletionData(interfaceType, dataScopeIdentifier, locale, dataKeyPropertyCollection); }
/// <exclude /> public bool Equals(DataScopeIdentifier dataScope) { return !ReferenceEquals(dataScope, null) && this.Name == dataScope.Name; }
/// <exclude /> public DataScope(DataScopeIdentifier dataScope) : this(dataScope, null) { }
private void AlterStore(UpdateDataTypeDescriptor updateDataTypeDescriptor, DataTypeChangeDescriptor changeDescriptor, DataScopeIdentifier dataScope, CultureInfo culture) { try { string originalTableName = GetConfiguredTableName(changeDescriptor.OriginalType, dataScope, culture.Name); string alteredTableName = originalTableName; // This could be done more nicely! But only give the table a new name if the type has changed its name and not because we changed the naming scheme if (updateDataTypeDescriptor.OldDataTypeDescriptor.Name != updateDataTypeDescriptor.NewDataTypeDescriptor.Name || updateDataTypeDescriptor.OldDataTypeDescriptor.Namespace != updateDataTypeDescriptor.NewDataTypeDescriptor.Namespace) { alteredTableName = DynamicTypesCommon.GenerateTableName(changeDescriptor.AlteredType, dataScope, culture); } var tables = GetTablesList(); if (!tables.Contains(originalTableName)) { throw new InvalidOperationException( string.Format( "Unable to alter data type store. The database does not contain expected table {0}", originalTableName)); } bool primaryKeyChanged = changeDescriptor.AddedKeyFields.Any() || changeDescriptor.DeletedKeyFields.Any() || changeDescriptor.KeyFieldsOrderChanged || changeDescriptor.OriginalType.PrimaryKeyIsClusteredIndex != changeDescriptor.AlteredType.PrimaryKeyIsClusteredIndex; DropConstraints(originalTableName, primaryKeyChanged); if (originalTableName != alteredTableName) { if (tables.Contains(alteredTableName)) throw new InvalidOperationException( string.Format("Can not rename table to {0}. A table with that name already exists", alteredTableName)); RenameTable(originalTableName, alteredTableName); } var newIndexes = changeDescriptor.AlteredType.Indexes.Select(i => i.ToString()).ToList(); foreach (var oldIndex in changeDescriptor.OriginalType.Indexes) { if (!newIndexes.Contains(oldIndex.ToString())) { DropIndex(alteredTableName, oldIndex); } } DropFields(alteredTableName, changeDescriptor.DeletedFields, changeDescriptor.OriginalType.Fields); ImplementFieldChanges(alteredTableName, changeDescriptor.ExistingFields); Dictionary<string, object> defaultValues = null; if (updateDataTypeDescriptor.PublicationAdded) { defaultValues = new Dictionary<string, object> { {"PublicationStatus", GenericPublishProcessController.Draft} }; } AppendFields(alteredTableName, changeDescriptor, changeDescriptor.AddedFields, defaultValues); // Clustered index has to be created first. var createIndexActions = new List<Tuple<bool, Action>>(); if (primaryKeyChanged) { bool isClusteredIndex = changeDescriptor.AlteredType.PrimaryKeyIsClusteredIndex; createIndexActions.Add(new Tuple<bool, Action>(isClusteredIndex, () => ExecuteNonQuery(SetPrimaryKey(alteredTableName, changeDescriptor.AlteredType.PhysicalKeyPropertyNames, isClusteredIndex)) )); } var oldIndexes = changeDescriptor.OriginalType.Indexes.Select(i => i.ToString()).ToList(); foreach (var newIndex in changeDescriptor.AlteredType.Indexes) { if (!oldIndexes.Contains(newIndex.ToString())) { var index = newIndex; createIndexActions.Add(new Tuple<bool, Action>(newIndex.Clustered, () => CreateIndex(alteredTableName, index))); } } createIndexActions.Sort((a, b) => b.Item1.CompareTo(a.Item1)); foreach (var createIndex in createIndexActions) { createIndex.Item2(); } SqlTableInformationStore.ClearCache(_connectionString, originalTableName); SqlTableInformationStore.ClearCache(_connectionString, alteredTableName); } catch (Exception ex) { throw MakeVerboseException(ex); } }
/// <exclude /> public DataScope(PublicationScope publicationScope) : this(DataScopeIdentifier.FromPublicationScope(publicationScope), null) { }
private void DropStore(DataTypeDescriptor dataTypeDescriptor, DataScopeIdentifier dataScope, CultureInfo cultureInfo) { string tableName = GetConfiguredTableName(dataTypeDescriptor, dataScope, cultureInfo.Name); if (string.IsNullOrEmpty(tableName)) { return; } try { var tables = GetTablesList(); if (tables.Contains(tableName)) { ExecuteNonQuery(string.Format("DROP TABLE [{0}];", tableName)); SqlTableInformationStore.ClearCache(_connectionString, tableName); } } catch (Exception ex) { throw MakeVerboseException(ex); } }
private List<DataKeyPropertyCollection> GetDataKeyPropertyCollection(Type interfaceType, DataScopeIdentifier dataScopeIdentifier, CultureInfo locale) { if (locale == null) { locale = CultureInfo.InvariantCulture; } return _dataPendingForDeletion .GetOrAdd(interfaceType, () => new Dictionary<DataScopeIdentifier, Dictionary<CultureInfo, List<DataKeyPropertyCollection>>>()) .GetOrAdd(dataScopeIdentifier, () => new Dictionary<CultureInfo, List<DataKeyPropertyCollection>>()) .GetOrAdd(locale, () => new List<DataKeyPropertyCollection>()); }
internal static void PushDataScope(DataScopeIdentifier dataScope) { DataScopeStack.Push(dataScope); }
/// <summary> /// /// </summary> /// <param name="publicationScope">Publication scope</param> /// <param name="cultureInfo">null for default culture</param> public DataScope(PublicationScope publicationScope, CultureInfo cultureInfo) : this(DataScopeIdentifier.FromPublicationScope(publicationScope), cultureInfo) { }
private HashSet<KeyValuePair<string, object>> GetDataset(DataScopeIdentifier publicationScope, string localizationScope) { string key = GetDataScopeKey(publicationScope, localizationScope); return _dataScopes.ContainsKey(key) ? _dataScopes[key] : null; }
public XmlDataTypeStoreDataScope GetDataScope(DataScopeIdentifier dataScope, CultureInfo culture, Type type) { string dataScopeName = dataScope.Name; Verify.That(HasDataScopeName(dataScope), "The store named '{0}' is not supported for data type '{1}'", dataScopeName, type); string cultureName = culture.Name; XmlDataTypeStoreDataScope dateTypeStoreDataScope = _xmlDateTypeStoreDataScopes.SingleOrDefault(f => f.DataScopeName == dataScopeName && f.CultureName == cultureName); if (dateTypeStoreDataScope == null) { if (culture.Equals(CultureInfo.InvariantCulture) && DataLocalizationFacade.IsLocalized(type)) { throw new InvalidOperationException("Failed to get data for type '{0}', no localization scope is provided for a localized type." .FormatWith(type.FullName)); } throw new InvalidOperationException("Failed to get '{0}' data for data scope ({1}, {2})" .FormatWith(type.FullName, dataScopeName, culture.Equals(CultureInfo.InvariantCulture) ? "invariant" : cultureName)); } return dateTypeStoreDataScope; }
private void RegisterKeyUsage(DataType dataType, string localeName, DataScopeIdentifier publicationScope, KeyValuePair<string, object> keyValuePair) { string dataScopeKey = GetDataScopeKey(publicationScope, localeName); if (!_dataScopes.ContainsKey(dataScopeKey)) { _dataScopes.Add(dataScopeKey, new HashSet<KeyValuePair<string, object>>()); } var hashset = _dataScopes[dataScopeKey]; Verify.That(!hashset.Contains(keyValuePair), "Item with the same key present twice. Data type: '{0}', field '{1}', value '{2}'", dataType.InterfaceTypeName ?? "null", keyValuePair.Key, keyValuePair.Value ?? "null"); hashset.Add(keyValuePair); }
public bool HasDataScopeName(DataScopeIdentifier dataScopeIdentifier) { return _xmlDateTypeStoreDataScopes.Any(f => f.DataScopeName == dataScopeIdentifier.Name); }