void ScanAssemblyAddinHeaders(AddinDescription config, Assembly asm, AddinScanResult scanResult)
        {
            // Get basic add-in information
            AddinAttribute att = (AddinAttribute)Attribute.GetCustomAttribute(asm, typeof(AddinAttribute), false);

            if (att != null)
            {
                if (att.Id.Length > 0)
                {
                    config.LocalId = att.Id;
                }
                if (att.Version.Length > 0)
                {
                    config.Version = att.Version;
                }
                if (att.Namespace.Length > 0)
                {
                    config.Namespace = att.Namespace;
                }
                if (att.Category.Length > 0)
                {
                    config.Category = att.Category;
                }
                config.IsRoot = att is AddinRootAttribute;
            }
        }
        bool ScanAssembly(IProgressStatus monitor, string filePath, AddinScanResult scanResult, out AddinDescription config)
        {
            config = null;

            try {
                Assembly asm = Util.LoadAssemblyForReflection(filePath);

                // Get the config file from the resources, if there is one

                string configFile = null;
                foreach (string res in asm.GetManifestResourceNames())
                {
                    if (res.EndsWith(".addin") || res.EndsWith(".addin.xml"))
                    {
                        configFile = res;
                        break;
                    }
                }

                if (configFile != null)
                {
                    using (Stream s = asm.GetManifestResourceStream(configFile)) {
                        string asmFile = new Uri(asm.CodeBase).LocalPath;
                        config = AddinDescription.Read(s, Path.GetDirectoryName(asmFile));
                    }
                }
                else
                {
                    // On this case, only scan the assembly if it has the Addin attribute.
                    AddinAttribute att = (AddinAttribute)Attribute.GetCustomAttribute(asm, typeof(AddinAttribute), false);
                    if (att == null)
                    {
                        config = null;
                        return(true);
                    }
                    config = new AddinDescription();
                }

                config.BasePath  = Path.GetDirectoryName(filePath);
                config.AddinFile = filePath;

                string rasmFile = Path.GetFileName(filePath);
                if (!config.MainModule.Assemblies.Contains(rasmFile))
                {
                    config.MainModule.Assemblies.Add(rasmFile);
                }

                return(ScanDescription(monitor, config, asm, scanResult));
            }
            catch (Exception ex) {
                // Something went wrong while scanning the assembly. We'll ignore it for now.
                monitor.ReportError("There was an error while scanning assembly: " + filePath, ex);
                return(false);
            }
        }
        public VimAddinOptionsPanelWidget()
        {
            this.Build();
            Assembly       assembly  = Assembly.GetExecutingAssembly();
            AddinAttribute addinAttr = assembly.GetCustomAttribute <AddinAttribute> ();
            string         labelText = String.Format("VimAddin version {0}",
                                                     addinAttr.Version);

            this.label1.Text         = labelText;
            this.checkbutton1.Active = (bool)PropertyService.Get("UseViModes", false);
        }
示例#4
0
        /// <summary>
        /// 解析插件所需程序集列表。
        /// </summary>
        private void AnalysisAssemblies()
        {
            if (References == null)
            {
                return;
            }
            LoadAssemblies();
            Type type = System.Type.GetType(Type,
                                            (n) =>
            {
                Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
                AssemblyName an       = null;
                for (Int32 i = 0; i < assemblies.Length; i++)
                {
                    an = assemblies[i].GetName();
                    if (an.Name == n.Name || an.FullName == n.FullName)
                    {
                        return(assemblies[i]);
                    }
                }
                return(null);
            },
                                            (a, s, b) =>
            {
                Type temp = a.GetType(s);
                if (temp == null)
                {
                    BuildState = AddinBuildState.LoadTypeFail;
                }
                return(temp);
            }, true);

            if (type.GetInterface(typeof(IAddin).FullName) == null)
            {
                BuildState = AddinBuildState.LoadTypeFail;
                throw new TypeLoadException($"{type.FullName} must implement IAddin interface");
            }
            AddinAttribute attr = type.GetCustomAttribute <AddinAttribute>();

            if (attr == null)
            {
                BuildState = AddinBuildState.LoadTypeFail;
                throw new AddinAttributeException($"{type.FullName} can not find 'AddinAttribute'");
            }
            if (attr.Guid != Owner.Guid)
            {
                BuildState = AddinBuildState.LoadTypeFail;
                throw new AddinAttributeException($"{type.FullName} guid not match");
            }
            _type = type;
        }
示例#5
0
        public void DiscoverAddinsWithCombinedCustomExportAndMetadataAttribute()
        {
            var container = ContainerFactory.CreateWithAttributedCatalog(typeof(Addin1), typeof(Addin2), typeof(Addin3));

            var addins = container.GetExports <IAddin, ITrans_AddinMetadata>().ToArray();

            Assert.AreEqual(3, addins.Length, "Incorrect number of addins");

            var values = new AddinAttribute[]
            {
                new AddinAttribute("Addin1", "1.0", "{63D1B00F-AD2F-4F14-8A36-FFA59E4A101C}"),
                new AddinAttribute("Addin2", "1.0", "{63D1B00F-AD2F-4F14-8A36-FFA59E4A101D}"),
                new AddinAttribute("Addin3", "1.0", "{63D1B00F-AD2F-4F14-8A36-FFA59E4A101E}"),
            };

            for (int i = 0; i < values.Length; i++)
            {
                var addinMetadata = addins[i].Metadata;

                Assert.AreEqual(values[i].Name, addinMetadata.Name);
                Assert.AreEqual(values[i].Version, addinMetadata.Version);
                Assert.AreEqual(values[i].Id, addinMetadata.Id);
            }
        }
        public static IList <InterceptedServiceBizModel> GetInterceptedService()
        {
            List <InterceptedServiceBizModel> services = new List <InterceptedServiceBizModel>();

            string path = string.Empty;

            path = HttpRuntime.AppDomainAppPath;
            path = path + @"\i6Rules";

            DirectoryInfo TheFolder = new DirectoryInfo(path);


            foreach (var file in TheFolder.GetFiles())
            {
                if (file.Extension != ".dll")
                {
                    continue;
                }
                //加载DLL
                try
                {
                    Assembly assembly = Assembly.LoadFrom(file.FullName);


                    var types = assembly.GetExportedTypes();


                    foreach (var clazz in types)
                    {
                        var methdoInfos = clazz.GetMethods();
                        foreach (var method in methdoInfos)
                        {
                            var attributes = method.GetCustomAttributes(true);
                            foreach (var attr in attributes)
                            {
                                if (attr.GetType().ToString() == "Enterprise3.Common.Model.Attributes.AddinAttribute")
                                {
                                    AddinAttribute attribute = attr as AddinAttribute;
                                    if (attribute != null)
                                    {
                                        //插入
                                        InterceptedServiceBizModel service = new InterceptedServiceBizModel();
                                        service.TargetAssemblyName = file.Name;
                                        service.TargetClassName    = clazz.Name;
                                        service.TargetMethodName   = method.Name;

                                        service.ServiceFuncName = attribute.ServiceMethodDescription;
                                        service.ServiceName     = attribute.ServiceDescription;
                                        service.MatchCondition  = attribute.MatchCondition;

                                        services.Add(service);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    continue;
                }
            }


            return(services);
        }
示例#7
0
        public void DiscoverAddinsWithCombinedCustomExportAndMetadataAttribute()
        {
            var container = ContainerFactory.CreateWithAttributedCatalog(typeof(Addin1), typeof(Addin2), typeof(Addin3));

            var addins = container.GetExports<IAddin, IAddinMetadata>().ToArray();

            Assert.AreEqual(3, addins.Length, "Incorrect number of addins");

            var values = new AddinAttribute[] 
                {
                    new AddinAttribute("Addin1", "1.0", "{63D1B00F-AD2F-4F14-8A36-FFA59E4A101C}"),
                    new AddinAttribute("Addin2", "1.0", "{63D1B00F-AD2F-4F14-8A36-FFA59E4A101D}"),
                    new AddinAttribute("Addin3", "1.0", "{63D1B00F-AD2F-4F14-8A36-FFA59E4A101E}"),
                };

            for (int i = 0; i < values.Length; i++)
            {
                var addinMetadata = addins[i].Metadata;

                Assert.AreEqual(values[i].Name, addinMetadata.Name);
                Assert.AreEqual(values[i].Version, addinMetadata.Version);
                Assert.AreEqual(values[i].Id, addinMetadata.Id);
            }
        }