internal DotNetFunctionInvoker(ScriptHost host, FunctionMetadata functionMetadata, Collection<FunctionBinding> inputBindings, Collection<FunctionBinding> outputBindings, IFunctionEntryPointResolver functionEntryPointResolver, FunctionAssemblyLoader assemblyLoader, ICompilationServiceFactory compilationServiceFactory, ITraceWriterFactory traceWriterFactory = null) : base(host, functionMetadata, traceWriterFactory) { _metricsLogger = Host.ScriptConfig.HostConfig.GetService<IMetricsLogger>(); _functionEntryPointResolver = functionEntryPointResolver; _assemblyLoader = assemblyLoader; _metadataResolver = new FunctionMetadataResolver(functionMetadata, host.ScriptConfig.BindingProviders, TraceWriter); _compilationService = compilationServiceFactory.CreateService(functionMetadata.ScriptType, _metadataResolver); _inputBindings = inputBindings; _outputBindings = outputBindings; _triggerInputName = functionMetadata.Bindings.FirstOrDefault(b => b.IsTrigger).Name; InitializeFileWatcher(); _resultProcessor = CreateResultProcessor(); _functionLoader = new FunctionLoader<MethodInfo>(CreateFunctionTarget); _reloadScript = ReloadScript; _reloadScript = _reloadScript.Debounce(); _restorePackages = RestorePackages; _restorePackages = _restorePackages.Debounce(); }
public void TestFunctionLoaderGetFunc() { var scriptFileToUse = Path.Join(_functionDirectory, "BasicFuncScript.ps1"); var entryPointToUse = string.Empty; var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse); FunctionLoader.LoadFunction(functionLoadRequest); var funcInfo = FunctionLoader.GetFunctionInfo(functionLoadRequest.FunctionId); Assert.Equal(scriptFileToUse, funcInfo.ScriptPath); Assert.Equal(string.Empty, funcInfo.EntryPoint); Assert.NotNull(funcInfo.FuncScriptBlock); Assert.Equal(2, funcInfo.FuncParameters.Count); Assert.True(funcInfo.FuncParameters.ContainsKey("req")); Assert.True(funcInfo.FuncParameters.ContainsKey("inputBlob")); Assert.Equal(3, funcInfo.AllBindings.Count); Assert.Equal(2, funcInfo.InputBindings.Count); Assert.Single(funcInfo.OutputBindings); }
public void ProfileWithNonTerminatingError() { //initialize fresh log _testLogger.FullLog.Clear(); var funcLoadReq = _functionLoadRequest.Clone(); funcLoadReq.Metadata.Directory = Path.Join(_functionDirectory, "ProfileWithNonTerminatingError", "Func1"); try { FunctionLoader.SetupWellKnownPaths(funcLoadReq); _testManager.PerformRunspaceLevelInitialization(); Assert.Equal(2, _testLogger.FullLog.Count); Assert.Equal("Error: ERROR: help me!", _testLogger.FullLog[0]); Assert.Matches("Error: Fail to run profile.ps1. See logs for detailed errors. Profile location: ", _testLogger.FullLog[1]); } finally { FunctionLoader.SetupWellKnownPaths(_functionLoadRequest); } }
public void TestFunctionLoaderGetFuncWithEntryPoint() { var functionId = Guid.NewGuid().ToString(); var directory = "/Users/tylerleonhardt/Desktop/Tech/PowerShell/AzureFunctions/azure-functions-powershell-worker/examples/PSCoreApp/MyHttpTrigger"; var scriptPathExpected = $"{directory}/run.ps1"; var entryPointExpected = "Foo"; var metadata = new RpcFunctionMetadata { Name = "MyHttpTrigger", EntryPoint = entryPointExpected, Directory = directory, ScriptFile = scriptPathExpected }; metadata.Bindings.Add("req", new BindingInfo { Direction = BindingInfo.Types.Direction.In, Type = "httpTrigger" }); metadata.Bindings.Add("res", new BindingInfo { Direction = BindingInfo.Types.Direction.Out, Type = "http" }); var functionLoadRequest = new FunctionLoadRequest { FunctionId = functionId, Metadata = metadata }; var functionLoader = new FunctionLoader(); functionLoader.Load(functionLoadRequest); var funcInfo = functionLoader.GetFunctionInfo(functionId); Assert.Equal(scriptPathExpected, funcInfo.ScriptPath); Assert.Equal(entryPointExpected, funcInfo.EntryPoint); }
public void TestFunctionLoaderGetFunc() { var functionId = Guid.NewGuid().ToString(); var directory = "/Users/azure/PSCoreApp/MyHttpTrigger"; var scriptPathExpected = $"{directory}/run.ps1"; var metadata = new RpcFunctionMetadata { Name = "MyHttpTrigger", EntryPoint = "", Directory = directory, ScriptFile = scriptPathExpected }; metadata.Bindings.Add("req", new BindingInfo { Direction = BindingInfo.Types.Direction.In, Type = "httpTrigger" }); metadata.Bindings.Add("res", new BindingInfo { Direction = BindingInfo.Types.Direction.Out, Type = "http" }); var functionLoadRequest = new FunctionLoadRequest { FunctionId = functionId, Metadata = metadata }; var functionLoader = new FunctionLoader(); functionLoader.Load(functionLoadRequest); var funcInfo = functionLoader.GetFunctionInfo(functionId); Assert.Equal(scriptPathExpected, funcInfo.ScriptPath); Assert.Equal("", funcInfo.EntryPoint); }
public PowerShellManagerTests() { _functionDirectory = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "TestScripts", "PowerShell"); _rpcFunctionMetadata = new RpcFunctionMetadata() { Name = "TestFuncApp", Directory = _functionDirectory, Bindings = { { TestInputBindingName, new BindingInfo { Direction = BindingInfo.Types.Direction.In, Type = "httpTrigger" } }, { TestOutputBindingName, new BindingInfo { Direction = BindingInfo.Types.Direction.Out, Type = "http" } } } }; _functionLoadRequest = new FunctionLoadRequest { FunctionId = "FunctionId", Metadata = _rpcFunctionMetadata }; FunctionLoader.SetupWellKnownPaths(_functionLoadRequest); _testLogger = new ConsoleLogger(); _testManager = new PowerShellManager(_testLogger); _testManager.PerformWorkerLevelInitialization(); _testInputData = new List <ParameterBinding> { new ParameterBinding { Name = TestInputBindingName, Data = new TypedData { String = TestStringData } } }; }
public void TestFunctionLoaderGetFuncWithEntryPoint() { var scriptFileToUse = Path.Join(_functionDirectory, "FuncWithEntryPoint.psm1"); var entryPointToUse = "Run"; var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse); var functionLoader = new FunctionLoader(); functionLoader.LoadFunction(functionLoadRequest); var funcInfo = functionLoader.GetFunctionInfo(functionLoadRequest.FunctionId); Assert.Equal(scriptFileToUse, funcInfo.ScriptPath); Assert.Equal(entryPointToUse, funcInfo.EntryPoint); Assert.Equal(2, funcInfo.FuncParameters.Count); Assert.Contains("req", funcInfo.FuncParameters); Assert.Contains("inputBlob", funcInfo.FuncParameters); Assert.Equal(3, funcInfo.AllBindings.Count); Assert.Equal(2, funcInfo.InputBindings.Count); Assert.Single(funcInfo.OutputBindings); }
static TestUtils() { FunctionDirectory = Path.Join(AppDomain.CurrentDomain.BaseDirectory, "TestScripts", "PowerShell"); RpcFunctionMetadata = new RpcFunctionMetadata() { Name = "TestFuncApp", Directory = FunctionDirectory, Bindings = { { TestInputBindingName, new BindingInfo { Direction = BindingInfo.Types.Direction.In, Type = "httpTrigger" } }, { TestOutputBindingName, new BindingInfo { Direction = BindingInfo.Types.Direction.Out, Type = "http" } } } }; FunctionLoadRequest = new FunctionLoadRequest { FunctionId = "FunctionId", Metadata = RpcFunctionMetadata }; FunctionLoader.SetupWellKnownPaths(FunctionLoadRequest); }
static void Main(string[] args) { Console.Title = "Producer"; var functionLoader = new FunctionLoader(); var producer = new DefaultProducer(functionLoader); using (var messageBuilder = new MessageBuilder(functionLoader)) { producer.CreateProducer("xxx"); var code1 = producer.SetProducerNameServerAddress("47.101.55.250:9876"); var code2 = producer.SetProducerLogLevel(LogLevel.Debug); var code3 = producer.StartProducer(); Console.WriteLine("press any key to send message."); Console.ReadKey(true); messageBuilder.CreateMessage("test"); var code4 = messageBuilder.SetMessageBody("hello" + Guid.NewGuid().ToString("N")); //var code5 = messageBuilder.SetMessageTags("xxxxfff中国"); //var code6 = messageBuilder.SetMessageKeys($"123:{Guid.NewGuid():N}"); //var code7 = messageBuilder.SetMessageProperty("key1", "value1"); //var code8 = messageBuilder.SetDelayTimeLevel(1); var result1 = producer.SendMessageSync(messageBuilder); //在 cpp sdk 未找到此方法 //var result2 = producer.SendMessageAsync(messageBuilder).GetAwaiter().GetResult(); //var result3 = producer.SendMessageOneway(messageBuilder); //var result4 = producer.SendMessageOrderly(messageBuilder, (size, message, arg) => { return 0; }, string.Empty, 1); } var code20 = producer.ShutdownProducer(); var code21 = producer.DestroyProducer(); }
public void TestFunctionLoaderGetFuncWithTriggerMetadataParam() { var scriptFileToUse = Path.Join(_functionDirectory, "BasicFuncScriptWithTriggerMetadata.ps1"); var entryPointToUse = string.Empty; var functionLoadRequest = GetFuncLoadRequest(scriptFileToUse, entryPointToUse); var functionLoader = new FunctionLoader(); functionLoader.LoadFunction(functionLoadRequest); var funcInfo = functionLoader.GetFunctionInfo(functionLoadRequest.FunctionId); Assert.Equal(scriptFileToUse, funcInfo.ScriptPath); Assert.Equal(string.Empty, funcInfo.EntryPoint); Assert.Equal(3, funcInfo.FuncParameters.Count); Assert.Contains("req", funcInfo.FuncParameters); Assert.Contains("inputBlob", funcInfo.FuncParameters); Assert.Contains("TriggerMetadata", funcInfo.FuncParameters); Assert.Equal(3, funcInfo.AllBindings.Count); Assert.Equal(2, funcInfo.InputBindings.Count); Assert.Single(funcInfo.OutputBindings); }
private static double GetFreeMemory() { IntPtr module = FunctionLoader.LoadLibrary("Win32Dll1.dll"); if (module == IntPtr.Zero) // error handling { return(0); } // get a "pointer" to the method IntPtr method = FunctionLoader.GetProcAddress(module, "GetFreeMemory"); if (method == IntPtr.Zero) // error handling { FunctionLoader.FreeLibrary(module); // unload library return(0); } // convert "pointer" to delegate DoubleVoidFunc f = (DoubleVoidFunc)Marshal.GetDelegateForFunctionPointer(method, typeof(DoubleVoidFunc)); // use function return(f()); }
public static T GetFunctionDelegate <T>(IntPtr libraryHandle, string functionName) => FunctionLoader.GetFunctionDelegate <T>(libraryHandle, functionName);
public static void ShowWindow(IntPtr hWnd, int nCmdShow) => FunctionLoader.Load <ShowWindow_t>("ShowWindow")(hWnd, nCmdShow);
public void Dispose() { FunctionLoader.ClearLoadedFunctions(); }
public static IntPtr GetConsoleWindow() => FunctionLoader.Load <GetConsoleWindow_t>("GetConsoleWindow")();
public void Dispose() { FunctionLoader.ClearLoadedFunctions(); s_testLogger.FullLog.Clear(); }
public void LoadNativeLibrary_Missing_ReturnsZero() { Assert.Equal(IntPtr.Zero, FunctionLoader.LoadNativeLibrary(new string[] { string.Empty })); }