public virtual ParallelMultiInstanceBehavior CreateParallelMultiInstanceBehavior(Activity activity, AbstractBpmnActivityBehavior innerActivityBehavior) { ExtensionAttribute assigneeType = activity.AssigneeType; switch (assigneeType?.Value?.ToLower()) { case AssigneeType.SINGLE: case AssigneeType.CUSTOM: default: return(new ParallelMultiInstanceBehavior(activity, innerActivityBehavior)); case AssigneeType.SINGLE_PASS: return(new SinglePassParallelMultiInstanceBehavior(activity, innerActivityBehavior)); case AssigneeType.ONE: return(new OnePassParallelMultiInstanceBehavior(activity, innerActivityBehavior)); case AssigneeType.HALF_PASSED: case AssigneeType.HALF_REJECT: return(new HalfPassParallelMultiInstanceBehavior(activity, innerActivityBehavior)); case AssigneeType.ALL: return(new AllPassParallelMultiInstanceBehavior(activity, innerActivityBehavior)); } }
public static void CompileExtension() { ArrayList codeAssemblies = CodeAssemblies(); List <SortedExtension> sortedExtensions = new List <SortedExtension>(); foreach (Assembly a in codeAssemblies) { Type[] types = a.GetTypes(); foreach (Type type in types) { object[] attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false); foreach (object attribute in attributes) { if (attribute.GetType().Name == "ExtensionAttribute") { ExtensionAttribute ext = (ExtensionAttribute)attribute; sortedExtensions.Add(new SortedExtension(ext.Priority, type.Name, type.FullName)); } } } sortedExtensions.Sort(delegate(SortedExtension e1, SortedExtension e2) { return(e1.Priority.CompareTo(e2.Priority)); }); foreach (SortedExtension x in sortedExtensions) { a.CreateInstance(x.Type); } } }
public virtual void Parse(XMLStreamReader xtr, BpmnModel model) { model.TargetNamespace = xtr.GetAttributeValue(BpmnXMLConstants.TARGET_NAMESPACE_ATTRIBUTE); for (int i = 0; i < xtr.NamespaceCount; i++) { string prefix = xtr.GetNamespacePrefix(i); if (!string.IsNullOrWhiteSpace(prefix)) { model.AddNamespace(prefix, xtr.GetNamespaceURI(i)); } } for (int i = 0; i < xtr.AttributeCount; i++) { var attr = xtr.element.Attributes().ElementAt(i); ExtensionAttribute extensionAttribute = new ExtensionAttribute { Name = attr.Name.LocalName, Value = attr.Value }; if (!string.IsNullOrWhiteSpace(attr.Name.NamespaceName)) { extensionAttribute.Namespace = attr.Name.NamespaceName; } if (!string.IsNullOrWhiteSpace(xtr.element.GetPrefixOfNamespace(attr.Name.Namespace))) { extensionAttribute.NamespacePrefix = xtr.element.GetPrefixOfNamespace(attr.Name.Namespace); } if (!BpmnXMLUtil.IsBlacklisted(extensionAttribute, defaultAttributes)) { model.AddDefinitionsAttribute(extensionAttribute); } } }
/// <summary> /// Loads the API for the given extension, using the base API. /// </summary> /// <param name="device">The device of the context.</param> /// <param name="baseAPI">The base API instance.</param> /// <typeparam name="TContextExtension">The extension type.</typeparam> /// <returns>The extension.</returns> /// <exception cref="ExtensionNotSupportedException">Thrown if the API doesn't support the extension.</exception> internal static TContextExtension LoadContextExtension <TContextExtension>(ALContext baseApi) where TContextExtension : NativeExtension <ALContext> { return(baseApi.IsExtensionPresent(ExtensionAttribute.GetExtensionAttribute(typeof(TContextExtension)).Name) ? (TContextExtension)Activator.CreateInstance(typeof(TContextExtension), baseApi.Context) : null); }
public void Merge(ExtensionAttribute attr) { System.Diagnostics.Trace.Assert(Id == attr.Id); if (string.IsNullOrEmpty(Name)) { Name = attr.Name; } if (string.IsNullOrEmpty(Description)) { Description = attr.Description; } if (string.IsNullOrEmpty(Implementation) && attr.Implementation != null) { Implementation = Utils.GetImplementationName(attr.Implementation); } if (string.IsNullOrEmpty(Point)) { Point = attr.Point; } if (string.IsNullOrEmpty(Configuration)) { Configuration = attr.Configuration; } }
internal ExtensionConfiguration(ExtensionAttribute attr) : this( attr.Id, attr.BundleId, attr.Name, attr.Description, attr.Point, attr.Implementation == null ? string.Empty : Utils.GetImplementationName(attr.Implementation), attr.Configuration) { }
/// <summary> /// If extensions not in the cache will load /// from the XML file. If file not exists /// will load from assembly using reflection /// </summary> static void LoadExtensions() { if (HttpRuntime.Cache["Extensions"] == null || (((List <ManagedExtension>)(HttpRuntime.Cache["Extensions"]))).Count == 0) { ArrayList codeAssemblies = Utils.CodeAssemblies(); ManagedExtension meta = DataStoreExtension("MetaExtension"); if (meta == null) { _extensions.Add(new ManagedExtension("MetaExtension", "1.0", "Meta extension", "BlogEngine.net")); } else { if (!_extensions.Contains(meta)) { _extensions.Add(meta); } } foreach (Assembly a in codeAssemblies) { Type[] types = a.GetTypes(); foreach (Type type in types) { object[] attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false); foreach (object attribute in attributes) { ExtensionAttribute xa = (ExtensionAttribute)attribute; // try to load from storage ManagedExtension x = DataStoreExtension(type.Name); // if nothing, crete new extension if (x == null) { x = new ManagedExtension(type.Name, xa.Version, xa.Description, xa.Author); _newExtensions.Add(type.Name); SaveToStorage(x); } else { // update attributes from assembly x.Version = xa.Version; x.Description = xa.Description; x.Author = xa.Author; if (x.Priority == 0) { x.Priority = xa.Priority; } } _extensions.Add(x); } } } //SaveToStorage(); SaveToCache(); } }
public bool TryGetExtension <T>(out T ext) where T : NativeExtension <CL> { ext = IsExtensionPresent(ExtensionAttribute.GetExtensionAttribute(typeof(T)).Name) ? (T)Activator.CreateInstance(typeof(T), Context) : null; return(ext != null); }
public void Check(Type type, List <AssemblyScanResult> result) { // 不检查接口 if (type.IsClass) { if (type.IsSealed && type.IsAbstract) { // 静态类 ExtensionAttribute a = type.GetCustomAttribute <ExtensionAttribute>(false); if (a != null && type.Name.EndsWith("Extensions", StringComparison.Ordinal) == false && type.Name.EndsWith("Helper", StringComparison.Ordinal) == false) { result.Add(new AssemblyScanResult { Type = type, Message = "SPEC:R00028; 扩展类型必须以 Extensions 结尾" }); } } else { // 非静态类 MemberInfo[] m1 = type.GetMembers(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); m1 = (from x in m1 where x.MemberType != MemberTypes.Constructor select x ).ToArray(); MemberInfo[] m2 = type.GetMembers(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly); m2 = (from x in m2 where x.MemberType != MemberTypes.Constructor select x ).ToArray(); if (m2.Length == 0 && m1.Length > 0) { result.Add(new AssemblyScanResult { Type = type, Message = "SPEC:R00029; 类型的所有成员都是静态的,类型必须申明成静态的" }); } } } }
/// <summary> /// Gets all file formats for open/save dialog /// </summary> /// <returns></returns> static private string GetDialogFormats() { string result = string.Join("|", serializers.Keys); foreach (string pluginName in plugins.Keys) { foreach (string serializerName in serializers.Keys) { ExtensionAttribute attribute = (ExtensionAttribute)plugins[pluginName].GetCustomAttribute(typeof(ExtensionAttribute)); if (attribute == null) { throw new ArgumentNullException("Extension attribute for plugin " + pluginName + " is not assigned"); } result += "|" + CombinePluginAndSerializer(serializerName, pluginName, attribute.Extension); } } return(result); }
/// <summary> /// Run through all code assemblies and creates object /// instance for types marked with extension attribute /// </summary> public static void LoadExtensions() { ArrayList codeAssemblies = CodeAssemblies(); List <SortedExtension> sortedExtensions = new List <SortedExtension>(); foreach (Assembly a in codeAssemblies) { Type[] types = a.GetTypes(); foreach (Type type in types) { object[] attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false); foreach (object attribute in attributes) { if (attribute.GetType().Name == "ExtensionAttribute") { ExtensionAttribute ext = (ExtensionAttribute)attribute; sortedExtensions.Add(new SortedExtension(ext.Priority, type.Name, type.FullName)); } } } sortedExtensions.Sort(delegate(SortedExtension e1, SortedExtension e2) { if (e1.Priority == e2.Priority) { return(string.CompareOrdinal(e1.Name, e2.Name)); } return(e1.Priority.CompareTo(e2.Priority)); }); foreach (SortedExtension x in sortedExtensions) { if (ExtensionManager.ExtensionEnabled(x.Name)) { a.CreateInstance(x.Type); } } } // initialize comment rules and filters CommentHandlers.Listen(); }
private static void AddExtensionToBundle(Bundle bundle, ExtensionAttribute extensionAttr) { if (extensionAttr.BundleId != bundle.Id) { _logger.WarnFormat("扩展 '{0}' 提供给包 '{1}',但程序集 '{2}' '{3}'." , extensionAttr.Id, extensionAttr.BundleId, bundle.AssemblyLocation, bundle.Id); return; } ExtensionConfiguration cfg; if (bundle._contributedExtensions.TryGetValue(extensionAttr.Id, out cfg)) { cfg.Merge(extensionAttr); } else { bundle.AddExtensionConfiguration(new ExtensionConfiguration(extensionAttr)); } }
/// <summary> /// If extensions not in the cache will load /// from the XML file. If file not exists /// will load from assembly using reflection /// </summary> static void LoadExtensions() { if (HttpContext.Current.Cache["Extensions"] == null) { ArrayList codeAssemblies = Utils.CodeAssemblies(); foreach (Assembly a in codeAssemblies) { Type[] types = a.GetTypes(); foreach (Type type in types) { object[] attributes = type.GetCustomAttributes(typeof(ExtensionAttribute), false); foreach (object attribute in attributes) { ExtensionAttribute xa = (ExtensionAttribute)attribute; // try to load from storage ManagedExtension x = DataStoreExtension(type.Name); // if nothing, crete new extension if (x == null) { x = new ManagedExtension(type.Name, xa.Version, xa.Description, xa.Author); _newExtensions.Add(type.Name); SaveToStorage(x); } else { // update attributes from assembly x.Version = xa.Version; x.Description = xa.Description; x.Author = xa.Author; x.Priority = xa.Priority; } _extensions.Add(x); } } } //SaveToStorage(); SaveToCache(); } }
void RegisterTypeNode(AddinDescription config, ExtensionAttribute eatt, string path, string nodeName, Type t) { ExtensionNodeDescription elem = config.MainModule.AddExtensionNode(path, nodeName); if (eatt.Id.Length > 0) { elem.SetAttribute("id", eatt.Id); elem.SetAttribute("type", t.FullName); } else { elem.SetAttribute("id", t.FullName); } if (eatt.InsertAfter.Length > 0) { elem.SetAttribute("insertafter", eatt.InsertAfter); } if (eatt.InsertBefore.Length > 0) { elem.SetAttribute("insertbefore", eatt.InsertAfter); } }
/// <summary> /// add all attributes from XML to element extensionAttributes (except blackListed). /// </summary> /// <param name="xtr"> </param> /// <param name="element"> </param> /// <param name="blackLists"> </param> public static void AddCustomAttributes(XMLStreamReader xtr, BaseElement element, params IList <ExtensionAttribute>[] blackLists) { foreach (var attr in xtr.element.Attributes()) { ExtensionAttribute extensionAttribute = new ExtensionAttribute { Name = attr.Name.LocalName, Value = attr.Value }; if (!string.IsNullOrWhiteSpace(attr.Name.NamespaceName)) { extensionAttribute.Namespace = attr.Name.NamespaceName; } if (!string.IsNullOrWhiteSpace(xtr.element.GetPrefixOfNamespace(attr.Name.Namespace))) { extensionAttribute.NamespacePrefix = xtr.element.GetPrefixOfNamespace(attr.Name.Namespace); } if (!IsBlacklisted(extensionAttribute, blackLists)) { element.AddAttribute(extensionAttribute); } } }
private static ExtensionElement CreateExtensionElement(XMLStreamReader xtr) { ExtensionElement extensionElement = new ExtensionElement { Name = xtr.LocalName }; if (!string.IsNullOrWhiteSpace(xtr.NamespaceURI)) { extensionElement.Namespace = xtr.NamespaceURI; } if (!string.IsNullOrWhiteSpace(xtr.Prefix)) { extensionElement.NamespacePrefix = xtr.Prefix; } foreach (var attr in xtr.element.Attributes()) { ExtensionAttribute extensionAttribute = new ExtensionAttribute { Name = attr.Name.LocalName, Value = attr.Value }; if (!string.IsNullOrWhiteSpace(attr.Name.NamespaceName)) { extensionAttribute.Namespace = attr.Name.NamespaceName; } if (!string.IsNullOrWhiteSpace(xtr.element.GetPrefixOfNamespace(attr.Name.NamespaceName))) { extensionAttribute.NamespacePrefix = xtr.element.GetPrefixOfNamespace(attr.Name.NamespaceName); } extensionElement.AddAttribute(extensionAttribute); } return(extensionElement); }
public static bool IsBlacklisted(ExtensionAttribute attribute, params IList <ExtensionAttribute>[] blackLists) { if (blackLists != null) { foreach (IList <ExtensionAttribute> blackList in blackLists) { foreach (ExtensionAttribute blackAttribute in blackList) { if (blackAttribute.Name.Equals(attribute.Name)) { if (blackAttribute.Namespace != null && attribute.Namespace != null && blackAttribute.Namespace.Equals(attribute.Namespace)) { return(true); } if (blackAttribute.Namespace == null && attribute.Namespace == null) { return(true); } } } } } return(false); }
public void MayBeExplicitlyDisabled() { var attr = new ExtensionAttribute() { Enabled = false }; Assert.False(attr.Enabled); }
/// <summary> /// 扩展项构造 /// </summary> /// <param name="assembly">The assembly.</param> /// <param name="extensionAttribute">The extension attribute.</param> public ExtensionItem(Assembly assembly, ExtensionAttribute extensionAttribute) { Assembly = assembly; ExtensionAttribute = extensionAttribute; }
public void WithExtension(ExtensionAttribute extension) { if (extension == null) return; if (extensionByName.ContainsKey(extension.Name)) Logger.AddMessage("В {0} '{1}' расширение '{2}' задается повторно", containerType, Name, extension.Name); extensionByName[extension.Name] = extension; }
public void WithExtension(ExtensionAttribute extension) { if (controlAsRead == null || controlAsRead.GetExtended(extension.Name) == null) control.WithExtension(extension); }
/// <summary> /// 注销扩展 /// </summary> /// <param name="assembly">程序集.</param> /// <param name="attribute">扩展.</param> internal abstract void InnerUnRegister(Assembly assembly, ExtensionAttribute attribute);
public ExtensionInfo(TInterface obj, ExtensionAttribute attr) { Attribute = attr; Instance = obj; }
public void MayBeExplicitlyEnabled() { var attr = new ExtensionAttribute() { Enabled = true }; Assert.True(attr.Enabled); }