/// <summary> /// Finds the task using the specified <paramref name="source" /> and <paramref name="taskID" />. /// </summary> /// <param name="source">The node.</param> /// <param name="taskID">The task ID.</param> /// <returns> /// Returns a <see cref="IMMPxTask" /> representing the tasks that matches specified task name for the given node; /// otherwise <c>null</c>. /// </returns> public static IMMPxTask GetTask(this IMMPxNode source, int taskID) { IMMPxNode3 node3 = source as IMMPxNode3; if (node3 == null) { return(null); } IMMEnumPxTasks tasks = node3.EnabledTasks; foreach (var task in tasks.AsEnumerable()) { if (taskID == task.TaskID) { return(task); } } return(null); }
/// <summary> /// Finds the task using the specified <paramref name="source" /> and <paramref name="taskName" />. /// </summary> /// <param name="source">The node.</param> /// <param name="taskName">Name of the task.</param> /// <param name="enabledTask">if set to <c>true</c> if the task must be enabled.</param> /// <returns> /// Returns a <see cref="IMMPxTask" /> representing the tasks that matches specified task name for the given node; /// otherwise <c>null</c>. /// </returns> /// <exception cref="ArgumentNullException">taskName</exception> public static IMMPxTask GetTask(this IMMPxNode source, string taskName, bool enabledTask) { if (source == null) { return(null); } if (taskName == null) { throw new ArgumentNullException("taskName"); } IEnumerable <IMMPxTask> tasks; if (enabledTask) { IMMPxNode3 node3 = source as IMMPxNode3; if (node3 == null) { return(null); } tasks = node3.EnabledTasks.AsEnumerable(); } else { IMMPxNode4 node4 = source as IMMPxNode4; if (node4 == null) { return(null); } tasks = node4.AllTasks.AsEnumerable(); } return(tasks.FirstOrDefault(o => o.Name.Equals(taskName, StringComparison.OrdinalIgnoreCase))); }