private PluginAssemblyInfo RetrieveAssemblyProperties(Assembly assembly, string path) { if (assembly == null) { throw new ArgumentNullException("assembly"); } FileInfo fileInfo = new FileInfo(path); AssemblyName name = assembly.GetName(); PluginAssemblyInfo pluginAssembly = new PluginAssemblyInfo(path) { AssemblyId = Guid.Empty, SourceType = CrmAssemblySourceType.Database, IsolationMode = CrmAssemblyIsolationMode.Sandbox, ServerFileName = fileInfo.Name, Name = name.Name, Version = name.Version.ToString() }; if (name.CultureInfo.LCID == CultureInfo.InvariantCulture.LCID) { pluginAssembly.Culture = "neutral"; } else { pluginAssembly.Culture = name.CultureInfo.Name; } byte[] publicKeyToken = name.GetPublicKeyToken(); if (publicKeyToken == null || publicKeyToken.Length == 0) { pluginAssembly.PublicKeyToken = null; } else { pluginAssembly.PublicKeyToken = string.Join(string.Empty, publicKeyToken.Select(b => b.ToString("X2"))); } return(pluginAssembly); }
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); }
public static void RefreshFromExistingAssembly(ContentRepository _repository, PluginAssemblyInfo assemblyInfo) { QueryByAttribute query = new QueryByAttribute("pluginassembly") { ColumnSet = new ColumnSet(true) }; query.AddAttributeValue("name", assemblyInfo.Name); Entity crmPluginAssembly = _repository.Get(query).SingleOrDefault(); if (crmPluginAssembly == null) { return; } assemblyInfo.AssemblyId = crmPluginAssembly.Id; if (crmPluginAssembly.Contains("description")) { assemblyInfo.Description = crmPluginAssembly.GetAttributeValue <string>("description"); } query = new QueryByAttribute("plugintype") { ColumnSet = new ColumnSet(true) }; query.AddAttributeValue("pluginassemblyid", assemblyInfo.AssemblyId); foreach (Entity crmPluginType in _repository.Get(query)) { PluginTypeInfo typeInfo = assemblyInfo.Plugins.SingleOrDefault(p => p.TypeName.Equals(crmPluginType.GetAttributeValue <string>("typename"), StringComparison.InvariantCultureIgnoreCase)); if (typeInfo != null) { typeInfo.PluginId = crmPluginType.Id; typeInfo.FriendlyName = crmPluginType.GetAttributeValue <string>("friendlyname"); typeInfo.Name = crmPluginType.GetAttributeValue <string>("name"); if (crmPluginType.Contains("isworkflowactivity") && crmPluginType.GetAttributeValue <bool>("isworkflowactivity") == true) { // Check if previous Activity Groupname was the default. If so keep the new default name, else keep existing name string existingGeneratedGroupName = PluginManagementHelper.GenerateDefaultGroupName(crmPluginAssembly.GetAttributeValue <string>("name"), new Version(crmPluginAssembly.GetAttributeValue <string>("version"))); string existingGroupName = crmPluginType.GetAttributeValue <string>("workflowactivitygroupname"); if (!string.Equals(existingGroupName, existingGeneratedGroupName, StringComparison.InvariantCultureIgnoreCase)) { typeInfo.WorkflowActivityGroupName = existingGroupName; } } } } }