/// <summary> /// Connects a group import to a group export with the given part and schedule connections described /// by the <paramref name="connection"/> object. /// </summary> /// <param name="connection">The object that describes how the group import and the group export should be connected.</param> /// <returns>A task that will finish when the connection action has completed.</returns> public Task Connect(GroupConnection connection) { var globalTask = Task.Factory.StartNew( () => { var key = m_DatasetLock.LockForWriting(); try { m_CompositionLayer.Connect(connection); } finally { m_DatasetLock.RemoveWriteLock(key); } }); return globalTask; }
/// <summary> /// Connects the exporting group with the importing group via the given import. /// </summary> /// <param name="connection">The object that describes how the group import and the group export should be connected.</param> public void Connect(GroupConnection connection) { { Lokad.Enforce.Argument(() => connection); Lokad.Enforce.With<UnknownGroupCompositionIdException>( m_Groups.ContainsKey(connection.ImportingGroup), Resources.Exceptions_Messages_UnknownGroupCompositionId); Lokad.Enforce.With<UnknownGroupCompositionIdException>( m_Groups.ContainsKey(connection.ExportingGroup), Resources.Exceptions_Messages_UnknownGroupCompositionId); } m_GroupConnections.AddEdge(new GroupCompositionGraphEdge(connection.ImportingGroup, connection.GroupImport, connection.ExportingGroup)); var importingParts = PartsForGroup(connection.ImportingGroup); var exportingParts = PartsForGroup(connection.ExportingGroup); ConnectParts(connection.PartConnections, importingParts, exportingParts); }
public void Connect() { var lockKey = new DatasetLockKey(); var datasetLock = new Mock<ITrackDatasetLocks>(); { datasetLock.Setup(d => d.LockForWriting()) .Returns(lockKey) .Verifiable(); datasetLock.Setup(d => d.RemoveWriteLock(It.IsAny<DatasetLockKey>())) .Callback<DatasetLockKey>(key => Assert.AreSame(lockKey, key)) .Verifiable(); } var originalConnection = new GroupConnection( new GroupCompositionId(), new GroupCompositionId(), GroupImportDefinition.CreateDefinition( "a", new GroupRegistrationId("a"), null, Enumerable.Empty<ImportRegistrationId>()), Enumerable.Empty<PartImportToPartExportMap>()); var storage = new Mock<IStoreGroupsAndConnections>(); { storage.Setup(s => s.Connect(It.IsAny<GroupConnection>())) .Callback<GroupConnection>( id => { Assert.AreSame(originalConnection, id); }); } var commands = new CompositionCommands(datasetLock.Object, storage.Object); var task = commands.Connect(originalConnection); task.Wait(); datasetLock.Verify(d => d.LockForWriting(), Times.Once()); datasetLock.Verify(d => d.RemoveWriteLock(It.IsAny<DatasetLockKey>()), Times.Once()); }
/// <summary> /// Connects the given export to the given import. /// </summary> /// <param name="importingGroup">The ID of the group that owns the import.</param> /// <param name="importDefinition">The import.</param> /// <param name="exportingGroup">The ID of the group that owns the export.</param> /// <returns>A task which indicates when the connection has taken place.</returns> public Task Connect( GroupCompositionId importingGroup, GroupImportDefinition importDefinition, GroupCompositionId exportingGroup) { { Debug.Assert(importingGroup != null, "The ID of the importing group should not be a null reference."); Debug.Assert(importDefinition != null, "The import definition should not be a null reference."); Debug.Assert(exportingGroup != null, "The ID of the exporting group should not be a null reference."); } if (!Contains(importingGroup) || !Contains(exportingGroup)) { throw new UnknownPartGroupException(); } m_Diagnostics.Log( LevelToLog.Trace, HostConstants.LogPrefix, string.Format( CultureInfo.InvariantCulture, Resources.ProxyCompositionLayer_LogMessage_ConnectingGroups_WithImportAndExport, importingGroup, exportingGroup)); var parts = m_Connector.GenerateConnectionFor(m_Groups[importingGroup], importDefinition, m_Groups[exportingGroup]); var state = new GroupConnection(importingGroup, exportingGroup, importDefinition, parts); var remoteTask = m_Commands.Connect(state); return remoteTask.ContinueWith( t => { lock (m_Lock) { m_GroupConnections.AddEdge(new CompositionLayerGroupEdge(importingGroup, importDefinition, exportingGroup)); } }); }