/// <summary>
        /// Creates an instance of the task data template
        /// </summary>
        /// <returns></returns>
        internal static FeatureDependencyDto ToInstance(this FeatureDependencyDto taskDataTemplate, int taskInstanceId)
        {
            // Cloning something that is not a task data template is not an implemented feature
            if (taskDataTemplate.PathOptionChosen)
            {
                throw new NotImplementedException("Instancing task data from another task data instance is not implemented.");
            }

            // Instance the task data
            var taskDataInstance = new FeatureDependencyDto()
            {
                TaskId = taskInstanceId
            };

            // Copy the path options over
            foreach (var pathOption in taskDataTemplate.PathOptions)
            {
                var clonedPathOption = new FeatureDependencyPathOptionDto()
                {
                    CMFeatureTemplateId   = pathOption.CMFeatureTemplateId,
                    CMTargetSystemStateId = pathOption.CMTargetSystemStateId,
                    FeatureVarName        = pathOption.FeatureVarName,
                    FeatureVarSetTo       = pathOption.FeatureVarSetTo,
                };
                taskDataInstance.PathOptions.Add(clonedPathOption);
            }

            return(taskDataInstance);
        }
示例#2
0
 /// <summary>
 /// Updates the task data with whatever is currently set in the TaskData
 /// </summary>
 private void UpdateTaskData()
 {
     if (TaskData.Id == 0)
     {
         var opResult = FeatureDependencyExtensions.FeatureDependencyDataProvider.Insert(TaskData);
         if (opResult.Errors.Any())
         {
             MessageBox.Show(opResult.ErrorsCombined);
             return;
         }
         // Re-get so the db id is assigned
         TaskData = FeatureDependencyExtensions.FeatureDependencyDataProvider.Get_ForTaskId(cmTask.Id);
     }
     else
     {
         FeatureDependencyExtensions.FeatureDependencyDataProvider.Update(TaskData);
     }
 }
        internal static void UpdateTaskStatesForFeatureDependendies(FeatureDependencyDto linkedTaskData, CMFeatureDto trackedFeature)
        {
            var cmTaskInstance = CMDataProvider.DataStore.Value.CMTasks.Value.Get(linkedTaskData.TaskId);

            if (cmTaskInstance == null)
            {
                // If the task this data links to is null then somehow the task was deleted without deleting the data,
                // Do so now
                FeatureDependencyDataProvider.Delete(linkedTaskData.Id);
                return;
            }

            if (trackedFeature == null && linkedTaskData.InstancedCMFeatureId != 0)
            {
                trackedFeature = CMDataProvider.DataStore.Value.CMFeatures.Value.Get(linkedTaskData.InstancedCMFeatureId);
            }

            // Figure out what the task (that is associated with the dependency data) state should be
            CMTaskStateDto shouldBeState = null;

            if (linkedTaskData.PathOptionChosen == false)
            {
                shouldBeState = FeatureDependency_TaskState_WaitingOnChoice;
            }
            else
            {
                shouldBeState = trackedFeature == null || linkedTaskData.InstancedTargetCMSystemStateId == trackedFeature.CMSystemStateId ?
                                FeatureDependency_TaskState_Closed :
                                FeatureDependency_TaskState_WaitingOnDependency;
            }

            // Now check to see if the dependency task actually is in that state
            if (cmTaskInstance.CMTaskStateId != shouldBeState.Id)
            {
                // If it's not in the state it should be, then do the update so it is.
                // All of the checks to avoid doing an update are to avoid chain reactions with the CUD events
                cmTaskInstance.CMTaskStateId = shouldBeState.Id;
                CMDataProvider.DataStore.Value.CMTasks.Value.Update(cmTaskInstance);
            }
        }
        /// <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;
                }
            }
        }
示例#5
0
        private void ReloadUI()
        {
            TaskData = FeatureDependencyExtensions.FeatureDependencyDataProvider.Get_ForTaskId(cmTask.Id);

            if (TaskData == null)
            {
                TaskData = new FeatureDependencyDto()
                {
                    TaskId = cmTask.Id
                };
            }

            dataGridEditFeatureDependencySettings.Visibility = Visibility.Hidden;
            dataGridChooseFeatureDependency.Visibility       = Visibility.Hidden;
            gridChosen.Visibility = Visibility.Hidden;

            dataGridEditFeatureDependencySettings.ItemsSource = null;
            dataGridChooseFeatureDependency.ItemsSource       = null;

            // Display as a task template
            if (cmTask.IsTemplate)
            {
                dataGridEditFeatureDependencySettings.Visibility = Visibility.Visible;

                dataGridEditFeatureDependencySettings.ItemsSource = TaskData.PathOptions;
            }
            // Display as a task instance
            else
            {
                // If choice has been made and there are no options to choose from then jump straight to the
                // dialog to select a dependency.
                if (TaskData.PathOptionChosen == false && !TaskData.PathOptions.Any())
                {
                    var featureSelectorUC = ShowFeatureSelectorWindow(0, 0, cmTask.IsTemplate);
                    if (featureSelectorUC.SelectionConfirmed)
                    {
                        TaskData.PathOptionChosen               = true;
                        TaskData.InstancedCMFeatureId           = featureSelectorUC.SelectedFeatureId;
                        TaskData.InstancedTargetCMSystemStateId = featureSelectorUC.SelectedSystemStateId;
                        UpdateTaskData();
                    }
                }

                // Display for an instance that does not yet have the choice made
                if (TaskData.PathOptionChosen == false)
                {
                    dataGridChooseFeatureDependency.Visibility  = Visibility.Visible;
                    dataGridChooseFeatureDependency.ItemsSource = TaskData.PathOptions;
                }
                // Display for an instance that already has the choice made
                else
                {
                    gridChosen.Visibility = Visibility.Visible;

                    if (TaskData.InstancedCMFeatureId == 0)
                    {
                        txtChosenFeatureName.Text = "<None>";
                        txtChosenTargetState.Text = "<None>";
                    }
                    else
                    {
                        cmTargetFeature = CMDataProvider.DataStore.Value.CMFeatures.Value.Get(TaskData.InstancedCMFeatureId);
                        var cmTargetSystemState = CMDataProvider.DataStore.Value.CMSystemStates.Value.Get(TaskData.InstancedTargetCMSystemStateId);
                        txtChosenFeatureName.Text = cmTargetFeature.Name;
                        txtChosenTargetState.Text = cmTargetSystemState.Name;
                    }
                }
            }
        }