protected override TreeViewItem BuildRoot() { Debug.Assert(m_PrefabInstanceRoot != null, "We should always have a valid apply target"); // Inner prefab asset root. m_AllModifications = GetPrefabOverrides(m_PrefabInstanceRoot, false); Dictionary <int, PrefabOverrides> instanceIDToPrefabOverridesMap; BuildPrefabOverridesPerObject(out instanceIDToPrefabOverridesMap); var hiddenRoot = new TreeViewItem { id = 0, depth = -1, displayName = "Hidden Root" }; var idSequence = new IdSequence(); hasModifications = AddTreeViewItemRecursive(hiddenRoot, m_PrefabInstanceRoot, instanceIDToPrefabOverridesMap, idSequence); if (!hasModifications) { hiddenRoot.AddChild(new TreeViewItem { id = 1, depth = 0, displayName = "No Overrides" }); } if (m_Debug) { AddDebugItems(hiddenRoot, idSequence); } return(hiddenRoot); }
private void Apply(StudentCreatedEvent evt) { // Only set defaults here. registrationSequence = new IdSequence(0); hasGraduated = false; credits = 0; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldToStringBothUsedAndUnusedDynamicLabelRecords() public virtual void ShouldToStringBothUsedAndUnusedDynamicLabelRecords() { // GIVEN IdSequence ids = mock(typeof(IdSequence)); when(ids.NextId()).thenReturn(1L, 2L); ReusableRecordsAllocator recordAllocator = new ReusableRecordsAllocator(30, new DynamicRecord(1), new DynamicRecord(2)); NodeRecord node = NewUsedNodeRecord(0); long labelId = 10_123; // A dynamic label record ICollection <DynamicRecord> existing = allocateRecordsForDynamicLabels(node.Id, new long[] { labelId }, recordAllocator); // and a deleted one as well (simulating some deleted labels) DynamicRecord unused = NewDeletedDynamicRecord(ids.NextId()); unused.InUse = false; existing.Add(unused); node.SetLabelField(dynamicPointer(existing), existing); // WHEN string toString = node.ToString(); // THEN assertThat(toString, containsString(labelId.ToString())); assertThat(toString, containsString(unused.ToString())); }
internal PropertyCreator(DynamicRecordAllocator stringRecordAllocator, DynamicRecordAllocator arrayRecordAllocator, IdSequence propertyRecordIdGenerator, PropertyTraverser traverser, bool allowStorePointsAndTemporal) { this._stringRecordAllocator = stringRecordAllocator; this._arrayRecordAllocator = arrayRecordAllocator; this._propertyRecordIdGenerator = propertyRecordIdGenerator; this._traverser = traverser; this._allowStorePointsAndTemporal = allowStorePointsAndTemporal; }
public MessageLayer(ILayer lowerLayer, ITransmissionContextFactory transmissionContextFactory) : base(lowerLayer) { _transmissionContextFactory = transmissionContextFactory; _retransmissions = new Dictionary<int, ITransmissionContext>(); _idSequence = new IdSequence(); _replyCache = new MessageCache(); _duplicationCache = new MessageCache(); }
public MessageLayer(ILayer lowerLayer, ITransmissionContextFactory transmissionContextFactory) : base(lowerLayer) { _transmissionContextFactory = transmissionContextFactory; _retransmissions = new Dictionary <int, ITransmissionContext>(); _idSequence = new IdSequence(); _replyCache = new MessageCache(); _duplicationCache = new MessageCache(); }
public override void Close() { foreach (StoreType type in StoreType.values()) { IdSequence generator = IdGenerator(type); if (generator is RenewableBatchIdSequence) { (( RenewableBatchIdSequence )generator).Close(); } } }
public Student(string firstName, string lastName) { CorrectName(firstName, lastName); registrations = new HashedSet <Registration>(); passedClasses = new HashedSet <Guid>(); failedClasses = new HashedSet <Guid>(); registrationSequence = new IdSequence(0); credits = 0; HasGraduated = false; }
protected override TreeViewItem BuildRoot() { Debug.Assert(m_PrefabInstanceRoot != null, "We should always have a valid apply target"); // Inner prefab asset root. m_AllModifications = GetPrefabOverrides(m_PrefabInstanceRoot, false); Dictionary <int, PrefabOverrides> instanceIDToPrefabOverridesMap; BuildPrefabOverridesPerObject(out instanceIDToPrefabOverridesMap); var hiddenRoot = new TreeViewItem { id = 0, depth = -1, displayName = "Hidden Root" }; var idSequence = new IdSequence(); hasApplicableModifications = false; hasModifications = AddTreeViewItemRecursive(hiddenRoot, m_PrefabInstanceRoot, instanceIDToPrefabOverridesMap, idSequence); if (!hasModifications) { hiddenRoot.AddChild(new TreeViewItem { id = 1, depth = 0, displayName = "No Overrides" }); } else { bool CanAnyPropertiesBeApplied() { if (m_AllModifications.addedComponents.Count != 0 || m_AllModifications.removedComponents.Count != 0 || m_AllModifications.addedGameObjects.Count != 0) { return(true); } foreach (var objectOverride in m_AllModifications.objectOverrides) { if (PrefabUtility.HasApplicableObjectOverrides(objectOverride.instanceObject, false)) { return(true); } } return(false); } hasApplicableModifications = CanAnyPropertiesBeApplied(); } if (m_Debug) { AddDebugItems(hiddenRoot, idSequence); } return(hiddenRoot); }
public override long NextId() { Debug.Assert(!_closed); long id; while (_currentBatch == null || (id = _currentBatch.nextId()) == VALUE_REPRESENTING_NULL) { _currentBatch = _source.nextIdBatch(_batchSize).GetEnumerator(); } return(id); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldContinueThroughEmptyIdBatch() public virtual void ShouldContinueThroughEmptyIdBatch() { // given IdSequence idSource = mock(typeof(IdSequence)); IEnumerator <IdRange> ranges = asList(new IdRange(EMPTY_LONG_ARRAY, 0, BATCH_SIZE), new IdRange(EMPTY_LONG_ARRAY, BATCH_SIZE, 0), new IdRange(EMPTY_LONG_ARRAY, BATCH_SIZE, BATCH_SIZE)).GetEnumerator(); //JAVA TO C# CONVERTER TODO TASK: Java iterators are only converted within the context of 'while' and 'for' loops: when(idSource.NextIdBatch(anyInt())).thenAnswer(invocation => ranges.next()); RenewableBatchIdSequence ids = new RenewableBatchIdSequence(idSource, BATCH_SIZE, _excessIds.add); // when/then for (long expectedId = 0; expectedId < BATCH_SIZE * 2; expectedId++) { assertEquals(expectedId, ids.NextId()); } }
/// <summary> /// Even if instances are meant to be accessed by a single thread at a time, lifecycle calls /// can guard for it nonetheless. Only the first call to close will perform close. /// </summary> public override void Close() { lock (this) { if (!_closed && _currentBatch != null) { long id; while ((id = _currentBatch.nextId()) != VALUE_REPRESENTING_NULL) { _excessIdConsumer.accept(id); } _currentBatch = null; } _closed = true; } }
public virtual void RegisterTo(Class @class) { // Business rules @class.Validation().NotNull("class"); if (registrations.Where(x => x.Class.Id == @class.Id).Count() > 0) { throw new InvalidOperationException("You can not register a student to a class he already registered"); } if (passedClasses.Where(x => x == @class.Id).Count() > 0) { throw new InvalidOperationException("You can not register a student to a class he already passed"); } // State changes registrationSequence = registrationSequence.Next(); registrations.Add(new Registration(this, registrationSequence.ToId(), @class)); }
void AddDebugItems(TreeViewItem hiddenRoot, IdSequence idSequence) { var debugItem = new TreeViewItem(idSequence.get(), 0, "<Debug raw list of modifications>"); foreach (var mod in m_AllModifications.addedGameObjects) { debugItem.AddChild(new TreeViewItem(idSequence.get(), debugItem.depth + 1, mod.instanceGameObject.name + " (Added GameObject)")); } foreach (var mod in m_AllModifications.addedComponents) { debugItem.AddChild(new TreeViewItem(idSequence.get(), debugItem.depth + 1, mod.instanceComponent.GetType() + " (Added Component)")); } foreach (var mod in m_AllModifications.removedComponents) { debugItem.AddChild(new TreeViewItem(idSequence.get(), debugItem.depth + 1, mod.assetComponent.GetType() + " (Removed Component)")); } hiddenRoot.AddChild(new TreeViewItem()); // spacer hiddenRoot.AddChild(debugItem); }
// Returns true if input gameobject or any of its descendants have modifications, otherwise returns false. bool AddTreeViewItemRecursive(TreeViewItem parentItem, GameObject gameObject, Dictionary <int, PrefabOverrides> prefabOverrideMap, IdSequence idSequence) { var gameObjectItem = new PrefabOverridesTreeViewItem ( gameObject.GetInstanceID(), parentItem.depth + 1, gameObject.name ); gameObjectItem.obj = gameObject; // We don't know yet if this item should be added to the parent. bool shouldAddGameObjectItemToParent = false; PrefabOverrides objectModifications; prefabOverrideMap.TryGetValue(gameObject.GetInstanceID(), out objectModifications); if (objectModifications != null) { // Added GameObject - note that this earlies out! AddedGameObject addedGameObjectData = objectModifications.addedGameObjects.Find(x => x.instanceGameObject == gameObject); if (addedGameObjectData != null) { gameObjectItem.singleModification = addedGameObjectData; gameObjectItem.type = ItemType.ADDED_OBJECT; parentItem.AddChild(gameObjectItem); return(true); } else { // Modified GameObject ObjectOverride modifiedGameObjectData = objectModifications.objectOverrides.Find(x => x.instanceObject == gameObject); if (modifiedGameObjectData != null) { gameObjectItem.singleModification = modifiedGameObjectData; gameObjectItem.type = ItemType.PREFAB_OBJECT; shouldAddGameObjectItemToParent = true; } } // Added components and component modifications foreach (var component in gameObject.GetComponents(typeof(Component))) { // GetComponents will return Missing Script components as null, we will skip them here to prevent NullReferenceExceptions. (case 1197599) if (component == null) { continue; } // Skip coupled components (they are merged into the display of their owning component) if (component.IsCoupledComponent()) { continue; } var componentItem = new PrefabOverridesTreeViewItem ( component.GetInstanceID(), gameObjectItem.depth + 1, ObjectNames.GetInspectorTitle(component) ); componentItem.obj = component; AddedComponent addedComponentData = objectModifications.addedComponents.Find(x => x.instanceComponent == component); if (addedComponentData != null) { // Skip coupled components (they are merged into the display of their owning component) if (addedComponentData.instanceComponent.IsCoupledComponent()) { continue; } componentItem.singleModification = addedComponentData; componentItem.type = ItemType.ADDED_OBJECT; gameObjectItem.AddChild(componentItem); shouldAddGameObjectItemToParent = true; } else { var coupledComponent = component.GetCoupledComponent(); ObjectOverride modifiedObjectData = objectModifications.objectOverrides.Find(x => x.instanceObject == component); ObjectOverride modifiedCoupledObjectData = (coupledComponent != null) ? objectModifications.objectOverrides.Find(x => x.instanceObject == coupledComponent) : null; if (modifiedObjectData != null || modifiedCoupledObjectData != null) { // If only the coupled component has modifications, create an // ObjectOverride object for the main component since it doesn't exist yet. if (modifiedObjectData == null) { modifiedObjectData = new ObjectOverride() { instanceObject = component } } ; modifiedObjectData.coupledOverride = modifiedCoupledObjectData; componentItem.singleModification = modifiedObjectData; componentItem.type = ItemType.PREFAB_OBJECT; gameObjectItem.AddChild(componentItem); shouldAddGameObjectItemToParent = true; } } } // Removed components foreach (var removedComponent in objectModifications.removedComponents) { // Skip coupled components (they are merged into the display of their owning component) if (removedComponent.assetComponent.IsCoupledComponent()) { continue; } var removedComponentItem = new PrefabOverridesTreeViewItem ( idSequence.get(), gameObjectItem.depth + 1, ObjectNames.GetInspectorTitle(removedComponent.assetComponent) ); removedComponentItem.obj = removedComponent.assetComponent; removedComponentItem.singleModification = removedComponent; removedComponentItem.type = ItemType.REMOVED_OBJECT; gameObjectItem.AddChild(removedComponentItem); shouldAddGameObjectItemToParent = true; } } // Recurse into children foreach (Transform childTransform in gameObject.transform) { var childGameObject = childTransform.gameObject; shouldAddGameObjectItemToParent |= AddTreeViewItemRecursive(gameObjectItem, childGameObject, prefabOverrideMap, idSequence); } if (shouldAddGameObjectItemToParent) { parentItem.AddChild(gameObjectItem); if (maxDepthItem == null || gameObjectItem.depth > maxDepthItem.depth) { maxDepthItem = gameObjectItem; } return(true); } return(false); }
public override void PrepareForCommit(R record, IdSequence idSequence) { Actual.prepareForCommit(record, idSequence); }
// Returns true if input gameobject or any of its descendants have modifications, otherwise returns false. bool AddTreeViewItemRecursive(TreeViewItem parentItem, GameObject gameObject, Dictionary <int, PrefabOverrides> prefabOverrideMap, IdSequence idSequence) { var gameObjectItem = new PrefabOverridesTreeViewItem ( idSequence.get(), parentItem.depth + 1, gameObject.name ); gameObjectItem.obj = gameObject; // We don't know yet if this item should be added to the parent. bool shouldAddGameObjectItemToParent = false; PrefabOverrides objectModifications; prefabOverrideMap.TryGetValue(gameObject.GetInstanceID(), out objectModifications); if (objectModifications != null) { // Added GameObject - note that this earlies out! AddedGameObject addedGameObjectData = objectModifications.addedGameObjects.Find(x => x.instanceGameObject == gameObject); if (addedGameObjectData != null) { gameObjectItem.singleModification = addedGameObjectData; gameObjectItem.type = ItemType.ADDED_OBJECT; parentItem.AddChild(gameObjectItem); return(true); } else { // Modified GameObject ObjectOverride modifiedGameObjectData = objectModifications.objectOverrides.Find(x => x.instanceObject == gameObject); if (modifiedGameObjectData != null) { gameObjectItem.singleModification = modifiedGameObjectData; gameObjectItem.type = ItemType.PREFAB_OBJECT; shouldAddGameObjectItemToParent = true; } } // Added components and component modifications foreach (var component in gameObject.GetComponents(typeof(Component))) { var componentItem = new PrefabOverridesTreeViewItem ( idSequence.get(), gameObjectItem.depth + 1, ObjectNames.GetInspectorTitle(component) ); componentItem.obj = component; AddedComponent addedComponentData = objectModifications.addedComponents.Find(x => x.instanceComponent == component); if (addedComponentData != null) { componentItem.singleModification = addedComponentData; componentItem.type = ItemType.ADDED_OBJECT; gameObjectItem.AddChild(componentItem); shouldAddGameObjectItemToParent = true; } else { ObjectOverride modifiedObjectData = objectModifications.objectOverrides.Find(x => x.instanceObject == component); if (modifiedObjectData != null) { componentItem.singleModification = modifiedObjectData; componentItem.type = ItemType.PREFAB_OBJECT; gameObjectItem.AddChild(componentItem); shouldAddGameObjectItemToParent = true; } } } // Removed components foreach (var removedComponent in objectModifications.removedComponents) { var removedComponentItem = new PrefabOverridesTreeViewItem ( idSequence.get(), gameObjectItem.depth + 1, ObjectNames.GetInspectorTitle(removedComponent.assetComponent) ); removedComponentItem.obj = removedComponent.assetComponent; removedComponentItem.singleModification = removedComponent; removedComponentItem.type = ItemType.REMOVED_OBJECT; gameObjectItem.AddChild(removedComponentItem); shouldAddGameObjectItemToParent = true; } } // Recurse into children foreach (Transform childTransform in gameObject.transform) { var childGameObject = childTransform.gameObject; shouldAddGameObjectItemToParent |= AddTreeViewItemRecursive(gameObjectItem, childGameObject, prefabOverrideMap, idSequence); } if (shouldAddGameObjectItemToParent) { parentItem.AddChild(gameObjectItem); return(true); } return(false); }
private void Apply(StudentRegisteredToClassEvent evt) { registrationSequence = registrationSequence.Next(); registrations.Add(new Registration(this, registrationSequence.ToId(), evt.ClassId, evt.Credits)); }
public override void Prepare(RECORD record, int recordSize, IdSequence idSequence) { PrepareConflict.Add(record); Actual.prepare(record, recordSize, idSequence); }
internal RenewableBatchIdSequence(IdSequence source, int batchSize, System.Action <long> excessIdConsumer) { this._source = source; this._batchSize = batchSize; this._excessIdConsumer = excessIdConsumer; }
public void SetUp() { _idSequence = new IdSequence(); }
public RelationshipGroupGetter(IdSequence idGenerator) { this._idGenerator = idGenerator; }
private static async Task <List <int> > GenerateIds(IdStorage idStorage, int count, IdSequence sequence) { var ids = new List <int>(); for (var index = 0; index < count; index++) { var nextId = await idStorage.GetNext(sequence); ids.Add(nextId); } return(ids); }