/// <summary> /// Scans a given <see cref="Type" /> for filters. /// </summary> /// <param name="type">The <see cref="Type" /> to scan.</param> /// <param name="task">The <see cref="Task" /> which will be used to output messages to the build log.</param> /// <returns> /// <see langword="true" /> if <paramref name="type" /> represents a /// <see cref="Filter" />; otherwise, <see langword="false" />. /// </returns> private static bool ScanTypeForFilters(Type type, Task task) { try { ElementNameAttribute elementNameAttribute = (ElementNameAttribute) Attribute.GetCustomAttribute(type, typeof(ElementNameAttribute)); if (type.IsSubclassOf(typeof(Filter)) && !type.IsAbstract && elementNameAttribute != null) { task.Log(Level.Debug, "Creating FilterBuilder for \"{0}\".", type.Name); FilterBuilder builder = new FilterBuilder(type.FullName, type.Assembly.Location); if (FilterBuilders[builder.FilterName] == null) { FilterBuilders.Add(builder); task.Log(Level.Debug, "Adding filter \"{0}\" from {1}:{2}.", builder.FilterName, builder.AssemblyFileName, builder.ClassName); } // specified type represents a filter return(true); } // specified type does not represent a valid filter return(false); } catch { task.Log(Level.Error, "Failure scanning \"{0}\" for filters.", type.AssemblyQualifiedName); throw; } }
/// <summary> /// Scans a given <see cref="Type" /> for data type. /// </summary> /// <param name="type">The <see cref="Type" /> to scan.</param> /// <param name="task">The <see cref="Task" /> which will be used to output messages to the build log.</param> /// <returns> /// <see langword="true" /> if <paramref name="type" /> represents a /// data type; otherwise, <see langword="false" />. /// </returns> private static bool ScanTypeForDataTypes(Type type, Task task) { try { ElementNameAttribute elementNameAttribute = (ElementNameAttribute) Attribute.GetCustomAttribute(type, typeof(ElementNameAttribute)); if (type.IsSubclassOf(typeof(DataTypeBase)) && !type.IsAbstract && elementNameAttribute != null) { logger.Info(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("String_CreatingDataTypeBaseBuilder"), type.Name)); DataTypeBaseBuilder dtb = new DataTypeBaseBuilder(type.FullName, type.Assembly.Location); if (DataTypeBuilders[dtb.DataTypeName] == null) { logger.Debug(string.Format(CultureInfo.InvariantCulture, ResourceUtils.GetString("String_AddingDataType"), dtb.DataTypeName, dtb.AssemblyFileName, dtb.ClassName)); DataTypeBuilders.Add(dtb); } // specified type represents a data type return(true); } else { // specified type does not represent valid data type return(false); } } catch { task.Log(Level.Error, "Failure scanning \"{0}\" for data types.", type.AssemblyQualifiedName); throw; } }
/// <summary> /// Creates a new instance of the <see cref="FilterBuilder" /> class /// for the specified <see cref="Filter" /> class in the <see cref="Assembly" /> /// specified. /// </summary> /// <param name="assembly">The <see cref="Assembly" /> containing the <see cref="Filter" />.</param> /// <param name="className">The class representing the <see cref="Filter" />.</param> public FilterBuilder(Assembly assembly, string className) { _assembly = assembly; _className = className; // get Element name from attribute ElementNameAttribute ElementNameAttribute = (ElementNameAttribute) Attribute.GetCustomAttribute(assembly.GetType(ClassName), typeof(ElementNameAttribute)); _filterName = ElementNameAttribute.Name; }
/// <summary> /// Creates a new instance of the <see cref="FilterBuilder" /> class /// for the specified <see cref="Filter" /> class in the specified /// <see cref="ExtensionAssembly" />. /// </summary> /// <param name="extensionAssembly">The <see cref="ExtensionAssembly" /> containing the <see cref="Filter" />.</param> /// <param name="className">The class representing the <see cref="Filter" />.</param> internal FilterBuilder(ExtensionAssembly extensionAssembly, string className) : base(extensionAssembly) { _className = className; // get Element name from attribute ElementNameAttribute ElementNameAttribute = (ElementNameAttribute) Attribute.GetCustomAttribute(Assembly.GetType(ClassName), typeof(ElementNameAttribute)); _filterName = ElementNameAttribute.Name; }
/// <summary> /// Creates a new instance of the <see cref="DataTypeBaseBuilder" /> class /// for the specified Element class in the assembly specified. /// </summary> /// <param name="className">The class representing the Element.</param> /// <param name="assemblyFileName">The assembly containing the Element.</param>/// public DataTypeBaseBuilder(string className, string assemblyFileName) { _className = className; _assemblyFileName = assemblyFileName; Assembly assembly = GetAssembly(); // get Element name from attribute ElementNameAttribute ElementNameAttribute = (ElementNameAttribute) Attribute.GetCustomAttribute(assembly.GetType(ClassName), typeof(ElementNameAttribute)); _elementName = ElementNameAttribute.Name; }
/// <summary> /// Creates a new instance of the <see cref="FilterBuilder" /> class /// for the specified Element class in the assembly specified. /// </summary> /// <param name="className">The class representing the Element.</param> /// <param name="assemblyFileName">The assembly containing the Element.</param>/// public FilterBuilder(Type filterType) { _Type = filterType; _className = filterType.FullName; _assemblyFileName = filterType.Assembly.Location; Assembly assembly = GetAssembly(); // get Element name from attribute ElementNameAttribute ElementNameAttribute = (ElementNameAttribute) Attribute.GetCustomAttribute(assembly.GetType(ClassName), typeof(ElementNameAttribute)); _filterName = ElementNameAttribute.Name; }
/// <summary> /// This method adds dynElements when opening from a file /// </summary> /// <param name="elementType"></param> /// <param name="nickName"></param> /// <param name="guid"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public dynElement AddDynElement(Type elementType, string nickName, Guid guid, double x, double y) { try { //create a new object from a type //that is passed in //dynElement el = (dynElement)Activator.CreateInstance(elementType, new object[] { nickName }); dynElement el = (dynElement)Activator.CreateInstance(elementType); if (!string.IsNullOrEmpty(nickName)) { el.NickName = nickName; } else { ElementNameAttribute elNameAttrib = this.GetType().GetCustomAttributes(typeof(ElementNameAttribute), true)[0] as ElementNameAttribute; if (elNameAttrib != null) { el.NickName = elNameAttrib.ElementName; } } el.GUID = guid; //store the element in the elements list elements.Add(el); workBench.Children.Add(el); Canvas.SetLeft(el, x); Canvas.SetTop(el, y); //create an event on the element itself //to update the elements ports and connectors el.PreviewMouseRightButtonDown += new MouseButtonEventHandler(UpdateElement); return(el); } catch (Exception e) { dynElementSettings.SharedInstance.Bench.Log("Could not create an instance of the selected type."); return(null); } }