/// <summary> /// 获取此资源所在的<see cref="Assembly"/> /// </summary> /// <returns>Type</returns> public Type GetFileInType() { if (this.fileInType == null) { this.fileInType = UtilityType.CreateType(this.GetType().Assembly, this.fileInTypeName, false); } return(this.fileInType); }
public static KeyValuePair <string, T> InterfaceBuilder <T>(XmlNode node) { if (node == null) { throw new ArgumentNullException("node", "参数不能为空"); } string name = node.Attributes["name"].Value; Type type = UtilityType.FindType(node.Attributes["class"].Value); object klass = UtilityType.CreateObject(type, typeof(T), true); return(new KeyValuePair <string, T>(name, (T)klass));; }
public static IUtility Instance(UtilityType type, DBArtifact db) { switch (type) { case UtilityType.Backup: return(new BackupUtility(db)); case UtilityType.Restore: return(new RestoreUtility(db)); default: throw new NotImplementedException(); } }
/// <summary> /// 从目录中找到所有的.Net程序集,并遍历所有程序集找到所有实现了IOption接口的类型 /// </summary> /// <param name="appStartPath">The app start path.</param> /// <returns></returns> private static Type[] GetOptionClassByDirectory(string appStartPath) { List <Type> typeList = new List <Type>(); Assembly[] assArray = UtilityFile.SearchAssemblyByDirectory(appStartPath); foreach (Assembly ass in assArray) { Type[] types = ass.GetTypes(); foreach (Type type in types) { if (UtilityType.ContainsInterface(type, typeof(IOption))) { typeList.Add(type); } } } return(typeList.ToArray()); }
private IOptionManager CreateOptionManager(string optionFile, bool monitor) { OptionAttribute[] optionAttributes = OptionAttribute.GetOptionAttributeFromAssembly(null); IOptionManager createdObject = null; if (optionAttributes != null && optionAttributes.Length > 0) { OptionAttribute optionAttribute = optionAttributes[0]; for (int i = 1; i < optionAttributes.Length; i++) { if (optionAttributes[i].Priority > optionAttribute.Priority) { optionAttribute = optionAttributes[i]; } } Type type = optionAttribute.RealType; if (type == null) { try { type = UtilityType.CreateType(this.GetType().Assembly, optionAttribute.TypeName, true); } catch (Exception e) { throw new OptionException("类型载入错误:" + e.Message, e); } } try { createdObject = (IOptionManager)UtilityType.CreateObject(this.GetType().Assembly, type.FullName, typeof(IOptionManager), true); createdObject.Initializes(optionFile, monitor); } catch (Exception e) { throw new OptionException(e.Message, e); } } return(createdObject); }
public async Task ReportSuccessfulSupplyMeterDataUpload(string portfolioId, string accountId, string[] fileNames, UtilityType utility) { var payload = new ReportSupplyDataUploadRequest { PortfolioId = portfolioId, CsvNames = fileNames, Notes = $"Uploaded ${DateTime.UtcNow}" }; var prefix = utility == UtilityType.Electricity ? "electricity" : "gas"; await MakeApiRequest($"supplymeterdata/{prefix}/{accountId}", payload); }
/// <summary> /// 从程序集中获得选项元属性 /// </summary> /// <param name="assemblies">程序集,如果为null,则从当前应用程序域中获取所载入的所有程序集</param> /// <returns>找到的选项元属性的数组</returns> public static OptionAttribute[] GetOptionAttributeFromAssembly(Assembly[] assemblies) { return(UtilityType.GetAttributeFromAssembly <OptionAttribute>(assemblies)); }
public static Option[] Load(Assembly ass, Type type, OptionAttribute optionAttr) { List <Option> options = new List <Option>(); #region if (!optionAttr.IsCollection)//如果不是集合型的选项 { #region Option option = new Option(); option.Name = optionAttr.OptionSectionName; XmlNode optionNode = OptionManager.Instance.OptionDocument.DocumentElement.SelectSingleNode(optionAttr.OptionSectionName); if (optionNode != null)//当选项的xml节点可以从选项文件找到 { //从类型创建对象 option.Entity = UtilityType.CreateObject(ass, type.FullName, type, true, null); //从类型获得该类型的所有属性 PropertyInfo[] propertyInfoList = type.GetProperties(); //为每个属性赋值 foreach (PropertyInfo info in propertyInfoList) { object[] valueAttrs = info.GetCustomAttributes(false); foreach (var attr in valueAttrs) { if (attr is OptionValueAttribute) { OptionValueAttribute valueAttr = (OptionValueAttribute)attr; XmlElement optionElement = (XmlElement)optionNode; Object obj = UtilityConvert.ConvertTo(optionElement.GetAttribute(valueAttr.Name), info.PropertyType); info.SetValue(option.Entity, obj, null); option.XmlElement = optionElement; } else { continue; } } //foreach } //foreach PropertyInfo } #endregion OptionManager.Instance.Options.Add(option); option.OnOptionLoaded(new OptionLoadedEventArgs(option)); options.Add(option); } else { #region XmlNode optionNode = OptionManager.Instance.OptionDocument.DocumentElement.SelectSingleNode(optionAttr.ParentSectionName); if (optionNode != null)//当选项的xml节点可以从选项文件找到 { if (optionNode.HasChildNodes) { foreach (XmlNode optionChildrenNode in optionNode) { Option option = new Option(); #region if (optionChildrenNode.NodeType == XmlNodeType.Element) { option.Name = optionAttr.OptionSectionName; //从类型创建对象 option.Entity = UtilityType.CreateObject(ass, type.FullName, type, true, null); //从类型获得该类型的所有属性 PropertyInfo[] propertyInfoList = type.GetProperties(); //为每个属性赋值 foreach (PropertyInfo info in propertyInfoList) { object[] valueAttrs = info.GetCustomAttributes(false); foreach (var attr in valueAttrs) { if (attr is OptionValueAttribute) { OptionValueAttribute valueAttr = (OptionValueAttribute)attr; XmlElement optionElement = (XmlElement)optionChildrenNode; Object obj = UtilityConvert.ConvertTo(optionElement.GetAttribute(valueAttr.Name), info.PropertyType); info.SetValue(option.Entity, obj, null); option.XmlElement = optionElement; } else { continue; } } //foreach } //foreach PropertyInfo } else { continue; } #endregion OptionManager.Instance.Options.Add(option); option.OnOptionLoaded(new OptionLoadedEventArgs(option)); options.Add(option); } } } #endregion } #endregion return(options.ToArray()); }
/// <summary></summary> protected override void AddNextNodeToCycle(IFocusCyclableNodeState state) { IFocusInsertionChildNodeIndexList CycleIndexList = state.CycleIndexList; INode ParentNode = state.ParentState.Node; IFocusNodeIndex NodeIndex = state.ParentIndex as IFocusNodeIndex; IDocument Documentation = null; IIdentifier ExportIdentifier = null; ExportStatus Export = ExportStatus.Exported; IName EntityName = null; IObjectType EntityType = null; IBlockList <IAssertion, Assertion> EnsureBlocks = null; IExpression ConstantValue = null; IBlockList <ICommandOverload, CommandOverload> CommandOverloadBlocks = null; OnceChoice Once = OnceChoice.Normal; IBlockList <IQueryOverload, QueryOverload> QueryOverloadBlocks = null; UtilityType PropertyKind = UtilityType.ReadWrite; IBlockList <IIdentifier, Identifier> ModifiedQueryBlocks = null; IOptionalReference <IBody> GetterBody = null; IOptionalReference <IBody> SetterBody = null; IBlockList <IEntityDeclaration, EntityDeclaration> IndexParameterBlocks = null; ParameterEndStatus ParameterEnd = ParameterEndStatus.Closed; List <Type> FeatureTypeList = new List <Type>() { typeof(AttributeFeature), typeof(ConstantFeature), typeof(CreationFeature), typeof(FunctionFeature), typeof(ProcedureFeature), typeof(PropertyFeature), typeof(IndexerFeature) }; foreach (IFocusInsertionChildNodeIndex Index in CycleIndexList) { IFeature Feature = Index.Node as IFeature; Debug.Assert(Feature != null); if (FeatureTypeList.Contains(Feature.GetType())) { FeatureTypeList.Remove(Feature.GetType()); } switch (Feature) { case IAttributeFeature AsAttribute: Documentation = AsAttribute.Documentation; ExportIdentifier = AsAttribute.ExportIdentifier; Export = AsAttribute.Export; EntityName = AsAttribute.EntityName; EntityType = AsAttribute.EntityType; EnsureBlocks = AsAttribute.EnsureBlocks; break; case IConstantFeature AsConstant: Documentation = AsConstant.Documentation; ExportIdentifier = AsConstant.ExportIdentifier; Export = AsConstant.Export; EntityName = AsConstant.EntityName; EntityType = AsConstant.EntityType; ConstantValue = AsConstant.ConstantValue; break; case ICreationFeature AsCreation: Documentation = AsCreation.Documentation; ExportIdentifier = AsCreation.ExportIdentifier; Export = AsCreation.Export; EntityName = AsCreation.EntityName; CommandOverloadBlocks = AsCreation.OverloadBlocks; break; case IFunctionFeature AsFunction: Documentation = AsFunction.Documentation; ExportIdentifier = AsFunction.ExportIdentifier; Export = AsFunction.Export; EntityName = AsFunction.EntityName; Once = AsFunction.Once; QueryOverloadBlocks = AsFunction.OverloadBlocks; break; case IProcedureFeature AsProcedure: Documentation = AsProcedure.Documentation; ExportIdentifier = AsProcedure.ExportIdentifier; Export = AsProcedure.Export; EntityName = AsProcedure.EntityName; CommandOverloadBlocks = AsProcedure.OverloadBlocks; break; case IPropertyFeature AsProperty: Documentation = AsProperty.Documentation; ExportIdentifier = AsProperty.ExportIdentifier; Export = AsProperty.Export; EntityName = AsProperty.EntityName; EntityType = AsProperty.EntityType; PropertyKind = AsProperty.PropertyKind; ModifiedQueryBlocks = AsProperty.ModifiedQueryBlocks; GetterBody = AsProperty.GetterBody; SetterBody = AsProperty.SetterBody; break; case IIndexerFeature AsIndexer: Documentation = AsIndexer.Documentation; ExportIdentifier = AsIndexer.ExportIdentifier; Export = AsIndexer.Export; EntityType = AsIndexer.EntityType; IndexParameterBlocks = AsIndexer.IndexParameterBlocks; ParameterEnd = AsIndexer.ParameterEnd; ModifiedQueryBlocks = AsIndexer.ModifiedQueryBlocks; GetterBody = AsIndexer.GetterBody; SetterBody = AsIndexer.SetterBody; break; } Debug.Assert(CommandOverloadBlocks == null || CommandOverloadBlocks.NodeBlockList.Count > 0); Debug.Assert(QueryOverloadBlocks == null || QueryOverloadBlocks.NodeBlockList.Count > 0); Debug.Assert(IndexParameterBlocks == null || IndexParameterBlocks.NodeBlockList.Count > 0); } // If the list is full, no need to add more nodes to the cycle. if (FeatureTypeList.Count > 0) { Type NodeType = FeatureTypeList[0]; INode NewFeature = NodeHelper.CreateInitializedFeature(NodeType, Documentation, ExportIdentifier, Export, EntityName, EntityType, EnsureBlocks, ConstantValue, CommandOverloadBlocks, Once, QueryOverloadBlocks, PropertyKind, ModifiedQueryBlocks, GetterBody, SetterBody, IndexParameterBlocks, ParameterEnd); IFocusInsertionChildNodeIndex InsertionIndex = (IFocusInsertionChildNodeIndex)((IFocusBrowsingInsertableIndex)NodeIndex).ToInsertionIndex(ParentNode, NewFeature); CycleIndexList.Add(InsertionIndex); } }