public void Mvc() { using (var plugin = new WebPlugin() { Name = "Hamster.Web" }) { plugin.Logger = new DebugLogger(plugin.Name); plugin.Settings = new WebPluginSettings() { Url = "http://localhost:8080/" }; plugin.Init(); plugin.AddApp("mvc", services => { services.AddMvc().AddApplicationPart(typeof(EchoController).Assembly); }, app => { app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Echo}/{action=Echo}/{id?}" ); }); }); plugin.Open(); Assert.Equal("foobar", WebRequest("http://localhost:8080/mvc")); } }
void OnGUI() { EditorGUILayout.Space(); EditorGUILayout.LabelField("Billing Plugin Setup", EditorStyles.boldLabel); EditorGUILayout.LabelField("Choose the store plugins you would like to use per platform:"); EditorGUILayout.Space(); EditorGUI.BeginChangeCheck(); androidPlugin = (AndroidPlugin)EditorGUILayout.EnumPopup("Android", androidPlugin); desktopPlugin = (DesktopPlugin)EditorGUILayout.EnumPopup("Standalone", desktopPlugin); webPlugin = (WebPlugin)EditorGUILayout.EnumPopup("WebGL", webPlugin); GUILayout.Space(15); playfabPlugin = (PlayfabPlugin)EditorGUILayout.EnumPopup("PlayFab Service", playfabPlugin); GUILayout.Space(20); EditorGUILayout.LabelField("Unity IAP will be used by default for all other platforms."); if (EditorGUI.EndChangeCheck()) { isChanged = true; } if (isChanged) { GUI.color = Color.yellow; } if (GUILayout.Button("Apply")) { ApplyScriptingDefines(); //SetPluginPlatformSettings(); isChanged = false; } }
public void TwoApps() { using (var plugin = new WebPlugin() { Name = "Hamster.Web" }) { plugin.Logger = new DebugLogger(plugin.Name); plugin.Settings = new WebPluginSettings() { Url = "http://localhost:8080/" }; plugin.Init(); plugin.AddApp("app1", services => {}, app => app.Run(async c => { await c.Response.WriteAsync("app1"); }) ); plugin.AddApp("app2", services => {}, app => app.Run(async c => { await c.Response.WriteAsync("app2"); }) ); plugin.Open(); Assert.Equal("app1", WebRequest("http://localhost:8080/app1")); Assert.Equal("app2", WebRequest("http://localhost:8080/app2")); } }
void OnEnable() { androidPlugin = (AndroidPlugin)FindScriptingDefineIndex(BuildTargetGroup.Android, androidPluginNames); desktopPlugin = (DesktopPlugin)FindScriptingDefineIndex(BuildTargetGroup.Standalone, desktopPluginNames); webPlugin = (WebPlugin)FindScriptingDefineIndex(BuildTargetGroup.WebGL, webPluginNames); //check if cross-platform use exists playfabPlugin = (PlayfabPlugin)FindScriptingDefineIndex(BuildTargetGroup.Android, playfabPluginNames); }
protected virtual WebPlugin GetPlugIn(int tenantId, PlugInTemplateMarkup plugIn, bool addIfMissing) { var retVal = db.WebPlugins.FirstOrDefault(n => n.TenantId == tenantId && n.UniqueName == plugIn.UniqueName); if (retVal == null && addIfMissing) { retVal = new WebPlugin { TenantId = tenantId, Constructor = plugIn.Constructor, UniqueName = plugIn.UniqueName, AutoLoad = plugIn.AutoLoad }; db.WebPlugins.Add(retVal); } return(retVal); }
public async Task <IActionResult> Create([DataSourceRequest] DataSourceRequest request, [FromQuery] int?tenantId) { if (!isSysAdmin) { tenantId = db.CurrentTenantId; } var model = new WebPlugin(); if (ModelState.IsValid) { await this.TryUpdateModelAsync <WebPluginViewModel, WebPlugin>(model); model.TenantId = tenantId; db.WebPlugins.Add(model); await db.SaveChangesAsync(); } return(Json(await new[] { model.ToViewModel <WebPlugin, WebPluginViewModel>() }.ToDataSourceResultAsync(request, ModelState))); }
public void AttributeGet() { var service = new Service(); using (var plugin = new WebPlugin() { Name = "Hamster.Web" }) { plugin.Logger = new DebugLogger(plugin.Name); plugin.Settings = new WebPluginSettings() { Url = "http://localhost:8081/" }; plugin.Init(); plugin.AddApp("api", new WebService <Service>(service, typeof(AttributeServiceController))); plugin.Open(); service.Data = "test1"; Assert.Equal("test1", WebRequest("http://localhost:8081/api/data")); service.Data = "test2"; Assert.Equal("test2", WebRequest("http://localhost:8081/api/data")); } }
public void ConfigurePlugin(WebPlugin pi) { logger?.Log(LogLevel.Debug, "Call to ConfigurePlugin is ignored for Settings-Plugins"); }
/// <summary> /// Copnfigures a Web-Plugin. This only works, when the Plugin-Configuration is writable /// </summary> /// <param name="pi">the plugin-member to modify</param> public void ConfigurePlugin(WebPlugin pi) { securityContext.SaveChanges(); }
protected virtual void RevokePlugin(int tenantId, WebPlugin plugIn) { }
/// <summary> /// Initializes a new i PluginFactory instance /// </summary> /// <returns>a Factory that can be used to load further plugins</returns> private PluginFactory CreateFactory() { var retVal = new PluginFactory(); LogEnvironment.OpenRegistrationTicket(retVal); retVal.AllowFactoryParameter = true; retVal.RegisterObject(Global.ServiceProviderName, serviceProvider); UnknownConstructorParameterEventHandler handler = (sender, args) => { PluginFactory pi = (PluginFactory)sender; IWebPluginsSelector availablePlugins = pluginProvider; var globalProvider = serviceProvider.GetService <IGlobalSettingsProvider>(); var tenantProvider = serviceProvider.GetService <IScopedSettingsProvider>(); var preInitializationSequence = tenantProvider?.GetJsonSetting($"PreInitSequenceFor{args.RequestedName}") ?? globalProvider?.GetJsonSetting($"PreInitSequenceFor{args.RequestedName}"); var postInitializationSequence = tenantProvider?.GetJsonSetting($"PostInitSequenceFor{args.RequestedName}") ?? globalProvider?.GetJsonSetting($"PostInitSequenceFor{args.RequestedName}"); var preInitSequence = DeserializeInitArray(preInitializationSequence); var postInitSequence = DeserializeInitArray(postInitializationSequence); WebPlugin plugin = availablePlugins.GetPlugin(args.RequestedName); if (plugin != null) { if (serviceProvider.VerifyUserPermissions(new [] { args.RequestedName }, true)) { if (preInitSequence.Length != 0) { foreach (var s in preInitSequence) { var tmp = pi[s, true]; } } if (!string.IsNullOrEmpty(plugin.Constructor)) { args.Value = pi.LoadPlugin <IPlugin>(plugin.UniqueName, plugin.Constructor); args.Handled = true; } if (postInitSequence.Length != 0) { foreach (var s in postInitSequence) { var tmp = pi[s, true]; } } } } else { var tmp = factoryOptions?.GetDependency(args.RequestedName, serviceProvider); args.Handled = tmp != null; args.Value = tmp; } }; void Initializer(object sender, PluginInitializedEventArgs args) { PluginLoadInterceptHelper.RunInterceptors(retVal, args.Plugin); } void Finalizer(object sender, EventArgs e) { LogEnvironment.DisposeRegistrationTicket(sender); var pi = (PluginFactory)sender; var dp = (IServiceProvider)pi.GetRegisteredObject(Global.ServiceProviderName); if (dp != null) { factory = null; } pi.Disposed -= Finalizer; pi.UnknownConstructorParameter -= handler; pi.PluginInitialized -= Initializer; pi.ImplementGenericType -= Implementer; } void Implementer(object sender, ImplementGenericTypeEventArgs args) { PluginFactory pi = (PluginFactory)sender; IWebPluginsSelector availablePlugins = pluginProvider; var impl = availablePlugins.GetGenericParameters(args.PluginUniqueName); if (impl != null) { var dic = new Dictionary <string, object>(); var assignments = (from t in args.GenericTypes join a in impl on t.GenericTypeName equals a.GenericTypeName select new { Arg = t, Type = a.TypeExpression }); foreach (var item in assignments) { item.Arg.TypeResult = (Type)ExpressionParser.Parse(item.Type.ApplyFormat(args), dic); } args.Handled = true; } } retVal.UnknownConstructorParameter += handler; retVal.PluginInitialized += Initializer; retVal.Disposed += Finalizer; retVal.ImplementGenericType += Implementer; return(retVal); }