public virtual void RemoveComponent(IStudioComponent component) { if (_components.Remove(component)) { component.InputRemoved -= Component_EndpointRemoved; component.OutputRemoved -= Component_EndpointRemoved; var foundConnections = new List <StudioConnection>(); if (component.Inputs != null) { foreach (var input in component.Inputs) { foreach (var connection in _connections.Where(c => c.Input == input).ToList()) { RemoveConnection(connection); } } } if (component.Outputs != null) { foreach (var output in component.Outputs) { foreach (var connection in _connections.Where(c => c.Output == output).ToList()) { RemoveConnection(connection); } } } ComponentRemoved?.Invoke(this, component); } }
public virtual IStudioComponent AddComponent(IStudioComponent component) { if (_components.Contains(component)) { return(null); } IStudioComponent newComponent = null; if (ComponentRepository.Contains(component)) { if (component is PlaceholderStudioComponent placeholderComponent) { newComponent = ComponentRepository.GetPlaceholderClone(placeholderComponent); } else { newComponent = component; } _components.Add(newComponent); newComponent.InputRemoved += Component_EndpointRemoved; newComponent.OutputRemoved += Component_EndpointRemoved; ComponentAdded?.Invoke(this, newComponent); } return(newComponent); }
public virtual void RemoveClient(IStudioComponent client) { if (_clients.Remove(client)) { ClientRemoved?.Invoke(this, client); } }
public void TestInit() { var virtualStudio = new VirtualStudioWithArrangement(); // Create a placeholder and add it to ComponentRepository and add a copy to the VirtualStudio's components. placeholderInRepository = new PlaceholderStudioComponent(); placeholderInRepository.SetName("Placeholder 1"); placeholderInRepository.AddInput("Input 1", Shared.DataKind.Audio, "WebRTC"); placeholderInRepository.AddOutput("Output 1", Shared.DataKind.Audio, "WebRTC"); virtualStudio.ComponentRepository.AddPlaceholder(placeholderInRepository); placeholderInComponents = virtualStudio.AddComponent(placeholderInRepository); // Create a component mock and add it to ComponentRepository AND the VirtualStudio. client1Mock = new Mock <IStudioComponent>(); client1Mock.Setup(m => m.SetId(It.IsAny <int>())).Callback <int>((value) => client1Id = value); client1Mock.SetupGet(m => m.Id).Returns(() => client1Id); virtualStudio.ComponentRepository.AddClient(client1Mock.Object); virtualStudio.AddComponent(client1Mock.Object); // Create a component mock and add it only to ComponentRepository. client2Mock = new Mock <IStudioComponent>(); client2Mock.Setup(m => m.SetId(It.IsAny <int>())).Callback <int>((value) => client2Id = value); client2Mock.SetupGet(m => m.Id).Returns(() => client2Id); virtualStudio.ComponentRepository.AddClient(client2Mock.Object); this.virtualStudio = virtualStudio; operationHandlerMock = new Mock <IVirtualStudioUpdateListener>(); virtualStudioEventProcessor = new VirtualStudioEventProcessor(virtualStudio, virtualStudioName, operationHandlerMock.Object); }
private void DetachComponentEventHandlers(IStudioComponent component) { component.PropertyChanged -= Component_PropertyChanged; component.InputAdded -= Component_InputAdded; component.InputRemoved -= Component_InputRemoved; component.OutputAdded -= Component_OutputAdded; component.OutputRemoved -= Component_OutputRemoved; }
public virtual bool AddClient(IStudioComponent client) { if (AddClientStudioComponent(client)) { ClientAdded?.Invoke(this, client); return(true); } return(false); }
public void Init() { virtualStudio = new VirtualStudio(); var placeholderComponent = new PlaceholderStudioComponent(); placeholderComponent.SetName("New Placeholder"); virtualStudio.ComponentRepository.AddPlaceholder(placeholderComponent); component = virtualStudio.AddComponent(placeholderComponent); repositoryComponent = placeholderComponent; }
protected virtual bool AddClientStudioComponent(IStudioComponent component) { if (!PrepareAddComponent(component)) { return(false); } _clients.Add(component); return(true); }
public override void RemoveComponent(IStudioComponent component) { if (_components.Contains(component)) { var node = _componentNodes.Single(c => c.Component == component); _componentNodes.Remove(node); node.PositionChanged -= ComponentNode_PositionChanged; base.RemoveComponent(component); } }
public static StudioComponentDto ToDto(this IStudioComponent component) { return(new StudioComponentDto { IsPlaceholder = component is PlaceholderStudioComponent, Id = component.Id, Name = component.Name, Inputs = component.Inputs?.ToDto(), Outputs = component.Outputs?.ToDto() }); }
private void VirtualStudio_ComponentAdded(object sender, IStudioComponent component) { if (component is PlaceholderStudioComponent) { AttachComponentEventHandlers(component); operationHandler.AddPlaceholder(VirtualStudioName, component.ToDto()); } else { operationHandler.AddComponent(VirtualStudioName, component.Id); } }
private bool ProcessSync(VirtualStudio virtualStudio) { IStudioComponent studioComponent = virtualStudio.Components.FirstOrDefault(c => c.Id == componentId); if (studioComponent is null) { Error = new OperationError(ErrorType.NotFound, $"Component with ID {componentId} not found."); return(false); } virtualStudio.RemoveComponent(studioComponent); return(true); }
private bool ChangeProperty(IStudioComponent component, string propertyName, object value) { switch (propertyName) { case nameof(component.Name): if (value is string nameString) { component.SetName(nameString); return(true); } break; } return(false); }
public void Init() { virtualStudio = new VirtualStudio(); var placeholder = new PlaceholderStudioComponent(); placeholder.AddInput("Input 1", DataKind.Audio, "UDP"); virtualStudio.ComponentRepository.AddPlaceholder(placeholder); componentWithUdpAudioInput = virtualStudio.AddComponent(placeholder); placeholder = new PlaceholderStudioComponent(); placeholder.AddOutput("Output 1", DataKind.Audio, "UDP"); virtualStudio.ComponentRepository.AddPlaceholder(placeholder); componentWithUdpAudioOutput = virtualStudio.AddComponent(placeholder); connection = virtualStudio.CreateConnection(componentWithUdpAudioOutput.Outputs[0], componentWithUdpAudioInput.Inputs[0]); }
public ComponentNode AddComponent(IStudioComponent component, Position2D targetPosition) { if (!_components.Contains(component)) { component = base.AddComponent(component); if (component != null) { var componentNode = new ComponentNode(component) { Position = targetPosition }; componentNode.PositionChanged += ComponentNode_PositionChanged; _componentNodes.Add(componentNode); ComponentNodeAdded?.Invoke(this, componentNode); return(componentNode); } } return(null); }
private bool PrepareAddComponent(IStudioComponent component) { if (Contains(component)) { return(false); } if (component.Id != 0) { if (Exists(c => c.Id == component.Id)) { throw new ArgumentException("Cannot add a placeholder component with an already existing ID."); } } else { do { component.SetId(idGenerator.GetNewId()); } while (Exists(c => c.Id == component.Id)); } return(true); }
public void Init() { virtualStudio = new VirtualStudio(); var placeholder = new PlaceholderStudioComponent(); placeholder.AddInput("Input 1", DataKind.Audio, "UDP"); virtualStudio.ComponentRepository.AddPlaceholder(placeholder); componentWithUdpAudioInput = virtualStudio.AddComponent(placeholder); componentWithUdpAudioInputInRepository = placeholder; placeholder = new PlaceholderStudioComponent(); placeholder.AddInput("Input 1", DataKind.Audio, "WebRtc"); virtualStudio.ComponentRepository.AddPlaceholder(placeholder); componentWithWebRtcAudioInput = virtualStudio.AddComponent(placeholder); placeholder = new PlaceholderStudioComponent(); placeholder.AddInput("Input 1", DataKind.Video, "WebRtc"); virtualStudio.ComponentRepository.AddPlaceholder(placeholder); componentWithWebRtcVideoInput = virtualStudio.AddComponent(placeholder); placeholder = new PlaceholderStudioComponent(); placeholder.AddOutput("Output 1", DataKind.Audio, "UDP"); virtualStudio.ComponentRepository.AddPlaceholder(placeholder); componentWithUdpAudioOutput = virtualStudio.AddComponent(placeholder); placeholder = new PlaceholderStudioComponent(); placeholder.AddOutput("Output 1", DataKind.Audio, "WebRtc"); virtualStudio.ComponentRepository.AddPlaceholder(placeholder); componentWithWebRtcAudioOutput = virtualStudio.AddComponent(placeholder); placeholder = new PlaceholderStudioComponent(); placeholder.AddOutput("Output 1", DataKind.Video, "WebRtc"); virtualStudio.ComponentRepository.AddPlaceholder(placeholder); componentWithWebRtcVideoOutput = virtualStudio.AddComponent(placeholder); }
private void ComponentRepository_ClientAdded(object sender, IStudioComponent client) { AttachComponentEventHandlers(client); operationHandler.AddClientToRepository(VirtualStudioName, client.ToDto()); }
private void ComponentRepository_PlaceholderAdded(object sender, IStudioComponent placeholder) { AttachComponentEventHandlers(placeholder); operationHandler.AddPlaceholderToRepository(VirtualStudioName, placeholder.ToDto()); }
private void ComponentRepository_PlaceholderRemoved(object sender, IStudioComponent placeholder) { DetachComponentEventHandlers(placeholder); operationHandler.RemovePlaceholderFromRepository(VirtualStudioName, placeholder.Id); }
private void VirtualStudio_ComponentRemoved(object sender, IStudioComponent component) { DetachComponentEventHandlers(component); operationHandler.RemoveComponent(VirtualStudioName, component.Id); }
public ComponentNode(IStudioComponent component) { Component = component ?? throw new ArgumentNullException(nameof(component)); }
public void ReplaceComponent(IStudioComponent component) { throw new NotImplementedException(); }
public override IStudioComponent AddComponent(IStudioComponent component) { return(AddComponent(component, Position2D.Zero)?.Component); }
private void ComponentRepository_ClientRemoved(object sender, IStudioComponent client) { DetachComponentEventHandlers(client); operationHandler.RemoveClientFromRepository(VirtualStudioName, client.Id); }
public bool Contains(IStudioComponent component) { return(_clients.Contains(component) || (component is PlaceholderStudioComponent psc && _placeholders.Contains(psc))); }