Ejemplo n.º 1
0
        /// <summary>
        /// Checks to see if the Model Element contains errors
        /// </summary>
        /// <param name="modelElement">Any <see cref="ModelElement"/>. Errors may be reported if the element implements <see cref="IModelErrorOwner"/></param>
        /// <param name="useFilter">The filter for the error being displayed. See <see cref="ModelErrorUses"/> for more information.</param>
        /// <param name="displayFilter">The <see cref="ModelErrorDisplayFilter"/> filter to determine if errors should be displayed or not.</param>
        /// <returns>Returns <see langword="true"/> if the errors are present for the provided filters</returns>
        public static bool HasErrors(ModelElement modelElement, ModelErrorUses useFilter, ModelErrorDisplayFilter displayFilter)
        {
            bool             hasError   = false;
            IModelErrorOwner errorOwner = modelElement as IModelErrorOwner;

            if (errorOwner != null)
            {
                foreach (ModelErrorUsage usage in errorOwner.GetErrorCollection(useFilter))
                {
                    if (ModelError.IsDisplayed(usage.Error, displayFilter))
                    {
                        hasError = true;
                        break;
                    }
                }
            }
            return(hasError);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Helper function to add an error to the task provider
        /// when the error display filter changes.
        /// </summary>
        /// <param name="error"></param>
        public static void AddToTaskProvider(ModelError error)
        {
            if (error.IsDeleted)
            {
                return;
            }
            IORMToolTaskProvider taskProvider;

            if (null != (taskProvider = ((IORMToolServices)error.Store).TaskProvider) &&
                ModelError.IsDisplayed(error, error.Model.ModelErrorDisplayFilter))
            {
                taskProvider = (error.Store as IORMToolServices).TaskProvider;
                IORMToolTaskItem newTask = taskProvider.CreateTask();
                newTask.ElementLocator = error as IRepresentModelElements;
                newTask.Text           = error.ErrorText;
                Debug.Assert(error.TaskData == null);
                error.TaskData = newTask;
                taskProvider.AddTask(newTask);
            }
        }