Ejemplo n.º 1
0
 private void FindIndirectCallersOfSP2010LoggingAPI(Method method)
 {
     MetadataCollection <Method> .Enumerator enumerator = CallGraph.CallersFor(method).GetEnumerator();
     while (enumerator.MoveNext())
     {
         Method current = enumerator.Current;
         this.FindIndirectCallersOfSP2010LoggingAPI(current);
     }
     if (!(this.methodsThatCallSP2010SPDiagnosticsServiceWriteTraceDirectly.ContainsKey(this.GetOnlyTheMethodName(method.FullName)) || this.methodsThatCallSP2010SPDiagnosticsServiceWriteTraceIndirectly.ContainsKey(this.GetOnlyTheMethodName(method.FullName))))
     {
         this.methodsThatCallSP2010SPDiagnosticsServiceWriteTraceIndirectly.Add(this.GetOnlyTheMethodName(method.FullName), method);
     }
 }
Ejemplo n.º 2
0
 private void FindIndirectCallersOfUnsupportedMethod(Method method)
 {
     MetadataCollection <Method> .Enumerator enumerator = CallGraph.CallersFor(method).GetEnumerator();
     while (enumerator.MoveNext())
     {
         Method current = enumerator.Current;
         this.FindIndirectCallersOfUnsupportedMethod(current);
     }
     if (!(this.methodsThatCallUnsupportedMethodsDirectly.ContainsKey(this.GetOnlyTheMethodName(method.FullName)) || this.methodsThatCallUnsupportedMethodsIndirectly.ContainsKey(this.GetOnlyTheMethodName(method.FullName))))
     {
         this.methodsThatCallUnsupportedMethodsIndirectly.Add(this.GetOnlyTheMethodName(method.FullName), method);
     }
 }
Ejemplo n.º 3
0
 private void FindCallersOfTraceEventAPI(Method method)
 {
     MetadataCollection <Method> .Enumerator enumerator = CallGraph.CallersFor(method).GetEnumerator();
     while (enumerator.MoveNext())
     {
         Method current = enumerator.Current;
         this.FindCallersOfTraceEventAPI(current);
     }
     if (!this.methodsThatCallOneOfTraceEventMethods.ContainsKey(this.GetOnlyTheMethodName(method.FullName)))
     {
         this.methodsThatCallOneOfTraceEventMethods.Add(this.GetOnlyTheMethodName(method.FullName), method);
     }
 }
Ejemplo n.º 4
0
    public bool ShouldCheckMethod(Method method)
    {
        Queue <Method> MethodsToCheck = new Queue <Method>();
        List <Method>  MethodsChecked = new List <Method>();

        MethodsToCheck.Enqueue(method);
        while (MethodsToCheck.Count != 0)
        {
            Method MethodToCheck = MethodsToCheck.Dequeue();
            if (!MethodsChecked.Contains(MethodToCheck) && MethodToCheck != null)
            {
                /*if (IsSubClassOf(MethodToCheck.DeclaringType, "Microsoft.Xna.Framework.Game") &&
                 *  MethodsToCheckNames.Contains(MethodToCheck.Name.Name))
                 * {
                 *  return true;
                 * }*/
                foreach (var attribute in MethodToCheck.Attributes.Union(MethodToCheck.DeclaringType.Attributes))
                {
                    if (attribute.Type != null &&
                        attribute.Type.FullName == "GridEngine.Components.Debugging.Attributes.FxCop.PerformanceCriticalAttribute")
                    {
                        return(true);
                    }
                }
                // Add methods up the class tree
                MethodsToCheck.Enqueue(MethodToCheck.OverriddenMethod);
                MethodsToCheck.Enqueue(MethodToCheck.HiddenMethod);

                // Add calling methods
                foreach (var CallingMethod in CallGraph.CallersFor(MethodToCheck))
                {
                    MethodsToCheck.Enqueue(CallingMethod);
                }
            }
            MethodsChecked.Add(MethodToCheck);
        }
        return(false);
    }
Ejemplo n.º 5
0
        public override ProblemCollection Check(TypeNode type)
        {
            Debug.WriteLine("Checking type:" + type.FullName);
            var initializer = type.Members.OfType <Method>().FirstOrDefault(x => x.FullName == type.FullName + ".InitializeComponent");

            if (initializer == null)
            {
                return(null);
            }
            Debug.WriteLine(initializer.FullName);
            var constructorsWithNoInitCall = type.Members.OfType <Method>().Where(m => m.NodeType == NodeType.InstanceInitializer).ToList();
            var visitedMethods             = new HashSet <string>();
            var foundMethods = new ObservableHashSet <Method>();


            var whenMethodsFound = Observable.FromEvent <NotifyCollectionChangedEventArgs>(foundMethods, "CollectionChanged")
                                   .Where(e => e.EventArgs.Action == NotifyCollectionChangedAction.Add &&
                                          constructorsWithNoInitCall.Any());



            whenMethodsFound.Subscribe(e => Parallel.ForEach(e.EventArgs.NewItems.OfType <Method>()
                                                             .Where(m => !visitedMethods.Any(v => v == m.FullName)),
                                                             i =>
            {
                lock (visitedMethods)
                {
                    if (visitedMethods.Contains(i.FullName))
                    {
                        return;
                    }
                    visitedMethods.Add(i.FullName);
                }
                Debug.WriteLine("Visiting:" + i.FullName);
                var callers = (CallGraph.CallersFor(i));
                constructorsWithNoInitCall.RemoveAll(x => callers.Any(c => x.FullName == c.FullName));
                if (constructorsWithNoInitCall.Any())
                {
                    foreach (var item in callers.Where(c => visitedMethods.Any(v => v == c.FullName) == false))
                    {
                        foundMethods.Add(item);
                    }
                }
            }));


            //e =>
            //{
            //                Parallel.ForEach(e.EventArgs.NewItems.OfType<Method>()
            //                                    .Where(m => !visitedMethods.Any(v => v == m.FullName) ),
            //                    i =>
            //                    {

            //                        lock (visitedMethods)
            //                        {
            //                            if (visitedMethods.Contains(i.FullName))
            //                                return;
            //                            visitedMethods.Add(i.FullName);

            //                        }
            //                        Debug.WriteLine("Visiting:" + i.FullName);
            //                        var callers = (CallGraph.CallersFor(i));
            //                        constructorsWithNoInitCall.RemoveAll(x => callers.Any(c => x.FullName == c.FullName));
            //                        if (constructorsWithNoInitCall.Any())
            //                            foreach (var item in callers.Where(c => visitedMethods.Any(v => v == c.FullName) == false))
            //                            {
            //                                foundMethods.Add(item);
            //                            }
            //                    });
            //));



            foundMethods.Add(initializer);

            //whenMethodsFound.Run();

            //_currentType=type;
            ReportProblem(constructorsWithNoInitCall, type);

            return(Problems);
        }