/// <summary> /// Register a pipe with the junction. /// </summary> /// <remarks> /// <para> /// Pipes are registered by unique name and type, /// which must be either <c>Junction.INPUT</c> /// or <c>Junction.OUTPUT</c>. /// </para> /// <para> /// NOTE: You cannot have an INPUT pipe and an OUTPUT /// pipe registered with the same name. All pipe names /// must be unique regardless of type. /// </para> /// </remarks> /// <param name="name">name of the pipe</param> /// <param name="type">type (INPUT/OUTPUT) of the pipe</param> /// <param name="pipe">Pipefitting</param> /// <returns>true if successfully registered. false if another pipe exists by that name.</returns> public virtual bool RegisterPipe(string name, string type, IPipeFitting pipe) { bool success = true; if (PipesMaps.TryGetValue(name, out IPipeFitting value) == false && PipesMaps.TryAdd(name, pipe) && PipeTypesMap.TryAdd(name, type)) { switch (type) { case INPUT: InputPipes.Add(name); break; case OUTPUT: OutputPipes.Add(name); break; default: success = false; break; } } else { success = false; } return(success); }
/// <summary> /// Remove the pipe with this name if it is registered. /// </summary> /// <remarks> /// <para> /// NOTE: You cannot have an INPUT pipe and an OUTPUT /// pipe registered with the same name. All pipe names /// must be unique regardless of type. /// </para> /// </remarks> /// <param name="name">name the pipe to remove</param> public virtual void RemovePipe(string name) { if (HasPipe(name)) { PipeTypesMap.TryGetValue(name, out string type); switch (type) { case INPUT: InputPipes.Remove(name); break; case OUTPUT: OutputPipes.Remove(name); break; } PipesMaps.TryRemove(name, out IPipeFitting pipe); PipeTypesMap.TryRemove(name, out string value); } }