コード例 #1
0
        private void LoadCategories()
        {
            ModelErrorDisplayFilter filter = myModel.ModelErrorDisplayFilter;

            DomainDataDirectory dataDirectory = myModel.Store.DomainDataDirectory;
            DomainClassInfo     baseType      = dataDirectory.GetDomainClass(typeof(ModelErrorCategory));
            ReadOnlyCollection <DomainClassInfo> categoryDescendants = baseType.AllDescendants;

            int numCategories = categoryDescendants.Count;

            Category[] categories = new Category[numCategories + 1];
            categories[numCategories] = new Category(null, false);
            for (int i = 0; i < numCategories; ++i)
            {
                DomainClassInfo info         = categoryDescendants[i];
                Type            categoryType = info.ImplementationClass;
                categories[i] = new Category(info, filter != null && filter.IsCategoryExcluded(categoryType));
            }

            // Presort the categories list
            Category.Sort(categories);

            baseType = dataDirectory.GetDomainClass(typeof(ModelError));
            ReadOnlyCollection <DomainClassInfo> errorDescendants = baseType.AllDescendants;
            int errorDescendantCount = errorDescendants.Count;
            int includedErrorCount   = 0;

            for (int i = 0; i < errorDescendantCount; ++i)
            {
                if (!errorDescendants[i].ImplementationClass.IsAbstract)
                {
                    ++includedErrorCount;
                }
            }

            Error[] errors             = new Error[includedErrorCount];
            int     includedErrorIndex = -1;

            for (int i = 0; i < errorDescendantCount; ++i)
            {
                DomainClassInfo info  = errorDescendants[i];
                Type            error = info.ImplementationClass;
                if (!error.IsAbstract)
                {
                    ++includedErrorIndex;
                    errors[includedErrorIndex] = new Error(
                        info,
                        Category.IndexOf(categories, ResolveErrorCategory(error)),
                        filter != null && filter.IsErrorExcluded(error));
                }
            }

            // Sort the errors with a primary sort on the presorted category index
            Array.Sort(errors,
                       delegate(Error error1, Error error2)
            {
                int retVal         = 0;
                int categoryIndex1 = error1.CategoryIndex;
                int categoryIndex2 = error2.CategoryIndex;
                if (categoryIndex1 < categoryIndex2)
                {
                    retVal = -1;
                }
                else if (categoryIndex1 > categoryIndex2)
                {
                    retVal = 1;
                }
                else
                {
                    retVal = string.Compare(error1.DisplayName, error2.DisplayName, StringComparison.CurrentCultureIgnoreCase);
                }
                return(retVal);
            });

            // Walk the errors and bind the categories to the errors
            int currentCategoryStartErrorIndex = -1;
            int lastCategoryIndex = -1;

            for (int i = 0; i < includedErrorCount; ++i)
            {
                int currentIndex = errors[i].CategoryIndex;
                if (currentIndex != lastCategoryIndex)
                {
                    if (lastCategoryIndex == -1)
                    {
                        lastCategoryIndex = currentIndex;
                        currentCategoryStartErrorIndex = i;
                    }
                    else
                    {
                        categories[lastCategoryIndex].BindErrorRange(currentCategoryStartErrorIndex, i - 1);
                        currentCategoryStartErrorIndex = i;
                        lastCategoryIndex = currentIndex;
                    }
                }
            }
            if (lastCategoryIndex != -1)
            {
                categories[lastCategoryIndex].BindErrorRange(currentCategoryStartErrorIndex, includedErrorCount - 1);
            }
            myCategories = categories;
            myErrors     = errors;
        }
コード例 #2
0
 void IORMModelErrorActivationService.RegisterErrorActivator(Type elementType, bool registerDerivedTypes, ORMModelErrorActivator activator)
 {
     if (registerDerivedTypes)
     {
         DomainDataDirectory dataDirectory = myStore.DomainDataDirectory;
         RegisterErrorActivator(elementType.IsSubclassOf(typeof(ElementLink)) ? dataDirectory.GetDomainRelationship(elementType) : dataDirectory.GetDomainClass(elementType), activator);
     }
     else
     {
         myActivators[elementType] = activator;
     }
 }