internal StreamingMessage ProcessFunctionLoadRequest(StreamingMessage request)
        {
            FunctionLoadRequest functionLoadRequest = request.FunctionLoadRequest;

            StreamingMessage response = NewStreamingMessageTemplate(
                request.RequestId,
                StreamingMessage.ContentOneofCase.FunctionLoadResponse,
                out StatusResult status);

            response.FunctionLoadResponse.FunctionId = functionLoadRequest.FunctionId;

            try
            {
                // Try loading the metadata of the function
                _functionLoader.Load(functionLoadRequest);

                // if we haven't yet, add the well-known Function App module path to the PSModulePath
                // The location of this module path is in a folder called "Modules" in the root of the Function App.
                if (!_prependedPath)
                {
                    string functionAppModulesPath = Path.GetFullPath(
                        Path.Combine(functionLoadRequest.Metadata.Directory, "..", "Modules"));
                    _powerShellManager.PrependToPSModulePath(functionAppModulesPath);
                    _prependedPath = true;
                }
            }
            catch (Exception e)
            {
                status.Status    = StatusResult.Types.Status.Failure;
                status.Exception = e.ToRpcException();
            }

            return(response);
        }
Exemple #2
0
        public void PrependingToPSModulePathShouldWork()
        {
            var logger  = new ConsoleLogger();
            var manager = new PowerShellManager(logger);
            var data    = "/some/unknown/directory";

            string modulePathBefore = Environment.GetEnvironmentVariable("PSModulePath");

            manager.PrependToPSModulePath(data);
            try
            {
                // the data path should be ahead of anything else
                Assert.Equal($"{data}{System.IO.Path.PathSeparator}{modulePathBefore}", Environment.GetEnvironmentVariable("PSModulePath"));
            }
            finally
            {
                // Set the PSModulePath back to what it was before
                Environment.SetEnvironmentVariable("PSModulePath", modulePathBefore);
            }
        }