public IPipeline Add(string name, IModuleList modules) { ExecutionPipeline executionPipeline = CreatePipeline(name, modules); _pipelines.Add(executionPipeline); return(executionPipeline); }
public IPipeline Insert(int index, string name, IModuleList modules) { ExecutionPipeline executionPipeline = CreatePipeline(name, modules); _pipelines.Insert(index, executionPipeline); return(executionPipeline); }
/// <summary> /// Gets the last module of the specified type. /// </summary> /// <typeparam name="TModule">The type of the module to find.</typeparam> /// <param name="moduleList">The <see cref="ModuleList"/> to search.</param> /// <param name="filter">A predicate determining which module to find.</param> /// <returns>The last module of the specified type or null if a module of the specified type could not be found.</returns> public static TModule GetLast <TModule>(this IModuleList moduleList, Predicate <TModule> filter) where TModule : class, IModule { int index = moduleList.IndexOfLast(filter); return(index == -1 ? default(TModule) : (TModule)moduleList[index]); }
public ExecutionPipeline(string name, IModuleList modules) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException(nameof(name)); } Name = name; _modules = modules ?? new ModuleList(); }
private static int IndexOfOrThrow(this IModuleList moduleList, string name) { int index = moduleList.IndexOf(name); if (index == -1) { throw new InvalidOperationException($"Could not find module with the name of {name}"); } return(index); }
private static int IndexOfLastOrThrow <TModule>(this IModuleList moduleList, Predicate <TModule> filter) where TModule : class, IModule { int index = moduleList.IndexOfLast(filter); if (index == -1) { throw new InvalidOperationException($"Could not find module of type {typeof(TModule).FullName}"); } return(index); }
private ExecutionPipeline CreatePipeline(string name, IModuleList modules) { _nameCounter++; if (string.IsNullOrWhiteSpace(name)) { name = "Pipeline " + _nameCounter; } if (ContainsKey(name)) { throw new ArgumentException("Pipelines must have a unique name."); } return(new ExecutionPipeline(name, modules)); }
public static void Replace(this IModuleList moduleList, int index, IModule module, string name = "") { if (string.IsNullOrWhiteSpace(name)) { NamedModule namedModule = moduleList[index] as NamedModule; if (namedModule != null) { name = namedModule.Name; } } moduleList.RemoveAt(index); moduleList.Insert(index, name, module); }
private static int GuardIndexOfFirst <T>(this IModuleList moduleList, Predicate <T> filter) where T : class, IModule { for (int index = 0; index < moduleList.Count; index++) { IModule module = moduleList[index]; T expectedModule = module as T; if (expectedModule == null) { continue; } if (filter(expectedModule)) { return(index); } } throw new InvalidOperationException($"Could not find module of type {typeof(T).FullName}"); }
/// <summary> /// Gets the index of the last module of the specified type. /// </summary> /// <typeparam name="TModule">The type of the module to find.</typeparam> /// <param name="moduleList">The <see cref="ModuleList"/> to search.</param> /// <param name="filter">A predicate determining which module to find.</param> /// <returns>The index of the last module of the specified type or -1 if a module of the specified type could not be found.</returns> public static int IndexOfLast <TModule>(this IModuleList moduleList, Predicate <TModule> filter) where TModule : class, IModule { for (int index = moduleList.Count - 1; index >= 0; index--) { IModule module = moduleList[index]; if (!(module is TModule expectedModule)) { continue; } if (filter(expectedModule)) { return(index); } } return(-1); }
/// <summary> /// Creates a pipeline with the specified modules /// and the specified name. /// </summary> /// <param name="name">The name of the pipeline.</param> /// <param name="modules">The modules in the pipeline.</param> public Pipeline(string name, IEnumerable <IModule> modules) { Name = name ?? GetType().Name; _modules = (modules as IModuleList) ?? new ModuleList(modules); }
public static void InsertBeforeLast <T>(this IModuleList moduleList, Predicate <T> filter, params IModule[] modules) where T : class, IModule => moduleList.Insert(moduleList.GuardIndexOfLast(filter), modules);
public static void InsertBeforeLast <T>(this IModuleList moduleList, params IModule[] modules) where T : class, IModule => moduleList.InsertBeforeLast <T>(_ => true, modules);
/// <summary> /// Replaces the last module in the list of the specified type. /// </summary> /// <typeparam name="T">The type of the module to replace.</typeparam> /// <param name="moduleList">The <see cref="ModuleList"/>.</param> /// <param name="module">The replacement module.</param> /// <param name="name">The name of the replacement module.</param> /// <returns>The current instance.</returns> public static IModuleList ReplaceLast <T>(this IModuleList moduleList, IModule module, string name = null) where T : class, IModule => moduleList.ReplaceLast <T>(_ => true, module, name);
/// <summary> /// Replaces the last module in the list of the specified type that satisfies a predicate. /// </summary> /// <typeparam name="T">The type of the module to replace.</typeparam> /// <param name="moduleList">The <see cref="ModuleList"/>.</param> /// <param name="filter">A predicate determining which module to replace.</param> /// <param name="module">The replacement module.</param> /// <param name="name">The name of the replacement module.</param> /// <returns>The current instance.</returns> public static IModuleList ReplaceLast <T>(this IModuleList moduleList, Predicate <T> filter, IModule module, string name = null) where T : class, IModule => moduleList.Replace(moduleList.GuardIndexOfLast(filter), module, name);
public static void InsertBefore(this IModuleList moduleList, string name, params IModule[] modules) => moduleList.Insert(moduleList.GuardIndexOf(name), modules);
/// <summary> /// Inserts modules after the last module in the list of the specified type that satisfies a predicate. /// </summary> /// <typeparam name="T">The type of the module at which to insert the modules.</typeparam> /// <param name="moduleList">The <see cref="ModuleList"/>.</param> /// <param name="filter">A predicate determining at which module to insert the specified modules.</param> /// <param name="name">The name of the module to insert.</param> /// <param name="module">The module to insert.</param> /// <returns>The current instance.</returns> public static IModuleList InsertAfterLast <T>(this IModuleList moduleList, Predicate <T> filter, string name, IModule module) where T : class, IModule { moduleList.Insert(moduleList.GuardIndexOfLast(filter) + 1, name, module); return(moduleList); }
/// <summary> /// Inserts a new named pipeline after an existing named pipeline. /// </summary> /// <param name="pipelines">The pipeline collection.</param> /// <param name="target">The pipeline after which the new pipeline should be inserted.</param> /// <param name="name">The name of the new pipeline.</param> /// <param name="modules">The modules the new pipeline should contain.</param> /// <returns>The newly inserted pipeline.</returns> public static IPipeline InsertAfter(this IPipelineCollection pipelines, string target, string name, IModuleList modules) { int index = pipelines.IndexOf(target); if (index < 0) { throw new KeyNotFoundException($"Target pipeline {target} was not found"); } return(index + 1 < pipelines.Count ? pipelines.Insert(index + 1, name, modules) : pipelines.Add(name, modules)); }
/// <summary> /// Inserts a new unnamed pipeline before an existing named pipeline. /// </summary> /// <param name="pipelines">The pipeline collection.</param> /// <param name="target">The pipeline before which the new pipeline should be inserted.</param> /// <param name="modules">The modules the new pipeline should contain.</param> /// <returns>The newly inserted pipeline.</returns> public static IPipeline InsertBefore(this IPipelineCollection pipelines, string target, IModuleList modules) => InsertBefore(pipelines, target, null, modules);
public static void ReplaceLast <T>(this IModuleList moduleList, IModule module) where T : class, IModule => moduleList.ReplaceLast <T>(_ => true, module);
/// <summary> /// Creates a new container module with the specified child modules. /// Any <c>null</c> items in the sequence of modules will be discarded. /// </summary> /// <param name="modules">The child modules.</param> protected ContainerModule(IEnumerable <IModule> modules) { _modules = (modules as IModuleList) ?? new ModuleList(modules); }
public ModuleEditController(IModuleList dalIModuleList, IMainModule dalIMainModule) { this.dalIModuleList = dalIModuleList; this.dalIMainModule = dalIMainModule; }
public static void ReplaceLast <T>(this IModuleList moduleList, Predicate <T> filter, IModule module) where T : class, IModule => moduleList.Replace(moduleList.GuardIndexOfLast(filter), module);
public static void Replace(this IModuleList moduleList, string name, IModule module) => moduleList.Replace(moduleList.GuardIndexOf(name), module, name);
/// <summary> /// Adds a new unnamed pipeline to the collection. /// </summary> /// <param name="pipelines">The pipeline collection.</param> /// <param name="modules">The modules the new pipeline should contain.</param> /// <returns>The newly added pipeline.</returns> public static IPipeline Add(this IPipelineCollection pipelines, IModuleList modules) => pipelines.Add(null, modules);
/// <summary> /// Gets the index of the last module of the specified type. /// </summary> /// <typeparam name="TModule">The type of the module to find.</typeparam> /// <param name="moduleList">The <see cref="ModuleList"/> to search.</param> /// <returns>The index of the last module of the specified type or -1 if a module of the specified type could not be found.</returns> public static int IndexOfLast <TModule>(this IModuleList moduleList) where TModule : class, IModule => moduleList.IndexOfLast <TModule>(_ => true);
/// <summary> /// Inserts a new unnamed pipeline into the collection. /// </summary> /// <param name="pipelines">The pipeline collection.</param> /// <param name="index">The index at which to insert the new pipeline.</param> /// <param name="modules">The modules the new pipeline should contain.</param> /// <returns>The newly inserted pipeline.</returns> public static IPipeline Insert(this IPipelineCollection pipelines, int index, IModuleList modules) => pipelines.Insert(index, null, modules);
/// <summary> /// Inserts modules after the last module in the list of the specified type. /// </summary> /// <typeparam name="T">The type of the module at which to insert the specified modules.</typeparam> /// <param name="moduleList">The <see cref="ModuleList"/>.</param> /// <param name="name">The name of the module to insert.</param> /// <param name="module">The module to insert.</param> /// <returns>The current instance.</returns> public static IModuleList InsertAfterLast <T>(this IModuleList moduleList, string name, IModule module) where T : class, IModule => moduleList.InsertAfterLast <T>(_ => true, name, module);
/// <summary> /// Inserts modules after the last module in the list of the specified type. /// </summary> /// <typeparam name="T">The type of the module at which to insert the specified modules.</typeparam> /// <param name="moduleList">The <see cref="ModuleList"/>.</param> /// <param name="modules">The modules to insert.</param> /// <returns>The current instance.</returns> public static IModuleList InsertAfterLast <T>(this IModuleList moduleList, params IModule[] modules) where T : class, IModule => moduleList.InsertAfterLast <T>(_ => true, modules);
/// <summary> /// Inserts modules after the last module in the list of the specified type that satisfies a predicate. /// </summary> /// <typeparam name="T">The type of the module at which to insert the modules.</typeparam> /// <param name="moduleList">The <see cref="ModuleList"/>.</param> /// <param name="filter">A predicate determining at which module to insert the specified modules.</param> /// <param name="modules">The modules to insert.</param> /// <returns>The current instance.</returns> public static IModuleList InsertAfterLast <T>(this IModuleList moduleList, Predicate <T> filter, params IModule[] modules) where T : class, IModule { moduleList.Insert(moduleList.GuardIndexOfLast(filter) + 1, modules); return(moduleList); }