/// <summary> /// 插件单元构造函数 /// </summary> /// <param name="exPath">插件路径</param> /// <param name="configuration">插件单元配置项</param> /// <param name="conditions">条件项</param> public AddInElement(ExtensionPath exPath, IConfiguration configuration, List<ICondition> conditions) { this.addIn = exPath.AddIn; this.workItem = exPath.AddIn.WorkItem; this.path = exPath.Name; this.configuration = configuration; this.conditions = conditions; this.logger = workItem.Services.Get<ILog>(); this.id = configuration.Attributes["id"]; this.name = configuration.Attributes["name"]; this.label = configuration.Attributes["label"]; this.className = configuration.Attributes["classname"].ToLower(); // 小写 this.command = configuration.Attributes["command"]; this.conditions.Add(new AuthorizationCondition(this)); // 加入默认的权限管理条件表达式 }
public ExtensionPath GetExtensionPath(string name) { if (!paths.ContainsKey(name)) return paths[name] = new ExtensionPath(this, name); return paths[name]; }
/// <summary> /// 设置当前插件路径 /// </summary> /// <param name="exPath">插件路径</param> /// <param name="configuration">配置项</param> public static void SetUp(ExtensionPath exPath, IConfiguration configuration) { ILog logger = exPath.AddIn.WorkItem.Services.Get<ILog>(); logger.Debug("解析插件路径," + exPath); /// Stack<ICondition> conditionStack = new Stack<ICondition>(); foreach (IConfiguration config in configuration.Children) { if (config.Name == "Condition") conditionStack.Push(new Condition(config.Name, config)); else if (config.Name == "ComplexCondition") conditionStack.Push(new ComplexCondition(config.Name, config)); else { List<ICondition> conditions = new List<ICondition>(); conditions.AddRange(conditionStack.ToArray()); AddInElement element = new AddInElement(exPath, config, conditions); logger.Debug(" 添加插件单元," + element.ToString()); if (exPath.BuildStartUp) // 立即创建插件单元 element.BuildSelf(); exPath.AddInElements.Add(element); if (config.Children.Count > 0) { string pathStr = exPath.Name.EndsWith("/") ? exPath.Name + element.Id : exPath.Name + "/" + element.Id; ExtensionPath subPath = exPath.AddIn.GetExtensionPath(pathStr); subPath.BuildStartUp = exPath.BuildStartUp; subPath.Label = element.Label; SetUp(subPath, config); } } } }