Example #1
0
        private void RegisterLoadedAssemblySimpleNameNoLock(Assembly assembly, string locationOpt)
        {
            var identity = AssemblyIdentity.FromAssemblyDefinition(assembly);
            var info     = new LoadedAssemblyInfo(assembly, identity, locationOpt);

            if (_loadedAssembliesBySimpleName.TryGetValue(identity.Name, out var existingInfos))
            {
                existingInfos.Add(info);
            }
            else
            {
                _loadedAssembliesBySimpleName.Add(identity.Name, new List <LoadedAssemblyInfo> {
                    info
                });
            }
        }
Example #2
0
        private void PreLoadAssembliesToPreventAssemblyNotFoundError(FileInfo[] assemblyFiles)
        {
            //TODO: Preloading all assemblies in the solution is BRUTE FORCE! Should separate discovery of recipes
            //      from invocation. Perhpas use LoadForReflection during discovery. We'd then need to have
            //      Assemblies loaded for real before invokation (see TaskRunner), along with satellite assemblies.

            foreach (var file in assemblyFiles)
                //loading the core twice is BAD because "if(blah is RecipeAttribute)" etc will always fail
                if( ! file.Name.StartsWith("Golem.Core") && ! LoadedAssemblies.Any(la=>la.File.Name == file.Name))
                {
                    try
                    {
                        var i =  new LoadedAssemblyInfo
                                {
                                    Assembly = Assembly.LoadFrom(file.FullName),
                                    File = file
                                };
                        _loadedAssemblies.Add(i);
                    }
                    catch (Exception e)
                    {
                        //Console.WriteLine("Ooops: " + e.Message);
                    }
                }
        }
Example #3
0
        private void ExtractRecipesFromType(Type type, LoadedAssemblyInfo la)
        {
            if (!typeof(RecipeBase).IsAssignableFrom(type)) return;
            if (type.IsAbstract) return;

            //create recipe details from attribute
            Recipe recipe = CreateRecipeForType(type);

            //associate recipe with assembly
            la.FoundRecipes.Add(recipe);

            //trawl through and add the tasks
            AddTasksToRecipe(type, recipe);
        }
        private void RegisterLoadedAssemblySimpleNameNoLock(Assembly assembly, string locationOpt)
        {
            var identity = AssemblyIdentity.FromAssemblyDefinition(assembly);
            var info = new LoadedAssemblyInfo(assembly, identity, locationOpt);

            List<LoadedAssemblyInfo> existingInfos;
            if (_loadedAssembliesBySimpleName.TryGetValue(identity.Name, out existingInfos))
            {
                existingInfos.Add(info);
            }
            else
            {
                _loadedAssembliesBySimpleName.Add(identity.Name, new List<LoadedAssemblyInfo> { info });
            }
        }
Example #5
0
        private void ExtractRecipesFromType(Type type, LoadedAssemblyInfo la)
        {
            //find the attribute on the assembly if there is one
            var recipeAtt = GetRecipeAttributeOrNull(type);

            //if not found, return
            if (recipeAtt == null) return;

            //create recipe details from attribute
            Recipe recipe = CreateRecipeFromAttribute(type, recipeAtt);

            //associate recipe with assembly
            la.FoundRecipes.Add(recipe);

            //trawl through and add the tasks
            AddTasksToRecipe(type, recipe);
        }
Example #6
0
        private IDictionary <AssemblyName, Assembly> LoadDependenciesRecursively(
            LoadedAssemblyInfo loadedAssembly
            )
        {
            var assemblies = this._assembliesByOriginalPath;

            var assembliesToProcess = new List <LoadedAssemblyInfo>
            {
                loadedAssembly
            };
            var addedThisRound = new List <LoadedAssemblyInfo>();
            var loadedDeps     = new Dictionary <AssemblyName, Assembly>(
                ComparerFromFunctions.NewEqualityComparer <AssemblyName>(
                    (a1, a2) => ReferenceEquals(a1, a2) || (a1 != null && a2 != null && String.Equals(a1.Name, a2.Name) && String.Equals(a1.CultureName, a2.CultureName) && a1.Version.Equals(a2.Version) && ArrayEqualityComparer <Byte> .ArrayEquality(a1.GetPublicKey(), a2.GetPublicKey())),
                    a => a.Name.GetHashCodeSafe()
                    )
                );

            do
            {
                addedThisRound.Clear();

                foreach (var loadedInfo in assembliesToProcess)
                {
                    foreach (var aRef in loadedInfo.Assembly.GetReferencedAssemblies())
                    {
                        var curRef       = aRef;
                        var oldCount     = assemblies.Count;
                        var originalPath = loadedInfo.OriginalPath;
                        var assemblyPath = this.GetFirstExistingAssemblyPath(originalPath, curRef);

                        // We *must* use loading by assembly name here - otherwise we end up with multiple loaded assemblies with the same assembly name!
                        Assembly curAssembly = null;
                        try
                        {
                            curAssembly = this.LoadAssemblyReference(
                                originalPath,
                                curRef
                                );
                        }
                        catch
                        {
                            // Ignore
                            loadedDeps.Add(aRef, null);
                        }

                        if (curAssembly != null && System.IO.File.Exists(assemblyPath))
                        {
                            var newCount = assemblies.Count;

                            if (newCount > oldCount)
                            {
                                addedThisRound.Add(this._assembliesByOriginalPath[assemblyPath]);
                                loadedDeps.Add(aRef, curAssembly);
                            }
                        }
                    }
                }

                assembliesToProcess.Clear();
                assembliesToProcess.AddRange(addedThisRound);
            } while (addedThisRound.Count > 0);

            return(loadedDeps);
        }