private bool InPrerequisiteLoop() { PartManager firstPart = _recursionStateStack.First(); PartManager?lastPart = null; foreach (PartManager testPart in _recursionStateStack.Skip(1)) { if (testPart.State == ImportState.PreExportImportsSatisfying) { return(true); } if (testPart == firstPart) { lastPart = testPart; break; } } // This should only be called when a loop has been detected - so it should always be on the stack if (lastPart != firstPart) { throw new Exception(SR.Diagnostic_InternalExceptionMessage); } return(false); }
private PartManager GetPartManager(ComposablePart part, bool createIfNotpresent) { PartManager partManager = null; using (this._lock.LockStateForRead()) { if (this._partManagers.TryGetValue(part, out partManager)) { return(partManager); } } if (createIfNotpresent) { using (this._lock.LockStateForWrite()) { if (!this._partManagers.TryGetValue(part, out partManager)) { partManager = new PartManager(this, part); this._partManagers.Add(part, partManager); } } } return(partManager); }
private void StopSatisfyingImports(PartManager partManager, AtomicComposition?atomicComposition) { // When not running in a atomicCompositional state, schedule reindexing after ensuring // that this isn't a redundant removal if (atomicComposition == null) { ConditionalWeakTable <ComposablePart, PartManager>?partManagers = null; RecompositionManager?recompositionManager = null; using (_lock.LockStateForRead()) { partManagers = _partManagers; recompositionManager = _recompositionManager; } if (partManagers != null) // Disposal race may have been won by dispose { partManagers.Remove(partManager.Part); // Take care of lifetime requirements partManager.DisposeAllDependencies(); if (partManager.TrackingImports) { partManager.TrackingImports = false; recompositionManager.AddPartToUnindex(partManager); } } } else { // While in a atomicCompositional state use a less efficient but effective means // of achieving the same results GetEngineContext(atomicComposition).RemovePartManager(partManager); } }
/// <summary> /// Create a node by adding a copy of the <see cref="PrototypeData"/> /// to the diagram's model, and assign its <see cref="Node.Location"/> /// to be the given point. /// </summary> /// <param name="loc"></param> /// <remarks> /// This also selects the new node and raises the "object created" event. /// </remarks> public virtual void InsertNode(Point loc) { Diagram diagram = this.Diagram; if (diagram == null) { return; } PartManager partmgr = diagram.PartManager; if (partmgr == null) { return; } StartTransaction("Create Node"); IDiagramModel model = partmgr.FindNodeDataModel(this.PrototypeData); Object copy = model.AddNodeCopy(this.PrototypeData); Node node = partmgr.FindNodeForData(copy, model); if (node != null) { node.Location = loc; if (diagram.AllowSelect) { diagram.Select(node); } } diagram.Panel.UpdateDiagramBounds(); // set the EditResult before raising event, in case it changes the result or cancels the tool this.TransactionResult = "Create Node"; RaiseEvent(Diagram.NodeCreatedEvent, new DiagramEventArgs(node)); StopTransaction(); }
void OnTriggerEnter(Collider other) { WeaponPickUp _PickUp = GetComponentInChildren <WeaponPickUp>(); if (_PickUp != null) { //PartManager _PartManager = other.GetComponentInChildren<PartManager>(); PartManager _PartManager = other.GetComponentInParent <PartManager>(); if (_PartManager != null) { switch (_PickUp.m_Type) { case WeaponPickUp.PickUpType.Barrel: _PartManager.AddBarrel(_PickUp.m_BarrelAttributes.m_Index); Mesh.enabled = false; aSource.PlayOneShot(aClip); break; case WeaponPickUp.PickUpType.Stock: _PartManager.AddStock(_PickUp.m_StockAttributes.m_Index); Mesh.enabled = false; aSource.PlayOneShot(aClip); break; default: break; } StartCoroutine(Vanish()); } } }
private void DoUpdateNodesAndLinks() { VerifyAccess(); this.UpdateNodesAndLinksNeeded = false; Diagram observed = this.Observed; if (observed == null) { return; } PartManager obmgr = observed.PartManager; if (obmgr == null) { return; } // make sure each Node and Link have the same locations and routes and visibility as those in the Observed diagram bool usevis = this.UsesObservedPartVisible; if (this.UsesObservedNodeLocation) { foreach (Node overviewnode in this.Nodes) { Node observednode = obmgr.FindNodeForData(overviewnode.Data, this.Model); if (observednode != null) { Point ovloc = overviewnode.Location; Point obloc = observednode.Location; if (!Geo.IsApprox(ovloc, obloc)) { overviewnode.Location = obloc; } if (usevis) { overviewnode.Visible = observednode.Visible; } } } } if (this.UsesObservedLinkRoute) { foreach (Link overviewlink in this.Links) { Link observedlink = obmgr.FindLinkForData(overviewlink.Data, this.Model); if (observedlink != null) { overviewlink.Route.Points = observedlink.Route.Points; if (usevis) { overviewlink.Visible = observedlink.Visible; } } } } // afterwards, Node.Location is updated dynamically in Overview.ObservedPanel_PartBoundsChanged // and Part.Visible is updated dynamically in Overview.ObservedPanel_PartVisibleChanged }
public void RemovePartManager(PartManager part) { Assumes.NotNull(part); if (!_addedPartManagers.Remove(part)) { _removedPartManagers.Add(part); } }
public void RemovePartManager(PartManager part) { Assumes.NotNull(part); if (!this._addedPartManagers.Remove(part)) { this._removedPartManagers.Add(part); } }
public void AddPartManager(PartManager part) { Assumes.NotNull(part); if (!this._removedPartManagers.Remove(part)) { this._addedPartManagers.Add(part); } }
public void FindPartManager() { GameObject player = GameObject.Find("Character"); if (player != null) { partManager = player.GetComponentInChildren <PartManager> (); } }
public void RemovePartManager(PartManager part) { ArgumentNullException.ThrowIfNull(part); if (!_addedPartManagers.Remove(part)) { _removedPartManagers.Add(part); } }
public void UpdateRouteTable() { var componentFeature = new ComponentFeature(); PartManager.PopulateFeature(componentFeature); var types = componentFeature.Components; Routes = RouteTable.Create(types); }
public BuildingControlCommands() { DependsOn((PartManager x) => m_partManager = x); Create("clear").Handler(ClearStations); Create("spawn").AllowOnlyOn(SessionType.PlayerController).Handler(ProcessSpawn) .NamedFlag("debug").NamedArgument <int?>("rooms", null).NamedArgument <long>("seed", 0).NamedArgument <int?>(new[] { "pop", "population" }, null); Create("info").AllowOnlyOn(SessionType.PlayerController).Handler <string>(ProcessInfo); Create("stations").Handler(ProcessStationLocations); Create("part").Handler <string>(ProcessDebugPart); }
private void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); } else { instance = this; } }
// Start is called before the first frame update void Start() { movePoint.parent = null; partManager = FindObjectOfType <PartManager>(); animator = GetComponent <Animator>(); if (animator != null) { print("Got Animator"); } }
private void Awake() { if (Instance == null) { Instance = this; } else { Destroy(this); } }
private PartManager GetPartManager(ComposablePart part) { PartManager partManager = null; if (!this._partManagers.TryGetValue(part, out partManager)) { partManager = new PartManager(part); this._partManagers.Add(part, partManager); } return(partManager); }
public void UpdatePart_RecalculateCostsForAssembly() { Mock <IDataRepositoryFactory> mockDataRepositoryFactory = new Mock <IDataRepositoryFactory>(); Mock <IPartRepository> mockPartRepository = new Mock <IPartRepository>(); mockDataRepositoryFactory.Setup(mock => mock.GetDataRepository <IPartRepository>()).Returns(mockPartRepository.Object); PartManager manager = new PartManager(mockDataRepositoryFactory.Object); manager.RecalculateCostsForAssembly(1); mockPartRepository.Verify(f => f.RecalculateCostsForAssembly(1)); }
public void RemovePartManager(PartManager part) { if (part == null) { throw new ArgumentNullException(nameof(part)); } if (!_addedPartManagers.Remove(part)) { _removedPartManagers.Add(part); } }
// Post public override void TranslateT2C(TransCAD.IFeature tFeature) { TransCAD.IStdSolidProtrusionExtrudeFeature proExtrude = (TransCAD.IStdSolidProtrusionExtrudeFeature)tFeature; // 스케치 변환 FeatureSketch SketchManager = new FeatureSketch(PartManager); TransCAD.IFeature profilesketch = PartManager.GetFeatureFromReference(proExtrude.ProfileSketch); SketchManager.TranslateT2C(profilesketch); double sD = proExtrude.StartDepth; TransCAD.StdExtrudeEndType sC = proExtrude.StartCondition; double eD = proExtrude.EndDepth; TransCAD.StdExtrudeEndType eC = proExtrude.EndCondition; bool isFlip = proExtrude.IsFlip; PARTITF.Pad cPad = PartManager.cShapeFactory.AddNewPadFromRef(SketchManager.cReference, sD); cPad.FirstLimit.Dimension.Value = sD; cPad.SecondLimit.Dimension.Value = eD; if (sC == TransCAD.StdExtrudeEndType.Blind) { cPad.FirstLimit.LimitMode = PARTITF.CatLimitMode.catOffsetLimit; } else if (sC == TransCAD.StdExtrudeEndType.ThroughAll) { cPad.FirstLimit.LimitMode = PARTITF.CatLimitMode.catUpToLastLimit; } if (eC == TransCAD.StdExtrudeEndType.Blind) { cPad.SecondLimit.LimitMode = PARTITF.CatLimitMode.catOffsetLimit; } else if (eC == TransCAD.StdExtrudeEndType.ThroughAll) { cPad.SecondLimit.LimitMode = PARTITF.CatLimitMode.catUpToLastLimit; } if (isFlip == false) { cPad.DirectionOrientation = PARTITF.CatPrismOrientation.catRegularOrientation; } else if (isFlip == true) { cPad.DirectionOrientation = PARTITF.CatPrismOrientation.catInverseOrientation; } PartManager.cPart.UpdateObject(cPad); PartManager.ReferenceManager.NameMap.Add(proExtrude.Name, cPad.get_Name()); }
private void ObservedPanel_PartVisibleChanged(object sender, EventArgs e) { Diagram observed = this.Observed; if (observed == null) { return; } PartManager partmgr = this.PartManager; if (partmgr == null) { return; } Node observednode = sender as Node; if (observednode != null && this.UsesObservedPartVisible) { // find the corresponding node in this Overview Node overviewnode = partmgr.FindNodeForData(observednode.Data, observed.Model); if (overviewnode != null) { // need to remove any Binding for Part.Visible on this node, // in case it is Mode=TwoWay, trying to update the data FrameworkElement ve = overviewnode.EnsuredVisualElement; if (ve != null) { ve.ClearValue(Part.VisibleProperty); } overviewnode.Visible = observednode.Visible; } } else { Link observedlink = sender as Link; if (observedlink != null && this.UsesObservedPartVisible) { Link overviewlink = partmgr.FindLinkForData(observedlink.Data, observed.Model); if (overviewlink != null) { // need to remove any Binding for Part.Visible on this node, // in case it is Mode=TwoWay, trying to update the data FrameworkElement ve = overviewlink.EnsuredVisualElement; if (ve != null) { ve.ClearValue(Part.VisibleProperty); } overviewlink.Visible = observedlink.Visible; } } } }
public static Guid CprToUuid(string cprNumber) { var uuid = PartManager.GetUuid(BrokerContext.Current.UserToken, BrokerContext.Current.ApplicationToken, cprNumber); if (StandardReturType.IsSucceeded(uuid.StandardRetur)) { return(new Guid(uuid.UUID)); } else { throw new Exception(string.Format("Could not find UUID of person <{0}>", cprNumber)); } }
/// <summary> /// Removes any state stored in the <see cref="ImportEngine"/> for the associated /// <see cref="ComposablePart"/> and releases all the <see cref="Export"/>s used to /// satisfy the imports on the <see cref="ComposablePart"/>. /// /// Also removes the enforcement for changes that would break a required import on /// <paramref name="part"/>. /// </summary> /// <param name="part"> /// The <see cref="ComposablePart"/> to release the imports on. /// </param> /// <param name="atomicComposition"> /// The <see cref="AtomicComposition"/> that the release imports is running under. /// </param> public void ReleaseImports(ComposablePart part, AtomicComposition atomicComposition) { this.ThrowIfDisposed(); Requires.NotNull(part, "part"); PartManager partManager = null; if (this._partManagers.TryGetValue(part, out partManager)) { StopSatisfyingImports(partManager, atomicComposition); } }
public void UpdatePart_UpdateExisting() { var existingPart = new Part { Id = 1, OwnCost = 1}; var updatedPart = new Part { Id = 1, OwnCost = 2}; Mock<IDataRepositoryFactory> mockDataRepositoryFactory = new Mock<IDataRepositoryFactory>(); mockDataRepositoryFactory.Setup(mock => mock.GetDataRepository<IPartRepository>().Update(existingPart)).Returns(updatedPart); PartManager manager = new PartManager(mockDataRepositoryFactory.Object); var resultedPart = manager.UpdatePart(existingPart); Assert.AreEqual(updatedPart, resultedPart); }
public IActionResult GetPart(int partId) { try { var manager = new PartManager(_options); return(Ok(manager.GetPart(partId))); } catch (Exception ex) { logger.Error(ex); return(BadRequest(ex.Message)); } }
public void UpdatePart_AddNew() { var newPart = new Part(); var addedPart = new Part { Id = 1 }; Mock<IDataRepositoryFactory> mockDataRepositoryFactory = new Mock<IDataRepositoryFactory>(); mockDataRepositoryFactory.Setup(mock => mock.GetDataRepository<IPartRepository>().Add(newPart)).Returns(addedPart); PartManager manager = new PartManager(mockDataRepositoryFactory.Object); var resultedPart = manager.UpdatePart(newPart); Assert.AreEqual(addedPart, resultedPart); }
public void PartManager_ValidatePartNumber_Success() { //Arrange string partNumber = "5678"; Boolean returnValue; PartManager objPartManager = new PartManager(); //Act returnValue = objPartManager.IsValidPartNumber(partNumber); //Result Assert.IsTrue(returnValue); }
public void PartManager_ValidateQuantity_Success() { //Arrange string quantity = "58"; Boolean returnValue; PartManager objPartManager = new PartManager(); //Act returnValue = objPartManager.IsValidQuantity(quantity); //Result Assert.IsTrue(returnValue); }
public void PartManager_ValidatePartNumber_Failure() { //Arrange string partNumber = ""; Boolean returnValue; PartManager objPartManager = new PartManager(); //Act returnValue = objPartManager.IsValidPartNumber(partNumber); //Result Assert.IsFalse(returnValue); }
public IActionResult SetPart([FromBody] Alkatresz data) { try { var manager = new PartManager(_options); var result = manager.SetPart(data); return(Ok(result)); } catch (Exception ex) { logger.Error(ex); return(BadRequest(ex.Message)); } }
public void PartManager_ValidateQuantity_Failure() { //Arrange string quantity = "a"; Boolean returnValue; PartManager objPartManager = new PartManager(); //Act returnValue = objPartManager.IsValidPartNumber(quantity); //Result Assert.IsFalse(returnValue); }
protected override void LoadContent() { IsMouseVisible = true; spriteBatch = new SpriteBatch(GraphicsDevice); graphics.SynchronizeWithVerticalRetrace = false; IsFixedTimeStep = false; graphics.PreferredBackBufferWidth = 1280; graphics.PreferredBackBufferHeight = 720; graphics.ApplyChanges(); enginesRoot = new EnginesRoot(new SimpleSubmissionEntityViewScheduler()); entityFactory = enginesRoot.GenerateEntityFactory(); entityFunctions = enginesRoot.GenerateEntityFunctions(); objects.RegisterInstance(spriteBatch); objects.RegisterInstance(graphics); objects.RegisterInstance(GraphicsDevice); objects.RegisterInstance(Content); objects.RegisterInstance(typeof(IEntityFactory), entityFactory); objects.RegisterInstance(typeof(IEntityFunctions), entityFunctions); objects.DiscoverServices(); objects.Verify(); objects.DoOnAttribute <SystemAttribute>((attribute, type) => { if (type.Implements <IEngine>()) { var engine = (IEngine)objects.Get(type); enginesRoot.AddEngine(engine); } }); parts = objects.Get <PartManager>(); parts.Load(); var resourceLoader = objects.Get <ResourceLoader>(); resourceLoader.Process(); var repository = objects.Get <SpriteRepository>(); repository.PlaceInternalCache(); parts.Ready(); }
private CompositionResult TryRecomposeImports(PartManager partManager, IEnumerable <ExportDefinition> changedExports, AtomicComposition atomicComposition) { var result = CompositionResult.SucceededResult; switch (partManager.State) { case ImportState.ImportsPreviewed: case ImportState.Composed: // Validate states to continue. break; default: { // All other states are invalid and for recomposition. return(new CompositionResult(ErrorBuilder.InvalidStateForRecompposition(partManager.Part))); } } var affectedImports = RecompositionManager.GetAffectedImports(partManager.Part, changedExports); bool partComposed = (partManager.State == ImportState.Composed); bool recomposedImport = false; foreach (var import in affectedImports) { result = result.MergeResult( TryRecomposeImport(partManager, partComposed, import, atomicComposition)); recomposedImport = true; } // Knowing that the part has already been composed before and that the only possible // changes are to recomposable imports, we can safely go ahead and do this now or // schedule it for later if (result.Succeeded && recomposedImport && partComposed) { if (atomicComposition == null) { result = result.MergeResult(partManager.TryOnComposed()); } else { atomicComposition.AddCompleteAction(() => partManager.TryOnComposed().ThrowOnErrors()); } } return(result); }
public void Part_GetProductTree() { var productTree = new HierarchyNode<ProductTree> { Depth = 111 }; Mock<IDataRepositoryFactory> mockDataRepositoryFactory = new Mock<IDataRepositoryFactory>(); mockDataRepositoryFactory.Setup(mock => mock.GetDataRepository<IPartRepository>().GetProductTree()).Returns(productTree); PartManager manager = new PartManager(mockDataRepositoryFactory.Object); var resultedTree = manager.GetProductTree(); Assert.AreEqual(111, resultedTree.Depth); }
public void Part_GetAll() { var parts = new[] { new Part {Id = 1, Notes = "Part 1"}, new Part {Id = 2, Notes = "Part 2"} }; Mock<IDataRepositoryFactory> mockDataRepositoryFactory = new Mock<IDataRepositoryFactory>(); mockDataRepositoryFactory.Setup(mock => mock.GetDataRepository<IPartRepository>().Get()).Returns(parts); PartManager manager = new PartManager(mockDataRepositoryFactory.Object); var resultedPart = manager.GetAllParts(); Assert.AreEqual(parts.Length, resultedPart.Length); }
private void AddIndexEntries(PartManager partManager) { foreach (string contractName in partManager.GetImportedContractNames()) { WeakReferenceCollection<PartManager> indexEntries; if (!this._partManagerIndex.TryGetValue(contractName, out indexEntries)) { indexEntries = new WeakReferenceCollection<PartManager>(); this._partManagerIndex.Add(contractName, indexEntries); } if (!indexEntries.Contains(partManager)) { indexEntries.Add(partManager); } } }
private PartManager GetPartManager(ComposablePart part) { PartManager partManager = null; if (!this._partManagers.TryGetValue(part, out partManager)) { partManager = new PartManager(part); this._partManagers.Add(part, partManager); } return partManager; }
private CompositionResult TryPreviewImportsStateMachine(PartManager partManager, ComposablePart part, AtomicComposition atomicComposition) { var result = CompositionResult.SucceededResult; if (partManager.State == ImportState.ImportsPreviewing) { // We shouldn't nomally ever hit this case but if we do // then we should just error with a cycle error. return new CompositionResult(ErrorBuilder.CreatePartCycle(part)); } // Transition from NoImportsStatisified to ImportsPreviewed if (partManager.State == ImportState.NoImportsSatisfied) { partManager.State = ImportState.ImportsPreviewing; var requiredImports = part.ImportDefinitions.Where(IsRequiredImportForPreview); // If this atomicComposition gets rolledback for any reason we need to reset our state atomicComposition.AddRevertActionAllowNull(() => partManager.State = ImportState.NoImportsSatisfied); result = result.MergeResult( this.TrySatisfyImportSubset(partManager, requiredImports, atomicComposition)); if (!result.Succeeded) { partManager.State = ImportState.NoImportsSatisfied; return result; } partManager.State = ImportState.ImportsPreviewed; } return result; }
private CompositionResult TrySatisfyImportsStateMachine(PartManager partManager, ComposablePart part) { var result = CompositionResult.SucceededResult; while (partManager.State < ImportState.Composed) { var previousState = partManager.State; switch (partManager.State) { // "ed" states which represent a some sort of steady state and will // attempt to do a state transition case ImportState.NoImportsSatisfied: case ImportState.ImportsPreviewed: { partManager.State = ImportState.PreExportImportsSatisfying; var prereqImports = part.ImportDefinitions.Where(import => import.IsPrerequisite); result = result.MergeResult( this.TrySatisfyImportSubset(partManager, prereqImports, null)); partManager.State = ImportState.PreExportImportsSatisfied; break; } case ImportState.PreExportImportsSatisfied: { partManager.State = ImportState.PostExportImportsSatisfying; var requiredImports = part.ImportDefinitions.Where(import => !import.IsPrerequisite); result = result.MergeResult( this.TrySatisfyImportSubset(partManager, requiredImports, null)); partManager.State = ImportState.PostExportImportsSatisfied; break; } case ImportState.PostExportImportsSatisfied: { partManager.State = ImportState.ComposedNotifying; partManager.ClearSavedImports(); result = result.MergeResult(partManager.TryOnComposed()); partManager.State = ImportState.Composed; break; } // "ing" states which represent some sort of cycle // These state should always return, error or not, instead of breaking case ImportState.ImportsPreviewing: { // We shouldn't nomally ever hit this case but if we do // then we should just error with a cycle error. return new CompositionResult(ErrorBuilder.CreatePartCycle(part)); } case ImportState.PreExportImportsSatisfying: case ImportState.PostExportImportsSatisfying: { if (InPrerequisiteLoop()) { return result.MergeError(ErrorBuilder.CreatePartCycle(part)); } // Cycles in post export imports are allowed so just return in that case return result; } case ImportState.ComposedNotifying: { // We are currently notifying so don't notify again just return return result; } } // if an error occured while doing a state transition if (!result.Succeeded) { // revert to the previous state and return the error partManager.State = previousState; return result; } } return result; }
public void AddPartToUnindex(PartManager partManager) { this._partsToUnindex.Add(partManager); }
private PartManager GetPartManager(ComposablePart part, bool createIfNotpresent) { PartManager partManager = null; using (this._lock.LockStateForRead()) { if (this._partManagers.TryGetValue(part, out partManager)) { return partManager; } } if (createIfNotpresent) { using (this._lock.LockStateForWrite()) { if (!this._partManagers.TryGetValue(part, out partManager)) { partManager = new PartManager(this, part); this._partManagers.Add(part, partManager); } } } return partManager; }
private CompositionResult TrySatisfyImports(PartManager partManager, ComposablePart part, bool shouldTrackImports) { Assumes.NotNull(part); var result = CompositionResult.SucceededResult; // get out if the part is already composed if (partManager.State == ImportState.Composed) { return result; } // Track number of recursive iterations and throw an exception before the stack // fills up and debugging the root cause becomes tricky if (this._recursionStateStack.Count >= MaximumNumberOfCompositionIterations) { return result.MergeError( ErrorBuilder.ComposeTookTooManyIterations(MaximumNumberOfCompositionIterations)); } // Maintain the stack to detect whether recursive loops cross prerequisites this._recursionStateStack.Push(partManager); try { result = result.MergeResult( TrySatisfyImportsStateMachine(partManager, part)); } finally { this._recursionStateStack.Pop(); } if (shouldTrackImports) { StartSatisfyingImports(partManager, null); } return result; }
public void UpdatePart_RecalculateCostsForAssembly() { Mock<IDataRepositoryFactory> mockDataRepositoryFactory = new Mock<IDataRepositoryFactory>(); Mock<IPartRepository> mockPartRepository = new Mock<IPartRepository>(); mockDataRepositoryFactory.Setup(mock => mock.GetDataRepository<IPartRepository>()).Returns(mockPartRepository.Object); PartManager manager = new PartManager(mockDataRepositoryFactory.Object); manager.RecalculateCostsForAssembly(1); mockPartRepository.Verify(f => f.RecalculateCostsForAssembly(1)); }
private CompositionResult TryRecomposeImports(PartManager partManager, IEnumerable<ExportDefinition> changedExports, AtomicComposition atomicComposition) { var result = CompositionResult.SucceededResult; switch (partManager.State) { case ImportState.ImportsPreviewed: case ImportState.Composed: // Validate states to continue. break; default: { // All other states are invalid and for recomposition. return new CompositionResult(ErrorBuilder.InvalidStateForRecompposition(partManager.Part)); } } var affectedImports = RecompositionManager.GetAffectedImports(partManager.Part, changedExports); bool partComposed = (partManager.State == ImportState.Composed); bool recomposedImport = false; foreach (var import in affectedImports) { result = result.MergeResult( TryRecomposeImport(partManager, partComposed, import, atomicComposition)); recomposedImport = true; } // Knowing that the part has already been composed before and that the only possible // changes are to recomposable imports, we can safely go ahead and do this now or // schedule it for later if (result.Succeeded && recomposedImport && partComposed) { if (atomicComposition == null) { result = result.MergeResult(partManager.TryOnComposed()); } else { atomicComposition.AddCompleteAction(() => partManager.TryOnComposed().ThrowOnErrors()); } } return result; }
private CompositionResult TryRecomposeImport(PartManager partManager, bool partComposed, ImportDefinition import, AtomicComposition atomicComposition) { if (partComposed && !import.IsRecomposable) { return new CompositionResult(ErrorBuilder.PreventedByExistingImport(partManager.Part, import)); } // During recomposition you must always requery with the new atomicComposition you cannot use any // cached value in the part manager var exportsResult = TryGetExports(this._sourceProvider, partManager.Part, import, atomicComposition); if (!exportsResult.Succeeded) { return exportsResult.ToResult(); } var exports = exportsResult.Value.AsArray(); if (partComposed) { // Knowing that the part has already been composed before and that the only possible // changes are to recomposable imports, we can safely go ahead and do this now or // schedule it for later if (atomicComposition == null) { return partManager.TrySetImport(import, exports); } else { atomicComposition.AddCompleteAction(() => partManager.TrySetImport(import, exports).ThrowOnErrors()); } } else { partManager.SetSavedImport(import, exports, atomicComposition); } return CompositionResult.SucceededResult; }
private void StartSatisfyingImports(PartManager partManager, AtomicComposition atomicComposition) { // When not running in a atomicCompositional state, schedule reindexing after ensuring // that this isn't a redundant addition if (atomicComposition == null) { if (!partManager.TrackingImports) { partManager.TrackingImports = true; this._recompositionManager.AddPartToIndex(partManager); } } else { // While in a atomicCompositional state use a less efficient but effective means // of achieving the same results GetEngineContext(atomicComposition).AddPartManager(partManager); } }
private void RemoveIndexEntries(PartManager partManager) { foreach (string contractName in partManager.GetImportedContractNames()) { WeakReferenceCollection<PartManager> indexEntries; if (this._partManagerIndex.TryGetValue(contractName, out indexEntries)) { indexEntries.Remove(partManager); var aliveItems = indexEntries.AliveItemsToList(); if (aliveItems.Count == 0) { this._partManagerIndex.Remove(contractName); } } } }
private CompositionResult TrySatisfyImportSubset(PartManager partManager, IEnumerable<ImportDefinition> imports, AtomicComposition atomicComposition) { CompositionResult result = CompositionResult.SucceededResult; var part = partManager.Part; foreach (ImportDefinition import in imports) { var exports = partManager.GetSavedImport(import); if (exports == null) { CompositionResult<IEnumerable<Export>> exportsResult = TryGetExports( this._sourceProvider, part, import, atomicComposition); if (!exportsResult.Succeeded) { result = result.MergeResult(exportsResult.ToResult()); continue; } exports = exportsResult.Value.AsArray(); } if (atomicComposition == null) { result = result.MergeResult( partManager.TrySetImport(import, exports)); } else { partManager.SetSavedImport(import, exports, atomicComposition); } } return result; }
private void StopSatisfyingImports(PartManager partManager, AtomicComposition atomicComposition) { // When not running in a atomicCompositional state, schedule reindexing after ensuring // that this isn't a redundant removal if (atomicComposition == null) { this._partManagers.Remove(partManager.Part); // Take care of lifetime requirements partManager.DisposeAllDependencies(); if (partManager.TrackingImports) { partManager.TrackingImports = false; this._recompositionManager.AddPartToUnindex(partManager); } } else { // While in a atomicCompositional state use a less efficient but effective means // of achieving the same results GetEngineContext(atomicComposition).RemovePartManager(partManager); } }