private void Initialize() { Stage = UpgradeMode.IsMultistage() ? UpgradeStage.Upgrading : UpgradeStage.Final; Hints = new SetSlim <UpgradeHint>(); RecycledDefinitions = new List <RecycledDefinition>(); Services = new UpgradeServiceAccessor(); }
public void SetValue(Disposable disposable) { SetSlim <IDisposable> set; if (!registry.TryGetValue(Session.Transaction, out set)) { set = new SetSlim <IDisposable>(); registry.Add(Session.Transaction, set); } set.Add(disposable); }
public void AddRemoveTest() { ISet <int> set = new SetSlim <int>(); Assert.IsTrue(set.Add(0)); Assert.IsFalse(set.Add(0)); Assert.IsTrue(set.Contains(0)); Assert.AreEqual(set.Count, 1); Assert.AreEqual(set[0], 0); Assert.IsTrue(set.Remove(0)); Assert.AreEqual(set.Count, 0); }
public void Add() { string[] strings = { "abc", "dfg", "ag", "abc" }; SetSlim <string> C = new SetSlim <string>(strings); SetSlim <int> B = new SetSlim <int>(); B.Add(1); B.Add(2); B.Add(2); B.Add(3); if (B.Count != 3 || C.Count != 3) { throw new Exception("Set.AddRange"); } }
/// <summary> /// Creates associate instance for specified parameter and result types. /// </summary> /// <typeparam name="TKey">Type to create the associate for.</typeparam> /// <typeparam name="TAssociate">Type of result to create the associate for.</typeparam> /// <param name="foundFor">The type associate was found for.</param> /// <returns>Newly created instance of associate, if found; /// otherwise, <see langword="null"/>.</returns> /// <exception cref="InvalidOperationException">Recursive associate lookup.</exception> protected virtual TAssociate CreateAssociate <TKey, TAssociate>(out Type foundFor) where TAssociate : class { if (InProgress == null) { InProgress = new SetSlim <TypePair>(); } var progressionMark = new TypePair(typeof(TKey), typeof(TAssociate)); if (InProgress.Contains(progressionMark)) { throw new InvalidOperationException(Strings.ExRecursiveAssociateLookupDetected); } InProgress.Add(progressionMark); try { var associate = TypeHelper.CreateAssociate <TAssociate>( typeof(TKey), out foundFor, TypeSuffixes, constructorParams, highPriorityLocations); return(associate); } finally { InProgress.Remove(progressionMark); } }
/// <summary> /// Compares <paramref name="sourceSchema"/> and <paramref name="targetSchema"/>. /// </summary> /// <param name="sourceSchema">The source schema.</param> /// <param name="targetSchema">The target schema.</param> /// <param name="schemaHints">The upgrade hints.</param> /// <param name="upgradeHints"><see cref="UpgradeHint"/>s to be applied.</param> /// <param name="schemaUpgradeMode">A <see cref="SchemaUpgradeMode"/> being used.</param> /// <param name="model">A <see cref="DomainModel"/> of a storage.</param> /// <param name="briefExceptionFormat">Indicates whether brief or full exception format should be used.</param> /// <param name="upgradeStage">A current <see cref="UpgradeStage"/>.</param> /// <returns>Comparison result.</returns> public static SchemaComparisonResult Compare( StorageModel sourceSchema, StorageModel targetSchema, HintSet schemaHints, SetSlim <UpgradeHint> upgradeHints, SchemaUpgradeMode schemaUpgradeMode, DomainModel model, bool briefExceptionFormat, UpgradeStage upgradeStage) { if (schemaHints == null) { schemaHints = new HintSet(sourceSchema, targetSchema); } var comparer = new Comparer(); var difference = comparer.Compare(sourceSchema, targetSchema, schemaHints); var actions = GetUpgradeActions(comparer, difference, schemaHints); var actionList = actions.Flatten().ToList(); var comparisonStatus = GetComparisonStatus(actionList, schemaUpgradeMode); var unsafeActions = GetUnsafeActions(actionList, upgradeHints); var columnTypeChangeActions = actionList.OfType <PropertyChangeAction>().Where(IsTypeChangeAction).ToList(); if (schemaUpgradeMode != SchemaUpgradeMode.ValidateLegacy) { return(new SchemaComparisonResult( comparisonStatus, columnTypeChangeActions.Count > 0, null, schemaHints, difference, actions, unsafeActions)); } // Legacy comparison var systemTablesSequence = model.Types.Where(type => type.IsSystem).Select(type => type.MappingName); var systemTables = new HashSet <string>(systemTablesSequence, Comparer); var createTableActions = actionList .OfType <CreateNodeAction>() .Where( action => { var table = action.Difference.Target as TableInfo; return(table != null && !systemTables.Contains(table.Name)); }) .ToList(); var createColumnActions = actionList .OfType <CreateNodeAction>() .Where( action => { var column = action.Difference.Target as StorageColumnInfo; return(column != null && !systemTables.Contains(column.Parent.Name)); }) .ToList(); columnTypeChangeActions = columnTypeChangeActions .Where( action => { var sourceType = action.Difference.Source as StorageTypeInfo; var targetType = action.Difference.Target as StorageTypeInfo; return(sourceType == null || targetType == null || sourceType.IsTypeUndefined || sourceType.Type.ToNullable() != targetType.Type.ToNullable()); }) .ToList(); var isCompatibleInLegacyMode = createTableActions.Count == 0 && createColumnActions.Count == 0 && columnTypeChangeActions.Count == 0; if (briefExceptionFormat) { unsafeActions = createTableActions.Cast <NodeAction>() .Concat(createColumnActions.Cast <NodeAction>()) .Concat(columnTypeChangeActions.Cast <NodeAction>()) .ToList(); } return(new SchemaComparisonResult( comparisonStatus, columnTypeChangeActions.Count > 0, isCompatibleInLegacyMode, schemaHints, difference, actions, unsafeActions)); }
private static IList <NodeAction> GetUnsafeActions(ICollection <NodeAction> actions, SetSlim <UpgradeHint> hints) { var unsafeActions = new List <NodeAction>(); GetUnsafeColumnTypeChanges(actions, hints, unsafeActions); GetUnsafeColumnRemovals(actions, hints, unsafeActions); GetUnsafeTableRemovals(actions, hints, unsafeActions); GetCrossHierarchicalMovements(actions, hints, unsafeActions); return(unsafeActions); }