/// <summary>获取插件目录</summary> /// <returns></returns> public String GetPluginPath() { //if (Runtime.IsWeb) // return "Bin".GetFullPath(); //else return(PluginPath.GetBasePath()); }
public override object Parse(ParserContext context) { if (string.IsNullOrWhiteSpace(context.Text)) { return(null); } //处理特殊路径表达式,即获取插件文件路径或目录 if (context.Text == "~") { return(context.Plugin.FilePath); } else if (context.Text == "~/") { return(System.IO.Path.GetDirectoryName(context.Plugin.FilePath)); } var text = PluginPath.PreparePathText(context.Text, out var mode); if (string.IsNullOrWhiteSpace(text)) { throw new PluginException($"Missing argument of the path parser."); } return(context.Node.Resolve(text, mode, context.MemberType)); }
private void GeneratePageContent(ViewContext context, Page page) { string controllerName = context.RouteData.GetRequiredString("controller"); string actionName = context.RouteData.GetRequiredString("action"); string areaName = context.RouteData.DataTokens["area"] as string; //将控制器传入的验证错误信息转发给页面 foreach (var modelState in context.ViewData.ModelState) { if (modelState.Value.Errors.Count < 1) { continue; } foreach (var error in modelState.Value.Errors) { page.ModelState.AddModelError(modelState.Key, error.ErrorMessage); } } //首先生成工作台节点下的基本控件 this.GeneratePageContent(page, _pluginContext.PluginTree.Find(_pluginContext.Settings.WorkbenchPath)); string path = PluginPath.Combine(string.IsNullOrWhiteSpace(areaName) ? "Workspace" : areaName, "Views", controllerName, actionName); var viewNode = _pluginContext.PluginTree.Find(path); if (viewNode != null) { this.GeneratePageContent(page, viewNode); } }
//TODO : yeid return /// <summary> /// 扫描指定插件目录内插件动态链接库 /// </summary> /// <param name="PluginsDirectory">插件目录</param> /// <returns></returns> public static List <TemplateClass> GetPlugins(string PluginsDirectory) { Debug.Print("扫描插件目录 : {0}", PluginsDirectory); List <TemplateClass> PluginInstanceList = new List <TemplateClass>(); foreach (string PluginPath in Directory.GetFiles(PluginsDirectory)) { if (!PluginPath.ToLower().EndsWith(".dll")) { continue; } Debug.Print("————————————————"); Debug.Print("发现插件链接库文件 : {0}", PluginPath); try { foreach (TemplateClass PluginInstance in CreatePluginInstance(PluginPath)) { PluginInstanceList.Add(PluginInstance); } } catch (Exception ex) { Debug.Print("加载插件遇到异常:{0}", ex.Message); } } return(PluginInstanceList); }
public override object Parse(ParserContext context) { if (string.IsNullOrWhiteSpace(context.Text)) { return(null); } PluginPathType pathType; string optionPath = context.Text; string[] memberNames; if (char.IsLetterOrDigit(optionPath[0])) { optionPath = '/' + optionPath; } if (PluginPath.TryResolvePath(optionPath, out pathType, out optionPath, out memberNames)) { object target = context.PluginContext.ApplicationContext.OptionManager.GetOptionObject(optionPath); if (target == null) { return(null); } return(Tiandao.Common.Converter.GetValue(target, memberNames)); } return(null); }
private PluginTreeNode GetControllerNode(RequestContext requestContext, string controllerName) { Route route = requestContext.RouteData.Route as Route; if (route == null) { return(null); } var controllerPath = string.Empty; var area = VirtualPathHelper.GetArea(requestContext.RouteData); if (string.IsNullOrWhiteSpace(area)) { controllerPath = PluginPath.Combine(ROOT_CONTROLLERS_PATH, controllerName); } else { controllerPath = PluginPath.Combine(ROOT_CONTROLLERS_PATH, area, controllerName); } requestContext.RouteData.DataTokens["area"] = area; requestContext.RouteData.DataTokens["controller.path"] = controllerPath; return(_pluginContext.PluginTree.Find(controllerPath)); }
private Task LoadBuildInPluginsAsync(IEnumerable <Assembly> builtInPlugins, CancellationToken cancellationToken) { var applicationRoot = Path.GetDirectoryName(typeof(Borg).Assembly.GetCodeBase()); return(Task.WhenAll(builtInPlugins .Select(a => a.GetName().Name) .Select(a => PluginPath.With(applicationRoot, $"{a}.dll")) .Select(p => _pluginManagementService.LoadPluginAsync(p, cancellationToken)))); }
public async Task<PluginInformation> LoadPluginAsync(PluginPath pluginPath, CancellationToken cancellationToken) { var plugin = await _pluginLoader.LoadPluginAsync(pluginPath, _pluginApiUri, cancellationToken).ConfigureAwait(false); var pluginInformation = await plugin.Plugin.GetPluginInformationAsync(cancellationToken).ConfigureAwait(false); _plugins.TryAdd(plugin.Id, plugin); return pluginInformation; }
public async Task <PluginInformation> LoadPluginAsync(PluginPath pluginPath, CancellationToken cancellationToken) { var plugin = await _pluginLoader.LoadPluginAsync(pluginPath, _pluginApiUri, cancellationToken).ConfigureAwait(false); var pluginInformation = await plugin.Plugin.GetPluginInformationAsync(cancellationToken).ConfigureAwait(false); _plugins.TryAdd(plugin.Id, plugin); return(pluginInformation); }
public Task <IReadOnlyCollection <PluginPath> > GetInstalledPluginsAsync(CancellationToken cancellationToken) { var pluginInstallPath = _configuration.PluginInstallPath; var pluginPaths = _fileSystemClient.GetDirectories(pluginInstallPath) .Select(d => Path.Combine(d, $"{Path.GetFileName(d)}.dll")) .Where(_fileSystemClient.FileExists) .Select(p => PluginPath.With(p)) .ToList(); return(Task.FromResult <IReadOnlyCollection <PluginPath> >(pluginPaths)); }
public override int GetHashCode() { int hashCode = -1043047289; hashCode = (hashCode * -1521134295) + PluginPath.GetHashCode(); foreach (var pluginSetting in _pluginSettingsSorted) { hashCode = (hashCode * -1521134295) + pluginSetting.Key.GetHashCode(); hashCode = (hashCode * -1521134295) + pluginSetting.Value.GetHashCode(); } return(hashCode); }
public void ParseTestAdvance() { PluginPath path; path = PluginPath.Parse("@[key].workbench.title[0].Value"); Assert.NotNull(path); Assert.Equal(PathAnchor.None, path.Anchor); Assert.Equal("", path.Path); Assert.Equal(5, path.Members.Length); Assert.True(path.Members[0].IsIndexer); Assert.Equal(1, path.Members[0].Parameters.Length); Assert.Equal("key", path.Members[0].Parameters[0]); Assert.Equal("workbench", path.Members[1].Name); Assert.Equal("title", path.Members[2].Name); Assert.True(path.Members[3].IsIndexer); Assert.Equal(1, path.Members[3].Parameters.Length); Assert.Equal(0, path.Members[3].Parameters[0]); Assert.Equal("Value", path.Members[4].Name); path = PluginPath.Parse("../@[key].workbench.title[0].Value"); Assert.NotNull(path); Assert.Equal(PathAnchor.Parent, path.Anchor); Assert.Equal("..", path.Path); Assert.Equal(5, path.Members.Length); Assert.True(path.Members[0].IsIndexer); Assert.Equal(1, path.Members[0].Parameters.Length); Assert.Equal("key", path.Members[0].Parameters[0]); Assert.Equal("workbench", path.Members[1].Name); Assert.Equal("title", path.Members[2].Name); Assert.True(path.Members[3].IsIndexer); Assert.Equal(1, path.Members[3].Parameters.Length); Assert.Equal(0, path.Members[3].Parameters[0]); Assert.Equal("Value", path.Members[4].Name); path = PluginPath.Parse(@".. / @ [ 'k\' ey' ] . workbench . title[ 0 ].Value"); Assert.NotNull(path); Assert.Equal(PathAnchor.Parent, path.Anchor); Assert.Equal("..", path.Path); Assert.Equal(5, path.Members.Length); Assert.True(path.Members[0].IsIndexer); Assert.Equal(1, path.Members[0].Parameters.Length); Assert.Equal("k' ey", path.Members[0].Parameters[0]); Assert.Equal("workbench", path.Members[1].Name); Assert.Equal("title", path.Members[2].Name); Assert.True(path.Members[3].IsIndexer); Assert.Equal(1, path.Members[3].Parameters.Length); Assert.Equal(0, path.Members[3].Parameters[0]); Assert.Equal("Value", path.Members[4].Name); }
private async Task <IPluginProxy> InternalLoadPluginAsync(PluginPath pluginPath, Uri pluginApiUri, CancellationToken cancellationToken) { var pluginId = pluginPath.GetPluginId(); var token = Token.NewFor(pluginId); using (_logger.Time($"Loading plugin '{pluginId}'")) { var appDomainSetup = new AppDomainSetup { ShadowCopyFiles = "true", LoaderOptimization = LoaderOptimization.MultiDomain, }; var configFilePath = $"{pluginPath.Value}.config"; if (File.Exists(configFilePath)) { appDomainSetup.ConfigurationFile = configFilePath; } var appDomain = _appDomainManager.CreateDomain(pluginId.Value, null, appDomainSetup); var pluginHost = appDomain.CreateInstanceAndUnwrap(Assembly.GetAssembly(typeof(PluginHostClient)).FullName, typeof(PluginHostClient).ToString()) as PluginHostClient; var autoResetEvent = new AutoResetEvent(false); var clientPort = TcpHelper.GetFreePort(); try { pluginHost.Launch(pluginPath.Value, appDomain, pluginApiUri, clientPort, token.Value); autoResetEvent.Set(); } catch (Exception e) { _logger.Error(e, $"Plugin '{pluginId}' failed"); AppDomain.Unload(appDomain); throw; } var pluginProxy = new PluginProxy( pluginId, appDomain, new Plugin(_logger, new Uri($"http://127.0.0.1:{clientPort}"), _restClient)); await pluginProxy.Plugin.PingAsync(cancellationToken).ConfigureAwait(false); return(pluginProxy); } }
private async Task<IPluginProxy> InternalLoadPluginAsync(PluginPath pluginPath, Uri pluginApiUri, CancellationToken cancellationToken) { var pluginId = pluginPath.GetPluginId(); var token = Token.NewFor(pluginId); using (_logger.Time($"Loading plugin '{pluginId}'")) { var appDomainSetup = new AppDomainSetup { ShadowCopyFiles = "true", LoaderOptimization = LoaderOptimization.MultiDomain, }; var configFilePath = $"{pluginPath.Value}.config"; if (File.Exists(configFilePath)) { appDomainSetup.ConfigurationFile = configFilePath; } var appDomain = _appDomainManager.CreateDomain(pluginId.Value, null, appDomainSetup); var pluginHost = appDomain.CreateInstanceAndUnwrap(Assembly.GetAssembly(typeof(PluginHostClient)).FullName, typeof(PluginHostClient).ToString()) as PluginHostClient; var autoResetEvent = new AutoResetEvent(false); var clientPort = TcpHelper.GetFreePort(); try { pluginHost.Launch(pluginPath.Value, appDomain, pluginApiUri, clientPort, token.Value); autoResetEvent.Set(); } catch (Exception e) { _logger.Error(e, $"Plugin '{pluginId}' failed"); AppDomain.Unload(appDomain); throw; } var pluginProxy = new PluginProxy( pluginId, appDomain, new Plugin(_logger, new Uri($"http://127.0.0.1:{clientPort}"), _restClient)); await pluginProxy.Plugin.PingAsync(cancellationToken).ConfigureAwait(false); return pluginProxy; } }
public void GetInstalledPluginsAsync() { // Arrange _fileSystemClientMock .Setup(f => f.GetDirectories(@"c:\plugins")) .Returns(new[] { @"c:\plugins\plugin.fancy", @"c:\plugins\plugin.magic" }); _fileSystemClientMock .Setup(f => f.FileExists(It.IsAny <string>())) .Returns(true); // Act var pluginPaths = Sut.GetInstalledPluginsAsync(C).Result; // Assert pluginPaths.ShouldAllBeEquivalentTo(new [] { PluginPath.With(@"c:\plugins", "plugin.fancy", "plugin.fancy.dll"), PluginPath.With(@"c:\plugins", "plugin.magic", "plugin.magic.dll") }); }
// Continue from our constructor to initialize our module public void Initialize(IHttpServer server) { m_log.Info("[SLIPSTREAM]: Running Initialize"); Server = server; string modulepath = String.Empty; m_log.InfoFormat("[SLIPSTREAM]: Module Loading. Path {0}/{1}", PluginPath, ServiceModuleName); if (PluginPath.Contains(".dll")) { modulepath = PluginPath; } else { modulepath = String.Format("{0}/{1}", PluginPath, ServiceModuleName); } Object[] args = new Object[] { Config, ConfigName }; ServiceModule = ServerUtils.LoadPlugin <IService>(modulepath, args); server.AddStreamHandler(new GetHandler(ServiceModule)); }
public override object Parse(ParserContext context) { if (string.IsNullOrWhiteSpace(context.Text)) { return(null); } var expression = PluginPath.Parse(context.Text); if (expression != null) { object target = context.PluginContext.ApplicationContext.OptionManager.GetOptionValue(expression.Path); if (target != null) { return(Reflection.MemberAccess.GetMemberValue <object>(target, expression.Members)); } } return(null); }
protected override void OnStart(string[] args) { this.PluginContext.PluginTree.Mount(PluginPath.Combine(this.PluginContext.Settings.WorkbenchPath, "Web"), this.Web); this.PluginContext.PluginTree.Mount(PluginPath.Combine(this.PluginContext.Settings.WorkbenchPath, "Web", "ViewEngines"), this.Web.ViewEngines); this.PluginContext.PluginTree.Mount(PluginPath.Combine(this.PluginContext.Settings.WorkbenchPath, "Web", "Api"), this.Web.Api); var routeProvider = this.Web.RouteProvider; if(routeProvider != null) { foreach(var token in routeProvider.GetRoutes()) { var route = token.ToRoute(); if(route is RouteBase) RouteTable.Routes.Add((RouteBase)route); else if(route is IHttpRoute) GlobalConfiguration.Configuration.Routes.Add(token.Name, (IHttpRoute)route); } } //启用XML序列化器,否则会导致未显式指定内容格式的请求无法序列化 GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear(); //GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = false; //初始化JSON格式化器的参数 if(GlobalConfiguration.Configuration.Formatters.JsonFormatter != null) { GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; var contractResolver = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ContractResolver as Newtonsoft.Json.Serialization.DefaultContractResolver; if(contractResolver != null) contractResolver.IgnoreSerializableAttribute = true; } //调用基类同名方法,以启动工作台下Startup下的所有工作者 base.OnStart(args); }
public override Type GetValueType(ParserContext context) { if (string.IsNullOrWhiteSpace(context.Text)) { return(null); } //处理特殊路径表达式,即获取插件文件路径或目录 if (context.Text.StartsWith("~")) { return(typeof(string)); } var expression = PluginPath.Parse(PluginPath.PreparePathText(context.Text)); var node = context.Node.Find(expression.Path); if (node != null && node.ValueType != null) { return(Reflection.MemberAccess.GetMemberType(node.ValueType, expression.Members)); } return(null); }
public override Type GetValueType(ParserContext context) { if (string.IsNullOrWhiteSpace(context.Text)) { return(null); } //处理特殊路径表达式,即获取插件文件路径或目录 if (context.Text.StartsWith("~")) { return(typeof(string)); } var expression = Collections.HierarchicalExpression.Parse(PluginPath.PreparePathText(context.Text)); var node = context.Node.Find(expression.Path); if (node != null && node.ValueType != null) { return(PluginUtility.GetMemberType(expression.Accessor, node.ValueType)); } return(null); }
public PluginServiceProvider(Builtin builtin) : base(builtin.Name) { var path = builtin.Properties.GetRawValue("path"); if (string.IsNullOrWhiteSpace(path)) { if (string.Equals(builtin.FullPath, SERVICES_PATH, StringComparison.OrdinalIgnoreCase)) { _path = builtin.FullPath; } else { _path = PluginPath.Combine(SERVICES_PATH, builtin.Name); } } else { _path = path == "." ? builtin.FullPath : path; } _context = builtin.Context; this.Storage = new PluginServiceStorage(this); }
public Task <IPluginProxy> LoadPluginAsync(PluginPath pluginPath, Uri pluginApiUri, CancellationToken cancellationToken) { return(Task.Run(() => InternalLoadPluginAsync(pluginPath, pluginApiUri, cancellationToken), cancellationToken)); }
public Task<IPluginProxy> LoadPluginAsync(PluginPath pluginPath, Uri pluginApiUri, CancellationToken cancellationToken) { return Task.Run(() => InternalLoadPluginAsync(pluginPath, pluginApiUri, cancellationToken), cancellationToken); }
public void ParseTest() { PluginPath path; path = PluginPath.Parse(""); Assert.Null(path); path = PluginPath.Parse(" "); Assert.Null(path); path = PluginPath.Parse("."); Assert.NotNull(path); Assert.Equal(PathAnchor.Current, path.Anchor); Assert.Equal(".", path.Path); Assert.Equal(0, path.Members.Length); path = PluginPath.Parse(".."); Assert.NotNull(path); Assert.Equal(PathAnchor.Parent, path.Anchor); Assert.Equal("..", path.Path); Assert.Equal(0, path.Members.Length); path = PluginPath.Parse("/"); Assert.NotNull(path); Assert.Equal(PathAnchor.Root, path.Anchor); Assert.Equal("/", path.Path); Assert.Equal(0, path.Members.Length); path = PluginPath.Parse("workbench.title"); Assert.NotNull(path); Assert.Equal(PathAnchor.None, path.Anchor); Assert.Equal("workbench", path.Path); Assert.Equal(1, path.Members.Length); Assert.Equal("title", path.Members[0].Name); path = PluginPath.Parse("/workbench.title"); Assert.NotNull(path); Assert.Equal(PathAnchor.Root, path.Anchor); Assert.Equal("/workbench", path.Path); Assert.Equal(1, path.Members.Length); Assert.Equal("title", path.Members[0].Name); path = PluginPath.Parse("./workbench.title"); Assert.NotNull(path); Assert.Equal(PathAnchor.Current, path.Anchor); Assert.Equal("./workbench", path.Path); Assert.Equal(1, path.Members.Length); Assert.Equal("title", path.Members[0].Name); path = PluginPath.Parse("../workbench.title"); Assert.NotNull(path); Assert.Equal(PathAnchor.Parent, path.Anchor); Assert.Equal("../workbench", path.Path); Assert.Equal(1, path.Members.Length); Assert.Equal("title", path.Members[0].Name); path = PluginPath.Parse("@workbench.title"); Assert.NotNull(path); Assert.Equal(PathAnchor.None, path.Anchor); Assert.Equal("", path.Path); Assert.Equal(2, path.Members.Length); Assert.Equal("workbench", path.Members[0].Name); Assert.Equal("title", path.Members[1].Name); path = PluginPath.Parse("*****@*****.**"); Assert.NotNull(path); Assert.Equal(PathAnchor.Current, path.Anchor); Assert.Equal(".", path.Path); Assert.Equal(2, path.Members.Length); Assert.Equal("workbench", path.Members[0].Name); Assert.Equal("title", path.Members[1].Name); path = PluginPath.Parse("./@workbench.title"); Assert.NotNull(path); Assert.Equal(PathAnchor.Current, path.Anchor); Assert.Equal(".", path.Path); Assert.Equal(2, path.Members.Length); Assert.Equal("workbench", path.Members[0].Name); Assert.Equal("title", path.Members[1].Name); path = PluginPath.Parse("../@Property"); Assert.NotNull(path); Assert.Equal(PathAnchor.Parent, path.Anchor); Assert.Equal("..", path.Path); Assert.Equal(1, path.Members.Length); Assert.Equal("Property", path.Members[0].Name); path = PluginPath.Parse("../@workbench.title"); Assert.NotNull(path); Assert.Equal(PathAnchor.Parent, path.Anchor); Assert.Equal("..", path.Path); Assert.Equal(2, path.Members.Length); Assert.Equal("workbench", path.Members[0].Name); Assert.Equal("title", path.Members[1].Name); path = PluginPath.Parse("../@workbench.title[0]"); Assert.NotNull(path); Assert.Equal(PathAnchor.Parent, path.Anchor); Assert.Equal("..", path.Path); Assert.Equal(3, path.Members.Length); Assert.Equal("workbench", path.Members[0].Name); Assert.Equal("title", path.Members[1].Name); Assert.True(path.Members[2].IsIndexer); Assert.True(string.IsNullOrEmpty(path.Members[2].Name)); Assert.Equal(1, path.Members[2].Parameters.Length); Assert.Equal(0, path.Members[2].Parameters[0]); }
/// <summary>获取插件目录</summary> /// <returns></returns> public String GetPluginPath() => PluginPath.GetBasePath();
/// <summary>获取插件目录</summary> /// <returns></returns> public String GetPluginPath() { return(PluginPath.GetBasePath()); }
private string pluginPath(string name) => '"' + (PluginPath.CombineWith(name) + (Env.IsWindows ? ".exe" : "")).Replace("\\", "/") + '"';