Esempio n. 1
0
        public TargetMethodMatch IsDatabaseAccess(MethodCall method, MethodObject currentMethod)
        {
            if (_isEntityFrameworkDict.Contains(currentMethod.GetMethodDefinition().FullName))
            {
                return(GetMatch("EntityFramework"));
            }

            if (UsesEntityFramework(currentMethod))
            {
                _isEntityFrameworkDict.Add(currentMethod.GetMethodDefinition().FullName);
                return(GetMatch("EntityFramework"));
            }

            return(GetNoMatch());
        }
Esempio n. 2
0
        private bool IsNonPublicInnerAssemblyCall(MethodNode rootMethod, MethodObject calledMethod, int depth)
        {
            if (depth == 1)
            {
                return(false);
            }

            var calledMethodDefinition = calledMethod.GetMethodDefinition();

            // if the method called is not public then return false
            if (calledMethodDefinition.IsPublic && calledMethodDefinition.DeclaringType.IsPublic)
            {
                return(false);
            }

            return(IsInnerAssemblyCall(rootMethod, calledMethod, calledMethodDefinition));
        }
Esempio n. 3
0
        private MethodNode GetMethodNode(GraphType graphType, string appDomain, MethodObject method)
        {
            var methodDef = method.GetMethodDefinition();

            var methodNode = new MethodNode(graphType, appDomain);

            methodNode.MethodName = SignatureKeyService.GetMethodSignature(methodDef);
            methodNode.IsPublic   = methodDef.IsPublic && methodDef.DeclaringType.IsPublic;

            if (method.HasImplementation())
            {
                methodNode.ConcreteType = new TypeInfo();
                methodNode.ConcreteType.AssemblyName    = method.ConcreteMethod.DeclaringType.Module.Assembly.Name.Name;
                methodNode.ConcreteType.AssemblyVersion = GetAssemblyVersion(method.ConcreteMethod);
                methodNode.ConcreteType.TypeName        = method.ConcreteMethod.DeclaringType.FullName;
            }
            else
            {
            }

            if (method.HasInterface())
            {
                methodNode.InterfaceType = new TypeInfo();
                methodNode.InterfaceType.AssemblyName    = method.InterfaceMethod.DeclaringType.Module.Assembly.Name.Name;
                methodNode.InterfaceType.AssemblyVersion = GetAssemblyVersion(method.InterfaceMethod);
                methodNode.InterfaceType.TypeName        = method.InterfaceMethod.DeclaringType.FullName;
            }

            if (method.HasAbstract())
            {
                methodNode.AbstractType = new TypeInfo();
                methodNode.AbstractType.AssemblyName    = method.AbstractMethod.DeclaringType.Module.Assembly.Name.Name;
                methodNode.AbstractType.AssemblyVersion = GetAssemblyVersion(method.AbstractMethod);
                methodNode.AbstractType.TypeName        = method.AbstractMethod.DeclaringType.FullName;
            }

            if (method.OverridesBaseClass())
            {
                methodNode.BaseClassType = new TypeInfo();
                methodNode.BaseClassType.AssemblyName    = method.VirtualMethod.DeclaringType.Module.Assembly.Name.Name;
                methodNode.BaseClassType.AssemblyVersion = GetAssemblyVersion(method.VirtualMethod);
                methodNode.BaseClassType.TypeName        = method.VirtualMethod.DeclaringType.FullName;
            }

            return(methodNode);
        }
        public string FindDatabaseName(TargetMethodMatch targetMethodMatch, MethodCall methodCall, MethodObject currentMethod, IAssignmentGraphWalker assignmentGraphWalker)
        {
            if (!_lastLoadedForApp.Equals(AnalysisScope.CurrentApplicationName))
            {
                IndexAppConfig();
                _lastLoadedForApp = AnalysisScope.CurrentApplicationName;
            }

            var assemblyName = currentMethod.GetMethodDefinition().Module.Assembly.Name.Name;

            // strategy 1 - if application accesses only one db, then choose that
            var appDbs = GetConnectionStrings(AnalysisScope.CurrentApplicationName);

            if (appDbs.Indexes.Count() == 1)
            {
                var indexedDb = appDbs.IndexValues.First();
                return(indexedDb.First()); // TODO: if multiple app.configs contains the same db, then here you might want to choose which one you want
            }

            // strategy 2 - if the assembly has an app config with only 1 connection string
            var assDbs = GetConnectionStrings(assemblyName);

            if (assDbs.Indexes.Count() == 1)
            {
                var indexedDb = assDbs.IndexValues.First();
                return(indexedDb.First()); // TODO: if multiple app.configs contains the same db, then here you might want to choose which one you want
            }

            // strategy 3 - if the database access is ADO.NET then use backtracking search to find the conn string name
            if (targetMethodMatch.AccessMode.IndexOf("ado.net", StringComparison.OrdinalIgnoreCase) > -1)
            {
                var matches = PerformAdoNetBacktrackingSearch(methodCall, assignmentGraphWalker);
                if (matches.Count == 1)
                {
                    return(matches.First());
                }
            }

            // strategy 4 - if EF then find the ctor of the context and do a backtracking search from there
            // TODO

            // there are multiple possible matches or none at all
            return("Unknown");
        }
Esempio n. 5
0
        private bool IsCrossAssemblyCall(MethodNode rootMethod, MethodObject calledMethod, int depth)
        {
            if (depth == 1)
            {
                return(false);
            }

            var calledMethodDefinition = calledMethod.GetMethodDefinition();

            if (!calledMethodDefinition.IsPublic && !calledMethodDefinition.DeclaringType.IsPublic)
            {
                return(false);
            }

            if (calledMethod.GetMethodType() == MethodType.ImplAndInterface)
            {
                if (calledMethod.ConcreteMethod.DeclaringType.Module.Assembly.Name.Name.Equals(rootMethod.ConcreteType.AssemblyName))
                {
                    return(false);
                }
            }
            else if (calledMethod.GetMethodType() == MethodType.InterfaceOnly)
            {
                if (calledMethod.InterfaceMethod.DeclaringType.Module.Name.Equals(rootMethod.ConcreteType.AssemblyName))
                {
                    return(false);
                }
            }
            else
            {
                if (calledMethod.ConcreteMethod.DeclaringType.Module.Assembly.Name.Name.Equals(rootMethod.ConcreteType.AssemblyName))
                {
                    return(false);
                }
            }

            if (!Regex.IsMatch(calledMethodDefinition.DeclaringType.Namespace, _companyAssembliesPattern))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 6
0
        private bool IsNoteworthyMethodCall(MethodObject calledMethod)
        {
            var calledMethodDefinition = calledMethod.GetMethodDefinition();

            if (calledMethodDefinition.IsGetter)
            {
                return(IsNoteworthyProperty(calledMethodDefinition));
            }
            else if (calledMethodDefinition.IsSetter)
            {
                return(false);
            }
            else if (calledMethodDefinition.IsConstructor)
            {
                var isNoteworthyConstructor = calledMethod.MethodsCalled.Any(x => !x.MethodCalled.DeclaringType.Module.Name.Equals(calledMethod.GetMethodDefinition().DeclaringType.Module.Name) &&
                                                                             !Regex.IsMatch(x.MethodCalled.DeclaringType.Module.Name, _companyAssembliesPattern));

                return(isNoteworthyConstructor);
            }


            return(true);
        }