/// <summary> /// Test if an error would normally be displayed but is currently hidden /// based on the current type-based filter state and the <see cref="ErrorState"/> /// of the error itself. /// </summary> /// <param name="error">The error to test.</param> /// <param name="filter">The filter to apply. Can be <see langword="null"/>.</param> /// <returns><see langword="true"/> if the error exists in a non-ignored state /// and the error type is allowed by the current filter.</returns> public static bool IsDisplayFiltered(ModelError error, ModelErrorDisplayFilter filter) { return(error != null && error.ErrorState != ModelErrorState.Ignored && (filter != null && filter.IsErrorExcluded(error.GetType()))); }
/// <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); }
private void SaveChanges() { ORMModel model = myModel; ModelErrorDisplayFilter filter = model.ModelErrorDisplayFilter; Store store = model.Store; using (Transaction t = store.TransactionManager.BeginTransaction(ResourceStrings.ModelErrorDisplayFilterChangeTransactionName)) { bool deleteFilter = true, anyChanges = false; Error[] errors = myErrors; Category[] categories = myCategories; foreach (Category category in categories) { bool allExcluded = true, allIncluded = true; if (category.FirstError == -1) { allExcluded = false; allIncluded = true; } else { for (int i = category.FirstError; i <= category.LastError; ++i) { Error error = errors[i]; if (error.IsExcluded != error.WasExcluded) { anyChanges = true; } if (error.IsExcluded) { deleteFilter = false; allIncluded = false; } else { allExcluded = false; } if (anyChanges && !deleteFilter && !allExcluded && !allIncluded) { break; } } } if (allIncluded) { category.IsExcluded = false; } else if (allExcluded) { category.IsExcluded = true; } } if (deleteFilter) { //if all errors are included, we can delete the filter anyChanges = true; if (filter != null) { filter.Delete(); } } else if (anyChanges) { if (filter == null) { filter = new ModelErrorDisplayFilter(store); filter.Model = model; } foreach (Category category in categories) { if (category.Type != null) { filter.ToggleCategory(category.Type, category.IsExcluded); } } foreach (Error error in errors) { filter.ToggleError(error.Type, error.IsExcluded); } filter.CommitChanges(); } if (anyChanges && t.HasPendingChanges) { t.Commit(); } } }