public override void Execute() { base.Execute(); if (!IsValid) { Help(); return; } if (ExtractAndValidateTypeQuery(myParsedArgs.TypeAndInnerQuery) == false) { return; } List <MethodDefinition> methodsToSearch = new List <MethodDefinition>(); Writer.SetCurrentSheet(mySearchHeader); LoadAssemblies(myParsedArgs.Queries1, (cecilAssembly, file) => { using (PdbInformationReader pdbReader = new PdbInformationReader(myParsedArgs.SymbolServer)) { foreach (var type in myTypeQueries.GetMatchingTypes(cecilAssembly)) { myMethodQuery.GetMethods(type).ForEach( (method) => { var fileLine = pdbReader.GetFileLine(method); Writer.PrintRow("{0,-60}; {1,-100}; {2}; {3}", () => GetFileInfoWhenEnabled(fileLine.Key), type.Print(), method.Print(MethodPrintOption.Full), Path.GetFileName(file), fileLine.Key ); lock (methodsToSearch) { methodsToSearch.Add(method); } }); } } }); if (methodsToSearch.Count == 0) { Out.WriteLine("Error: No methods to query found. Aborting query."); return; } Writer.PrintRow("", null); Writer.PrintRow("", null); Writer.SetCurrentSheet(myResultHeader); LoadAssemblies(myParsedArgs.Queries2, (cecilAssembly, file) => { using (UsageQueryAggregator aggregator = new UsageQueryAggregator(myParsedArgs.SymbolServer)) { new WhoUsesMethod(aggregator, methodsToSearch); aggregator.Analyze(cecilAssembly); aggregator.MethodMatches.ForEach((result) => { Writer.PrintRow("{0,-60};{1,-100}; {2}; {3}; {4}; {5}", () => GetFileInfoWhenEnabled(result.SourceFileName), result.Match.DeclaringType.FullName, result.Match.Print(MethodPrintOption.Full), result.Annotations.Item, Path.GetFileName(file), result.SourceFileName, result.LineNumber ); }); } }); }
public override void Execute() { base.Execute(); if (!IsValid) { Help(); return; } if (ExtractAndValidateTypeQuery(myParsedArgs.TypeAndInnerQuery) == false) { return; } List <EventDefinition> eventsToSearch = new List <EventDefinition>(); Writer.SetCurrentSheet(mySearchHeader); LoadAssemblies(myParsedArgs.Queries1, (cecilAssembly, file) => { using (PdbInformationReader pdbreader = new PdbInformationReader(myParsedArgs.SymbolServer)) { foreach (var type in myTypeQueries.GetMatchingTypes(cecilAssembly)) { myEventQuery.GetMatchingEvents(type).ForEach( (ev) => { var fileLine = pdbreader.GetFileLine((TypeDefinition)ev.DeclaringType); Writer.PrintRow("{0,-70}; {1,-40}; {2}; {3}", () => GetFileInfoWhenEnabled(fileLine.Key), type.Print(), ev.Print(), Path.GetFileName(file), fileLine.Key ); lock (eventsToSearch) { eventsToSearch.Add(ev); } }); } } }); if (eventsToSearch.Count == 0) { Out.WriteLine("Error: No events to query found. Aborting query."); return; } Writer.PrintRow("", null); Writer.PrintRow("", null); if (myParsedArgs.EventSubscriptionImbalance == true) { SearchForImablancedEventSubscriptions(eventsToSearch); } else { Writer.SetCurrentSheet(myResultHeader); LoadAssemblies(myParsedArgs.Queries2, (cecilAssembly, file) => { using (UsageQueryAggregator aggregator = new UsageQueryAggregator(myParsedArgs.SymbolServer)) { new WhoUsesEvents(aggregator, eventsToSearch); aggregator.Analyze(cecilAssembly); aggregator.MethodMatches.ForEach((result) => { Writer.PrintRow("{0,-80}; {1,-40}; {2}; {3}; {4}; {5}; {6}", () => GetFileInfoWhenEnabled(result.SourceFileName), result.Match.DeclaringType.FullName, result.Match.Print(MethodPrintOption.Full), Path.GetFileName(file), result.Annotations.Reason, result.Annotations.Item, result.SourceFileName, result.LineNumber ); }); } }); } }
public override void Execute() { base.Execute(); if (!IsValid) { Out.WriteLine("Expected: ApiChange -whousesType [typeQuery] [files] -in [files]"); Help(); return; } var typeQueries = TypeQuery.GetQueries(myParsedArgs.TypeQuery, TypeQueryMode.All); List <TypeDefinition> searchTypes = new List <TypeDefinition>(); Writer.SetCurrentSheet(mySearchHeader); LoadAssemblies(myParsedArgs.Queries1, (cecilAssembly, file) => { using (var pdbReader = new PdbInformationReader(myParsedArgs.SymbolServer)) { foreach (TypeDefinition matchingType in typeQueries.GetMatchingTypes(cecilAssembly)) { var fileline = pdbReader.GetFileLine(matchingType); lock (this) { Writer.PrintRow("{0}; {1}; {2}", () => GetFileInfoWhenEnabled(fileline.Key), matchingType.Print(), Path.GetFileName(file), fileline.Key); searchTypes.Add(matchingType); } } } }); if (searchTypes.Count == 0) { Out.WriteLine("Error: Could not find any matching types to search for. Aborting"); return; } Writer.SetCurrentSheet(myResultHeader); LoadAssemblies(myParsedArgs.Queries2, (cecilAssembly, file) => { using (UsageQueryAggregator agg = new UsageQueryAggregator(myParsedArgs.SymbolServer)) { new WhoUsesType(agg, searchTypes); string fileName = Path.GetFileName(file); agg.Analyze(cecilAssembly); /* * "Assembly" "Type", "Method" "Field" "Match Reason" "Match Item" * "Source File" "Line" */ lock (this) { foreach (var match in agg.MethodMatches) { Writer.PrintRow("{0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}", () => GetFileInfoWhenEnabled(match.SourceFileName), fileName, ((TypeDefinition)match.Match.DeclaringType).Print(), match.Match.Print(MethodPrintOption.Full), "", match.Annotations.Reason, match.Annotations.Item, match.SourceFileName, match.LineNumber); } foreach (var match in agg.TypeMatches) { Writer.PrintRow("{0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}", () => GetFileInfoWhenEnabled(match.SourceFileName), fileName, match.Match.Print(), "", "", match.Annotations.Reason, match.Annotations.Item, match.SourceFileName, ""); } foreach (var match in agg.FieldMatches) { Writer.PrintRow("{0}; {1}; {2}; {3}; {4}; {5}; {6}; {7}", () => GetFileInfoWhenEnabled(match.SourceFileName), fileName, ((TypeDefinition)match.Match.DeclaringType).Print(), "", match.Match.Print(FieldPrintOptions.All), match.Annotations.Reason, match.Annotations.Item, match.SourceFileName, ""); } } } }); }
public override void Execute() { base.Execute(); if (!IsValid) { Help(); return; } if (ExtractAndValidateTypeQuery(myParsedArgs.TypeAndInnerQuery) == false) { return; } List <FieldDefinition> fieldsToSearch = new List <FieldDefinition>(); Writer.SetCurrentSheet(mySearchHeader); LoadAssemblies(myParsedArgs.Queries1, (cecilAssembly, file) => { using (PdbInformationReader pdbReader = new PdbInformationReader(myParsedArgs.SymbolServer)) { foreach (var type in myTypeQueries.GetMatchingTypes(cecilAssembly)) { myFieldQuery.GetMatchingFields(type).ForEach( (field) => { var fileLine = pdbReader.GetFileLine((TypeDefinition)field.DeclaringType); Writer.PrintRow( "{0,-80}; {1,-50}; {2}; {3}", () => GetFileInfoWhenEnabled(fileLine.Key), type.Print(), field.Print(FieldPrintOptions.All), Path.GetFileName(file), fileLine.Key ); lock (this) { fieldsToSearch.Add(field); } }); } } }); List <FieldDefinition> nonConstFields = (from field in fieldsToSearch where !field.HasConstant select field).ToList(); if (nonConstFields.Count < fieldsToSearch.Count) { Out.WriteLine("Warning: It is not possible to track the usage of constant fields. Only non constant fields are considered in the search."); Out.WriteLine(" The only secure way is to search the source code for the constant field/s in question."); } if (nonConstFields.Count == 0) { Out.WriteLine("Error: No non constant fields are found which usage could be tracked"); } Writer.PrintRow("", null); Writer.PrintRow("", null); Writer.SetCurrentSheet(myResultHeader); LoadAssemblies(myParsedArgs.Queries2, (cecilAssembly, file) => { using (UsageQueryAggregator agg = new UsageQueryAggregator(myParsedArgs.SymbolServer)) { new WhoAccessesField(agg, nonConstFields); agg.Analyze(cecilAssembly); agg.MethodMatches.ForEach((result) => { Writer.PrintRow("{0,-80};{1,-40}; {2}; {3}; {4}; {5}; {6}", () => GetFileInfoWhenEnabled(result.SourceFileName), result.Match.DeclaringType.FullName, result.Match.Print(MethodPrintOption.Full), Path.GetFileName(file), result.Annotations.Reason, result.Annotations.Item, result.SourceFileName, result.LineNumber ); }); } }); }