private bool AddIAction(Type[] types, Assembly actionAssembly, ResourceAction resourceAction) { bool actionClassFound = false; bool actionPropertyFound = false; bool actionPropertySetLayoutFound = false; foreach (Type type in types) { if (type.GetInterface(typeof(IAction).FullName) != null) { actionClassFound = true; Logger.LogDebug("Loading action class: " + type.FullName); resourceAction.ActionClass = type.FullName; resourceAction.SetAction(actionAssembly.CreateInstance(type.FullName) as IAction); if (null != OnBeforeAddResourceAction) { ResourceActionEventArgs args = new ResourceActionEventArgs(resourceAction); OnBeforeAddResourceAction(this, args); if (args.Cancel) { //We no longer want to add this action so can return straight away return false; } } //check for duplicate action already existing if (DuplicateFoundInList(resourceAction) && OnDuplicateResourceAction != null) { ResourceActionEventArgs args = new ResourceActionEventArgs(resourceAction); do { OnDuplicateResourceAction(this, args); } while (!args.Cancel && DuplicateFoundInList(resourceAction)); if (args.Cancel) { //We no longer want to add this action so can return straight away return false; } } } if (type.GetInterface(typeof(IActionPropertySet).FullName) != null) { actionPropertyFound = true; LoadActionProperties(actionAssembly, resourceAction, type); } else { CreateActionProperties(resourceAction); } //If we have this interface, we can populate an extra data structure //and get some extra layout info if (type.GetInterface(typeof(IPropertySetLayout).FullName) != null) { actionPropertySetLayoutFound = true; LoadActionPropertyLayout(actionAssembly, resourceAction, type); } if (actionClassFound && actionPropertyFound && actionPropertySetLayoutFound) { return true; } } // The least requirement is for the action and the action properties to be present. return (actionClassFound && actionPropertyFound); }
private bool AddIAction3(Type[] types, Assembly assembly, ResourceAction resourceAction) { Type action2Type = null; Type actionInstallerType = null; Type customDataType = null; foreach(Type type in types) { if (type.GetInterface(typeof(IAction3).FullName) != null && action2Type == null) action2Type = type; if (typeof(ActionInstaller).IsAssignableFrom(type) && actionInstallerType == null) actionInstallerType = type; if (type.GetInterface(typeof(ICustomDataType).FullName) != null && customDataType == null) customDataType = type; } if (action2Type == null) return false; Logger.LogDebug("Loading action class: " + action2Type.FullName); resourceAction.ActionClass = action2Type.FullName; IAction3 action2 = assembly.CreateInstance(action2Type.FullName) as IAction3; resourceAction.SetAction(action2); if (customDataType != null) resourceAction.CustomDataTypeUI = assembly.CreateInstance(customDataType.FullName) as ICustomDataType; ResourceActionProperties properties = new ResourceActionProperties(); properties.SetActionProperties(action2.PropertySet); resourceAction.Properties = properties; PolicyType[] supportedPolicyTypes = null; RunAt[] execLocations = null; if (actionInstallerType != null) { ActionInstaller installer = assembly.CreateInstance(actionInstallerType.FullName) as ActionInstaller; if(installer.ExecuteLocations != null) { execLocations = new RunAt[installer.ExecuteLocations.Count]; installer.ExecuteLocations.CopyTo(execLocations, 0); } if (installer.SupportedPolicyTypes != null) { supportedPolicyTypes = new PolicyType[installer.SupportedPolicyTypes.Count]; installer.SupportedPolicyTypes.CopyTo(supportedPolicyTypes, 0); } resourceAction.ImpliesIncident = installer.ImpliesIncident; resourceAction.AllowTransparent = installer.AllowsTransparency; } //default to supporting all if (supportedPolicyTypes == null) supportedPolicyTypes = new PolicyType[] { PolicyType.ActiveContent, PolicyType.ClientEmail, PolicyType.ClientRemovableMedia, PolicyType.NetworkContentDiscovery, PolicyType.Mta, PolicyType.NetMon }; resourceAction.SupportedPolicySetting = supportedPolicyTypes; //default to supporting all if(execLocations == null) execLocations = new RunAt[] { RunAt.Both }; resourceAction.ExecutionTarget = execLocations; resourceAction.ExecutionTargetCapabilities = (RunAt[])execLocations.Clone(); return true; }