зеркало из https://github.com/microsoft/rudder.git
Avoid trying to create an instance of any processor which has a Finalize method. There is no way to guarantee that the method won't throw an exception and if it does, then the process is torn down because there's no way to catch it.
Don't bother trying to load the core assembly greedily --- not sure why that was ever there. Fix the caching of units so it actually can get used and avoid a possible bug by directly using the scopeRuntime assembly instead of searching all located units. The latter can cause an exception since the collection of loaded units can be modified.
This commit is contained in:
Родитель
63dc07d10a
Коммит
760f91a88b
|
@ -60,7 +60,7 @@ namespace ScopeProgramAnalysis.Framework
|
|||
PlatformTypes = host.PlatformType;
|
||||
|
||||
this.failedAssemblies = new HashSet<IAssemblyReference>();
|
||||
LoadCoreAssembly();
|
||||
//LoadCoreAssembly();
|
||||
|
||||
LoadRuntimeTypes(directory);
|
||||
}
|
||||
|
|
|
@ -909,7 +909,7 @@ namespace ScopeProgramAnalysis
|
|||
{
|
||||
try
|
||||
{
|
||||
var resultOfProducesMethod = ExecuteProducesMethod(factoryMethod, inputSchema);
|
||||
var resultOfProducesMethod = ExecuteProducesMethod(processorClass, factoryMethod, inputSchema);
|
||||
var declaredPassThroughDictionary = resultOfProducesMethod.Item1;
|
||||
declaredPassthroughString = String.Join("|", declaredPassThroughDictionary.Select(e => e.Key + " <: " + e.Value));
|
||||
var dependenceDictionary = resultOfProducesMethod.Item2;
|
||||
|
@ -1108,11 +1108,19 @@ namespace ScopeProgramAnalysis
|
|||
return r;
|
||||
}
|
||||
|
||||
private static Tuple<Dictionary<string, string>, Dictionary<string, string>> ExecuteProducesMethod(IMethodDefinition factoryMethod, Schema inputSchema)
|
||||
private static Tuple<Dictionary<string, string>, Dictionary<string, string>> ExecuteProducesMethod(ITypeDefinition processorClass, IMethodDefinition factoryMethod, Schema inputSchema)
|
||||
{
|
||||
var sourceDictionary = new Dictionary<string, string>();
|
||||
var dependenceDictionary = new Dictionary<string, string>();
|
||||
|
||||
var processorAssembly = System.Reflection.Assembly.LoadFrom(TypeHelper.GetDefiningUnitReference(processorClass).ResolvedUnit.Location);
|
||||
if (processorAssembly == null) { sourceDictionary.Add("666", "no processorAssembly"); goto L; }
|
||||
var processorClass2 = processorAssembly.GetType(TypeHelper.GetTypeName(processorClass, NameFormattingOptions.UseReflectionStyleForNestedTypeNames));
|
||||
if (processorClass2 == null) { sourceDictionary.Add("666", "no processorClass2"); goto L; }
|
||||
var finalizeMethod = processorClass2.GetMethod("Finalize", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance);
|
||||
if (finalizeMethod != null) { sourceDictionary.Add("666", "Finalize() method found for processor: " + TypeHelper.GetTypeName(processorClass)); goto L; }
|
||||
|
||||
|
||||
if (factoryMethod == null) { sourceDictionary.Add("666", "no factoryMethod"); goto L; }
|
||||
// Call the factory method to get an instance of the processor.
|
||||
var factoryClass = factoryMethod.ContainingType;
|
||||
|
|
|
@ -35,11 +35,9 @@ namespace RuntimeLoader
|
|||
/// Inspired in Zvonimir code
|
||||
/// </summary>
|
||||
/// <param name="host"></param>
|
||||
public static void InitializeScopeTypes(IMetadataHost host)
|
||||
public static void InitializeScopeTypes(IMetadataHost host, IAssembly scopeRuntime)
|
||||
{
|
||||
var scopeAssembly = host.LoadedUnits.OfType<IModule>()
|
||||
.Single(module => module.ContainingAssembly.NamespaceRoot.Members.Any(m => m.Name.Value == "ScopeRuntime"));
|
||||
foreach (var type in scopeAssembly.GetAllTypes())
|
||||
foreach (var type in scopeRuntime.GetAllTypes())
|
||||
{
|
||||
if (type.FullName() == "ScopeRuntime.Reducer") Reducer = type;
|
||||
else if (type.FullName() == "ScopeRuntime.Processor") Processor = type;
|
||||
|
@ -113,7 +111,7 @@ namespace RuntimeLoader
|
|||
var t = LoadAssembly(path2);
|
||||
var scopeRuntime = t;
|
||||
|
||||
ScopeTypes.InitializeScopeTypes(host);
|
||||
ScopeTypes.InitializeScopeTypes(host, scopeRuntime);
|
||||
cachedScopeRuntime = scopeRuntime;
|
||||
}
|
||||
|
||||
|
@ -121,10 +119,10 @@ namespace RuntimeLoader
|
|||
}
|
||||
public IAssembly LoadAssembly(string fileName)
|
||||
{
|
||||
var unit = host.LoadedUnits.SingleOrDefault(u => u.Location == fileName);
|
||||
var unit = host.LoadedUnits.SingleOrDefault(u => Path.GetFileName(u.Location) == fileName);
|
||||
if (unit != null)
|
||||
{
|
||||
return unit as IAssembly;
|
||||
return (IAssembly) unit;
|
||||
}
|
||||
|
||||
var module = host.LoadUnitFrom(fileName) as IModule;
|
||||
|
|
Загрузка…
Ссылка в новой задаче