public void BuildLogTest()
        {
            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }
            BuildLog.Debug("Test message", null);
            BuildLog.Debug("Test message with parameter {0}", new object[] { 1 });
            BuildLog.Debug(new Exception("Some exception"), "Test message with parameter {0}", new object[] { 1 });
            BuildLog.Debug("Test message", new object[] { 1 });
            BuildLog.Debug("Test message {0}", null);
            BuildLog.Debug(new Exception("Some exeption"));
            BuildLog.Debug(null, new object[] { 1 });

            BuildLog.Info("Test message", null);
            BuildLog.Info("Test message with parameter {0}", new object[] { 1 });
            BuildLog.Info(new Exception("Some exception"), "Test message with parameter {0}", new object[] { 1 });
            BuildLog.Info("Test message", new object[] { 1 });
            BuildLog.Info("Test message {0}", null);
            BuildLog.Info(new Exception("Some exeption"));
            BuildLog.Info(null, new object[] { 1 });

            BuildLog.Warning("Test message", null);
            BuildLog.Warning("Test message with parameter {0}", new object[] { 1 });
            BuildLog.Warning(new Exception("Some exception"), "Test message with parameter {0}", new object[] { 1 });
            BuildLog.Warning("Test message", new object[] { 1 });
            BuildLog.Warning("Test message {0}", null);
            BuildLog.Warning(new Exception("Some exeption"));
            BuildLog.Warning(null, new object[] { 1 });

            BuildLog.Error("Test message", null);
            BuildLog.Error("Test message with parameter {0}", new object[] { 1 });
            BuildLog.Error(new Exception("Some exception"), "Test message with parameter {0}", new object[] { 1 });
            BuildLog.Error("Test message", new object[] { 1 });
            BuildLog.Error("Test message {0}", null);
            BuildLog.Error(new Exception("Some exeption"));
            BuildLog.Error(null, new object[] { 1 });

            BuildLog.FatalError("Test message", null);
            BuildLog.FatalError("Test message with parameter {0}", new object[] { 1 });
            BuildLog.FatalError(new Exception("Some exception"), "Test message with parameter {0}", new object[] { 1 });
            BuildLog.FatalError("Test message", new object[] { 1 });
            BuildLog.FatalError("Test message {0}", null);
            BuildLog.FatalError(new Exception("Some exeption"));
            BuildLog.FatalError(null, new object[] { 1 });

            Assert.IsTrue(File.Exists(filePath));
            Assert.AreEqual(File.ReadAllLines(filePath).Count(), 35);
        }
Beispiel #2
0
        private void ProcessLazyLoad(FieldDef fieldDef, FieldAttribute attribute)
        {
            if (attribute.lazyLoad == null)
            {
                return;
            }

            if (!fieldDef.IsPrimitive && attribute.LazyLoad)
            {
                BuildLog.Warning(
                    Strings.LogExplicitLazyLoadAttributeOnFieldXIsRedundant, fieldDef.Name);
            }
            else
            {
                fieldDef.IsLazyLoad = attribute.LazyLoad;
            }
        }
Beispiel #3
0
        private void ProcessMappingName(MappedNode node, string mappingName, ValidationRule rule)
        {
            if (mappingName.IsNullOrEmpty())
            {
                return;
            }

            mappingName = context.NameBuilder.ApplyNamingRules(mappingName);

            context.Validator.ValidateName(mappingName, rule);

            if (Comparer.Equals(node.MappingName, mappingName))
            {
                BuildLog.Warning(Strings.ExplicitMappingNameSettingIsRedundantTheSameNameXWillBeGeneratedAutomatically, node.MappingName);
            }
            else
            {
                node.MappingName = mappingName;
            }
        }
        private void BuildClassTableIndexes(TypeInfo type)
        {
            if (type.Indexes.Count > 0)
            {
                return;
            }
            if (type.IsStructure)
            {
                return;
            }

            var root       = type.Hierarchy.Root;
            var typeDef    = context.ModelDef.Types[type.UnderlyingType];
            var ancestors  = type.GetAncestors().ToList();
            var interfaces = type.GetInterfaces();

            // Building declared indexes both secondary and primary (for root of the hierarchy only)
            foreach (var indexDescriptor in typeDef.Indexes)
            {
                // Skip indef building for inherited fields
                var hasInheritedFields = indexDescriptor.KeyFields
                                         .Select(kvp => type.Fields[kvp.Key])
                                         .Any(f => f.IsInherited);
                if (hasInheritedFields)
                {
                    continue;
                }
                var declaredIndex = BuildIndex(type, indexDescriptor, false);

                type.Indexes.Add(declaredIndex);
                context.Model.RealIndexes.Add(declaredIndex);
            }

            // Building primary index for non root entities
            var parent = type.GetAncestor();

            if (parent != null)
            {
                var parentPrimaryIndex = parent.Indexes.FindFirst(IndexAttributes.Primary | IndexAttributes.Real);
                var inheritedIndex     = BuildInheritedIndex(type, parentPrimaryIndex, false);

                type.Indexes.Add(inheritedIndex);
                context.Model.RealIndexes.Add(inheritedIndex);
            }

            // Building inherited from interfaces indexes
            foreach (var @interface in interfaces)
            {
                foreach (var interfaceIndex in @interface.Indexes.Find(IndexAttributes.Primary, MatchType.None))
                {
                    if (interfaceIndex.DeclaringIndex != interfaceIndex &&
                        parent != null &&
                        parent.Indexes.Any(i => i.DeclaringIndex == interfaceIndex))
                    {
                        continue;
                    }
                    if (type.Indexes.Any(i => i.DeclaringIndex == interfaceIndex))
                    {
                        continue;
                    }
                    var index = BuildInheritedIndex(type, interfaceIndex, false);
                    if (IndexBuiltOverInheritedFields(index))
                    {
                        BuildLog.Warning(string.Format(Strings.ExUnableToBuildIndexXBecauseItWasBuiltOverInheritedFields, index.Name));
                    }
                    else
                    {
                        type.Indexes.Add(index);
                        context.Model.RealIndexes.Add(index);
                    }
                }
            }

            // Build typed indexes
            if (type == root)
            {
                foreach (var realIndex in type.Indexes.Find(IndexAttributes.Real))
                {
                    if (!untypedIndexes.Contains(realIndex))
                    {
                        continue;
                    }
                    var typedIndex = BuildTypedIndex(type, realIndex);
                    type.Indexes.Add(typedIndex);
                }
            }

            // Build indexes for descendants
            foreach (var descendant in type.GetDescendants())
            {
                BuildClassTableIndexes(descendant);
            }

            // Import inherited indexes
            var primaryIndex = type.Indexes.FindFirst(IndexAttributes.Primary | IndexAttributes.Real);

            if (untypedIndexes.Contains(primaryIndex) && primaryIndex.ReflectedType == root)
            {
                primaryIndex = type.Indexes.Single(i => i.DeclaringIndex == primaryIndex.DeclaringIndex && i.IsTyped);
            }
            var filterByTypes = type.GetDescendants(true).Append(type).ToList();

            // Build virtual primary index
            if (ancestors.Count > 0)
            {
                var baseIndexes = new Stack <IndexInfo>();
                foreach (var ancestor in ancestors.Where(t => t.Fields.Any(f => !f.IsPrimaryKey && !f.IsTypeId && f.IsDeclared)))
                {
                    var ancestorIndex = ancestor.Indexes.Single(i => i.IsPrimary && !i.IsVirtual);
                    if (untypedIndexes.Contains(ancestorIndex) && ancestorIndex.ReflectedType == root)
                    {
                        ancestorIndex = ancestor.Indexes.Single(i => i.DeclaringIndex == ancestorIndex.DeclaringIndex && i.IsTyped);
                    }
                    if (ancestorIndex.ValueColumns.Count > 0)
                    {
                        baseIndexes.Push(ancestorIndex);
                    }
                }
                if (baseIndexes.Count > 0)
                {
                    if (primaryIndex.ValueColumns.Count > 0 && type.Fields.Any(f => !f.IsPrimaryKey && !f.IsTypeId && f.IsDeclared))
                    {
                        baseIndexes.Push(primaryIndex);
                    }
                    else
                    {
                        var ancestorIndex = baseIndexes.Pop();
                        var filteredIndex = BuildFilterIndex(type, ancestorIndex, filterByTypes);
                        baseIndexes.Push(filteredIndex);
                    }
                    var virtualPrimaryIndex = baseIndexes.Count == 1
            ? baseIndexes.Pop()
            : BuildJoinIndex(type, baseIndexes);
                    type.Indexes.Add(virtualPrimaryIndex);
                }
            }

            // Build virtual secondary index
            foreach (var ancestorIndex in ancestors.SelectMany(ancestor => ancestor.Indexes.Find(IndexAttributes.Primary | IndexAttributes.Virtual, MatchType.None)))
            {
                if (ancestorIndex.DeclaringIndex != ancestorIndex)
                {
                    continue;
                }
                var ancestorType  = ancestorIndex.ReflectedType;
                var indexToFilter = untypedIndexes.Contains(ancestorIndex) && ancestorIndex.ReflectedType == root
          ? ancestorType.Indexes.Single(i => i.DeclaringIndex == ancestorIndex.DeclaringIndex && i.IsTyped)
          : ancestorIndex;

                var virtualIndex = BuildFilterIndex(type, ancestorIndex, filterByTypes);
                type.Indexes.Add(virtualIndex);
            }
        }