Beispiel #1
0
        public PluginAssemblyInfo RetrievePluginAssemblyInfo(string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }
            if (!File.Exists(path))
            {
                throw new ArgumentException("Path does not point to an existing file");
            }

            Assembly     assembly = this.LoadAssembly(path);
            AssemblyName name     = assembly.GetName();

            PluginAssemblyInfo pluginAssembly = this.RetrieveAssemblyProperties(assembly, path);

            Type[] exportedTypes = assembly.GetExportedTypes();
            foreach (Type exportedType in exportedTypes)
            {
                if (!exportedType.IsAbstract && exportedType.IsClass)
                {
                    Type xrmPluginInterface = exportedType.GetInterface(typeof(IPlugin).FullName);
                    Type crmPluginInterface = exportedType.GetInterface("Microsoft.Crm.Sdk.IPlugin");

                    Version       version = null;
                    CrmPluginType crmPluginType;
                    bool?         isolatable;

                    if (xrmPluginInterface != null)
                    {
                        crmPluginType = CrmPluginType.Plugin;
                        isolatable    = true;
                        version       = xrmPluginInterface.Assembly.GetName().Version;
                    }
                    else if (crmPluginInterface != null)
                    {
                        crmPluginType = CrmPluginType.Plugin;
                        isolatable    = false;
                        version       = new Version(4, 0);
                    }
                    else if (exportedType.IsSubclassOf(typeof(System.Activities.Activity)))
                    {
                        crmPluginType = CrmPluginType.WorkflowActivity;
                        isolatable    = true;
                    }
                    else
                    {
                        continue;
                    }

                    if (version != null)
                    {
                        pluginAssembly.SdkVersion = new Version(version.Major, version.Minor);
                    }

                    PluginTypeInfo pluginType = new PluginTypeInfo
                    {
                        PluginId   = Guid.Empty,
                        Name       = exportedType.FullName,
                        TypeName   = exportedType.FullName,
                        PluginType = crmPluginType,
                        AssemblyId = pluginAssembly.AssemblyId,
                        Isolatable = isolatable
                    };
                    if (crmPluginType == CrmPluginType.WorkflowActivity)
                    {
                        pluginType.WorkflowActivityGroupName = PluginManagementHelper.GenerateDefaultGroupName(name.Name, name.Version);
                    }
                    pluginAssembly.Plugins.Add(pluginType);
                }
            }
            return(pluginAssembly);
        }