internal static void FeatureDependency_CreateTaskDataInstance(CMTaskDto cmTaskTemplate, CMTaskDto cmTaskInstance) { // Double check to make sure there isn't task data for this task already var existingTaskData = FeatureDependencyDataProvider.Get_ForTaskId(cmTaskInstance.Id); if (existingTaskData != null) { throw new Exception("Task data already exists for the feature dependency task."); } // The task data (template) to clone var taskDataTemplate = FeatureDependencyDataProvider.Get_ForTaskId(cmTaskTemplate.Id); // If there was no task data template defined then just return without creating data for the instance if (taskDataTemplate == null) { return; } // Clone the template task data var taskDataInstance = taskDataTemplate.ToInstance(cmTaskInstance.Id); // And insert it var opInsertResult = FeatureDependencyExtensions.FeatureDependencyDataProvider.Insert(taskDataInstance); if (opInsertResult.Errors.Any()) { throw new Exception(opInsertResult.ErrorsCombined); } // A new task data has just been inserted, CUD triggers that react to the taskdata created should take over from here. }
internal static void Note_ResolveFeatureVars(CMTaskDto cmTask, List <CMFeatureVarStringDto> featureVars) { // Do not resolve feature vars for a task template if (cmTask.IsTemplate) { return; } // The task data for the task var taskData = NoteDataProvider.Get_ForTaskId(cmTask.Id); // If there is no note data then there is nothing more to do here if (taskData == null) { return; } var newNote = FeatureVars.ResolveFeatureVarsInString(taskData.Note, featureVars); if (newNote != taskData.Note) { taskData.Note = newNote; var opUpdateTaskData = NoteDataProvider.Update(taskData); if (opUpdateTaskData.Errors.Any()) { throw new InvalidOperationException(opUpdateTaskData.ErrorsCombined); } } }
internal static void Note_CreateTaskDataInstance(CMTaskDto cmTaskTemplate, CMTaskDto cmTaskInstance) { // The task data (template) to clone var taskDataTemplate = NoteDataProvider.Get_ForTaskId(cmTaskTemplate.Id); // If there was no task data template defined then just return without creating data for the instance if (taskDataTemplate == null) { return; } // Now we can create new task data note var taskData = new NoteDto() { TaskId = cmTaskInstance.Id, Note = taskDataTemplate.Note }; var opResult = NoteDataProvider.Insert(taskData); if (opResult.Errors.Any()) { throw new Exception(opResult.ErrorsCombined); } }
public FeatureDependencyUC(CMSystemDto cmSystem, CMFeatureDto cmFeature, CMTaskDto cmTask) { InitializeComponent(); this.cmSystem = cmSystem; this.cmFeature = cmFeature; this.cmTask = cmTask; }
public override bool HasTaskData(CMTaskTypeDto cmTaskType, CMTaskDto cmTask) { switch (cmTaskType.Name) { case nameof(BuildInTaskTypes.FeatureDependency): return(FeatureDependencyExtensions.FeatureDependencyDataProvider.Get_ForTaskId(cmTask.Id) != null); case nameof(BuildInTaskTypes.Note): return(NoteExtensions.NoteDataProvider.Get_ForTaskId(cmTask.Id) != null); } return(false); }
public override void CreateTaskDataInstance(CMTaskTypeDto cmTaskType, CMTaskDto cmTaskTemplate, CMTaskDto cmTaskInstance) { switch (cmTaskType.Name) { case nameof(BuildInTaskTypes.FeatureDependency): FeatureDependencyExtensions.FeatureDependency_CreateTaskDataInstance(cmTaskTemplate, cmTaskInstance); break; case nameof(BuildInTaskTypes.Note): NoteExtensions.Note_CreateTaskDataInstance(cmTaskTemplate, cmTaskInstance); break; } }
/// <summary> /// Creates an instance of the task, setting the instanced task to the <see cref="ReservedTaskStates.Instance"/> state. /// The clone task Id is left at 0 and not inserted into the database. /// System and feature ids are re-assigned to the passed in values. /// All other values are an exact copy from the template with no feature vars resolved. /// </summary> /// <param name="taskTemplate"></param> /// <param name="cmFeatureId">The feature id that the clone should be assigned to</param> /// <returns></returns> public static CMTaskDto ToInstance(this CMTaskDto taskTemplate, int cmFeatureId) { // Cloning something that is not a template is not an implemented feature if (!taskTemplate.IsTemplate) { throw new NotImplementedException("A task instance can only be created from a task template."); } // Instance the task var taskInstance = new CMTaskDto() { CMFeatureId = cmFeatureId, CMParentTaskTemplateId = taskTemplate.Id, CMSystemStateId = taskTemplate.CMSystemStateId, CMTaskStateId = CMDataProvider.DataStore.Value.CMTaskStates.Value.Get_ForInternalName(ReservedTaskStates.Instance, taskTemplate.CMTaskTypeId).Id, CMTaskTypeId = taskTemplate.CMTaskTypeId, Title = taskTemplate.Title }; return(taskInstance); }
public static void ResolveFeatureVars(this CMTaskDto task, List <CMFeatureVarStringDto> featureVars) { if (task.IsTemplate) { throw new InvalidOperationException("Resolving feature vars for a task template is not supported."); } // The only thing to resolve in a task itself is the title var newTaskTitle = ResolveFeatureVarsInString(task.Title, featureVars); // Only update the task if a change was made if (!newTaskTitle.Equals(task.Title, StringComparison.OrdinalIgnoreCase)) { task.Title = newTaskTitle; var opTaskUpdate = CMDataProvider.DataStore.Value.CMTasks.Value.Update(task); if (opTaskUpdate.Errors.Any()) { throw new Exception(opTaskUpdate.ErrorsCombined); } } }
/// <summary> /// Examines the current set of path options for the feature dependency task data and creates a feature instance if one of the path options matches the rules. /// Only 1 feature will be instanced. If a feature has already been instanced then this function will do nothing. /// If no path option rules match, then the function does nothing. /// </summary> internal static void FeatureDependency_ResolveFeatureVars(CMTaskDto taskInstance, List <CMFeatureVarStringDto> featureVars) { FeatureDependencyDto instanceTaskData = FeatureDependencyDataProvider.Get_ForTaskId(taskInstance.Id); if (instanceTaskData.PathOptionChosen) { // There is already a choice made return; } // The feature instance that the task is part of var featureInstance = CMDataProvider.DataStore.Value.CMFeatures.Value.Get(taskInstance.CMFeatureId); // Do not process if we are dealing with a template if (taskInstance.IsTemplate || featureInstance.IsTemplate) { return; } // Examine all path options foreach (var pathOption in instanceTaskData.PathOptions.OrderBy(po => po.Order)) { bool useThisOption = false; // A setting with a blank feature var name is auto-chosen if we get to it if (string.IsNullOrWhiteSpace(pathOption.FeatureVarName)) { useThisOption = true; } else { // If the feature var to look for is not yet present in the featurevars collection, then this option is skipped over. // The order that feature vars are set in has an effect on which option is chosen. var matchingFeatureVar = featureVars.FirstOrDefault(v => v.Name.Equals(pathOption.FeatureVarName, StringComparison.OrdinalIgnoreCase)); if (matchingFeatureVar != null && matchingFeatureVar.Value.Equals(pathOption.FeatureVarSetTo, StringComparison.OrdinalIgnoreCase)) { useThisOption = true; } } if (useThisOption) { instanceTaskData.PathOptionChosen = true; // If the path option leads to a feature template, then instance it if (pathOption.CMFeatureTemplateId > 0) { // The feature template referred to by this option var featureTemplate = CMDataProvider.DataStore.Value.CMFeatures.Value.Get(pathOption.CMFeatureTemplateId); // Make it so the child feature inherits the color from the parent featureTemplate.TasksBackgroundColor = featureInstance.TasksBackgroundColor; var childFeatureVars = new List <CMFeatureVarStringDto>(); var clonedFeatureInstance = featureTemplate.ToInstance(childFeatureVars); // Set the task data to represent the feature instance that was created instanceTaskData.InstancedCMFeatureId = clonedFeatureInstance.Id; instanceTaskData.InstancedTargetCMSystemStateId = pathOption.CMTargetSystemStateId; } var opUpdateTaskData = FeatureDependencyDataProvider.Update(instanceTaskData); if (opUpdateTaskData.Errors.Any()) { throw new Exception(opUpdateTaskData.ErrorsCombined); } break; } } }
public TaskEditor(CMTaskDto cmTaskDto) { this.cmTaskDto = cmTaskDto; InitializeComponent(); }
/// <summary> /// Called when instancing a task. A <see cref="CMTaskDto"/> will have already been created and is passed in. /// The task factory should create any task data for this new task and take care of updating the database. /// </summary> /// <param name="cmTaskType"></param> /// <param name="cmTaskTemplate">The task template that the task was created from</param> /// <param name="cmTaskInstance">The new task that was created</param> public abstract void CreateTaskDataInstance(CMTaskTypeDto cmTaskType, CMTaskDto cmTaskTemplate, CMTaskDto cmTaskInstance);
/// <summary> /// Called when the program needs to determine if task data exists already for a task or not /// </summary> /// <param name="cmTask"></param> /// <returns></returns> public abstract bool HasTaskData(CMTaskTypeDto cmTaskType, CMTaskDto cmTask);
/// <summary> /// The UI that is shown when editing a task /// </summary> /// <param name="cmTaskType"></param> /// <param name="cmSystem"></param> /// <param name="cmFeature"></param> /// <param name="cmTask"></param> /// <returns></returns> public abstract UserControl GetTaskUI(CMTaskTypeDto cmTaskType, CMSystemDto cmSystem, CMFeatureDto cmFeature, CMTaskDto cmTask);
public FeatureEditorTaskRowDto(CMTaskDto cmTask) { this.Task = cmTask; }
public FeatureEditorTaskRowDto() { this.Task = new CMTaskDto(); }
/// <summary> /// Gets the user control meant to edit or view a particular task /// </summary> /// <param name="cmTaskType"></param> /// <param name="cmSystem"></param> /// <param name="cmFeature"></param> /// <param name="cmTask"></param> /// <returns></returns> public UserControl GetTaskUI(CMTaskTypeDto cmTaskType, CMSystemDto cmSystem, CMFeatureDto cmFeature, CMTaskDto cmTask) { var taskFactory = GetTaskFactory(cmTaskType.Name); var taskUC = taskFactory.GetTaskUI(cmTaskType, cmSystem, cmFeature, cmTask); return(taskUC); }
public override UserControl GetTaskUI(CMTaskTypeDto cmTaskType, CMSystemDto cmSystem, CMFeatureDto cmFeature, CMTaskDto cmTask) { switch (cmTaskType.Name) { case nameof(BuildInTaskTypes.FeatureDependency): var featureDependencyTaskUI = new FeatureDependencyUC(cmSystem, cmFeature, cmTask); return(featureDependencyTaskUI); case nameof(BuildInTaskTypes.Note): var noteTaskUI = new NoteUC(cmSystem, cmFeature, cmTask); return(noteTaskUI); } return(null); }
public bool HasTaskData(CMTaskTypeDto cmTaskType, CMTaskDto cmTask) { var taskFactory = GetTaskFactory(cmTaskType.Name); return(taskFactory.HasTaskData(cmTaskType, cmTask)); }
/// <summary> /// Called when instancing a task. A <see cref="CMTaskDto"/> will have already been created and is passed in. /// The task factory should create any task data for this new task and take care of updating the database. /// </summary> /// <param name="cmTaskType"></param> /// <param name="cmTaskInstance">The id of the newly created CMTaskDto instance that was created from the template</param> public void CreateTaskDataInstance(CMTaskTypeDto cmTaskType, CMTaskDto cmTaskTemplate, CMTaskDto cmTaskInstance) { var taskFactory = GetTaskFactory(cmTaskType.Name); taskFactory.CreateTaskDataInstance(cmTaskType, cmTaskTemplate, cmTaskInstance); }