public void AddWorkItemModelTransformer(SarifWorkItemModelTransformer workItemModelTransformer)
        {
            StringSet assemblies             = this.GetProperty(PluginAssemblyLocations);
            StringSet assemblyQualifiedNames = this.GetProperty(PluginAssemblyQualifiedNames);

            string assemblyLocation      = workItemModelTransformer.GetType().Assembly.Location;
            string assemblyQualifiedName = workItemModelTransformer.GetType().AssemblyQualifiedName;

            assemblies.Add(assemblyLocation);
            assemblyQualifiedNames.Add(assemblyQualifiedName);

            this.workItemModelTransformers = this.workItemModelTransformers ?? new List <SarifWorkItemModelTransformer>();
            this.workItemModelTransformers.Add(workItemModelTransformer);
        }
        private IReadOnlyList <SarifWorkItemModelTransformer> PopulateWorkItemModelTransformers()
        {
            if (this.workItemModelTransformers == null)
            {
                AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

                this.workItemModelTransformers = new List <SarifWorkItemModelTransformer>();

                var    loadedAssemblies      = new Dictionary <string, Assembly>();
                string thisAssemblyDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                foreach (string assemblyLocation in this.GetProperty(PluginAssemblyLocations))
                {
                    string assemblyPath = assemblyLocation;
                    if (!Path.IsPathRooted(assemblyLocation))
                    {
                        assemblyPath = Path.GetFullPath(Path.Combine(thisAssemblyDirectory, assemblyLocation));
                    }

                    Assembly a = Assembly.LoadFrom(assemblyPath);
                    loadedAssemblies.Add(a.FullName, a);
                    this.AssemblyLocationMap.Add(a.FullName, Path.GetDirectoryName(Path.GetFullPath(a.Location)));
                }

                StringSet assemblyAndTypeNames = this.GetProperty(PluginAssemblyQualifiedNames);
                foreach (string assemblyAndTypeName in assemblyAndTypeNames)
                {
                    Type type = Type.GetType(assemblyAndTypeName);

                    if (type == null)
                    {
                        string assemblyName = assemblyAndTypeName.Substring(assemblyAndTypeName.IndexOf(',') + 1).Trim();
                        if (loadedAssemblies.TryGetValue(assemblyName, out Assembly loadedAssembly))
                        {
                            type = loadedAssembly.GetType(assemblyAndTypeName);
                        }
                    }

                    SarifWorkItemModelTransformer workItemModelTransformer =
                        (SarifWorkItemModelTransformer)Activator.CreateInstance(type);

                    workItemModelTransformers.Add(workItemModelTransformer);
                }
            }

            return(this.workItemModelTransformers.AsReadOnly());
        }
示例#3
0
        private IReadOnlyList <SarifWorkItemModelTransformer> PopulateWorkItemModelTransformers()
        {
            if (this.workItemModelTransformers == null)
            {
                this.workItemModelTransformers = new List <SarifWorkItemModelTransformer>();

                foreach (string assemblyLocation in this.GetProperty(PluginAssemblyLocations))
                {
                    Assembly.LoadFrom(assemblyLocation);
                }

                StringSet assemblyAndTypeNames = this.GetProperty(PluginAssemblyQualifiedNames);
                foreach (string assemblyAndTypeName in assemblyAndTypeNames)
                {
                    Type type = Type.GetType(assemblyAndTypeName);

                    SarifWorkItemModelTransformer workItemModelTransformer =
                        (SarifWorkItemModelTransformer)Activator.CreateInstance(type);

                    workItemModelTransformers.Add(workItemModelTransformer);
                }
            }
            return(this.workItemModelTransformers.AsReadOnly());
        }