private bool UnzipWithTool(string zipArchivePath, string unzipFolder) { var unzipTool = ProcessLauncher.UnzipExe; if (unzipTool == null) { AddError("failed to find the \"unzip\" utility program in path. This program is required to maintain Linux file permissions in the zip archive."); return(false); } return(ProcessLauncher.Execute( unzipTool, new[] { zipArchivePath, "-d", unzipFolder }, Directory.GetCurrentDirectory(), Settings.VerboseLevel >= VerboseLevel.Detailed )); }
private bool ZipWithTool(string zipArchivePath, string zipFolder) { var zipTool = ProcessLauncher.ZipExe; if (string.IsNullOrEmpty(zipTool)) { AddError("failed to find the \"zip\" utility program in path. This program is required to maintain Linux file permissions in the zip archive."); return(false); } return(ProcessLauncher.Execute( zipTool, new[] { "-r", zipArchivePath, "." }, zipFolder, Settings.VerboseLevel >= VerboseLevel.Detailed )); }
private bool DotNetLambdaPackage(string targetFramework, string buildConfiguration, string outputPackagePath, string projectDirectory) { var dotNetExe = ProcessLauncher.DotNetExe; if (string.IsNullOrEmpty(dotNetExe)) { AddError("failed to find the \"dotnet\" executable in path."); return(false); } return(ProcessLauncher.Execute( dotNetExe, new[] { "lambda", "package", "-c", buildConfiguration, "-f", targetFramework, "-o", outputPackagePath }, projectDirectory, Settings.VerboseLevel >= VerboseLevel.Detailed )); }
private bool DotNetRestore(string projectDirectory) { var dotNetExe = ProcessLauncher.DotNetExe; if (string.IsNullOrEmpty(dotNetExe)) { AddError("failed to find the \"dotnet\" executable in path."); return(false); } return(ProcessLauncher.Execute( dotNetExe, new[] { "restore" }, projectDirectory, Settings.VerboseLevel >= VerboseLevel.Detailed )); }
public static string Process( FunctionItem function, bool skipCompile, bool noAssemblyValidation, string gitSha, string gitBranch, string buildConfiguration, bool showOutput ) { function.Language = "scala"; var projectDirectory = Path.GetDirectoryName(function.Project); // check if we need a default handler if (function.Function.Handler == null) { throw new Exception("The function handler cannot be empty for Scala functions."); } // compile function and create assembly if (!skipCompile) { ProcessLauncher.Execute( "sbt", new[] { "assembly" }, projectDirectory, showOutput ); } // check if we need to set a default runtime if (function.Function.Runtime == null) { function.Function.Runtime = "java8"; } // check if the project zip file was created var scalaOutputJar = Path.Combine(projectDirectory, "target", "scala-2.12", "app.jar"); return(scalaOutputJar); }
/// <summary> /// Export to Excel /// </summary> private void btnExpToExcel_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e) { string tempFileName = Path.ChangeExtension(Path.GetTempFileName(), ".xlsx"); gridView_Logs.ExportToXlsx(tempFileName); if (File.Exists(tempFileName)) { ProcessLauncher plauncher = new ProcessLauncher(tempFileName) { Verb = "open", WaitForExit = false, WindowStyle = System.Diagnostics.ProcessWindowStyle.Maximized }; plauncher.Execute(); } }
private bool LambdaSharpCreateInvocationSchemas( string buildFolder, string rootNamespace, string handler, IEnumerable <ApiGatewayInvocationMapping> mappings ) { // check if there is anything to do if (!mappings.Any()) { return(true); } // check if we have enough information to resolve the invocation methods var incompleteMappings = mappings.Where(mapping => !StringEx.TryParseAssemblyClassMethodReference( mapping.Method, out var mappingAssemblyName, out var mappingClassName, out var mappingMethodName ) || (mappingAssemblyName == null) || (mappingClassName == null) ).ToList(); if (incompleteMappings.Any()) { if (handler == null) { LogError("either function 'Handler' attribute must be specified as a literal value or all invocation methods must be fully qualified"); return(false); } // extract the assembly and class name from the handler if (!StringEx.TryParseAssemblyClassMethodReference( handler, out var lambdaFunctionAssemblyName, out var lambdaFunctionClassName, out var lambdaFunctionEntryPointName )) { LogError("'Handler' attribute has invalid value"); return(false); } // set default qualifier to the class name of the function handler foreach (var mapping in incompleteMappings) { if (!StringEx.TryParseAssemblyClassMethodReference( mapping.Method, out var mappingAssemblyName, out var mappingClassName, out var mappingMethodName )) { LogError("'Invoke' attribute has invalid value"); return(false); } mapping.Method = $"{mappingAssemblyName ?? lambdaFunctionAssemblyName}::{mappingClassName ?? lambdaFunctionClassName}::{mappingMethodName}"; } } // build invocation arguments string tmpSchemaFile = Path.GetTempFileName(); var arguments = new[] { "util", "create-invoke-methods-schema", "--directory", buildFolder, "--default-namespace", rootNamespace, "--out", tmpSchemaFile, "--quiet" } .Union(mappings.Select(mapping => $"--method={mapping.Method}")) .ToList(); // check if lambdasharp is installed or if we need to run it using dotnet var lambdaSharpFolder = Environment.GetEnvironmentVariable("LAMBDASHARP"); if (lambdaSharpFolder == null) { // check if lash executable exists (it should since we're running) var lash = ProcessLauncher.Lash; if (string.IsNullOrEmpty(lash)) { LogError("failed to find the \"lash\" executable in path."); return(false); } var success = ProcessLauncher.Execute( lash, arguments, Settings.WorkingDirectory, Settings.VerboseLevel >= VerboseLevel.Detailed ); } else { // check if dotnet executable exists var dotNetExe = ProcessLauncher.DotNetExe; if (string.IsNullOrEmpty(dotNetExe)) { LogError("failed to find the \"dotnet\" executable in path."); return(false); } var success = ProcessLauncher.Execute( dotNetExe, new[] { "run", "-p", $"{lambdaSharpFolder}/src/LambdaSharp.Tool", "--" }.Union(arguments).ToList(), Settings.WorkingDirectory, Settings.VerboseLevel >= VerboseLevel.Detailed ); } try { try { var schemas = (Dictionary <string, InvocationTargetDefinition>)JsonConvert.DeserializeObject <Dictionary <string, InvocationTargetDefinition> >(File.ReadAllText(tmpSchemaFile)).ConvertJTokenToNative(type => type == typeof(InvocationTargetDefinition)); foreach (var mapping in mappings) { if (!schemas.TryGetValue(mapping.Method, out var invocationTarget)) { LogError($"failed to resolve method '{mapping.Method}'"); continue; } if (invocationTarget.Error != null) { LogError(invocationTarget.Error); continue; } // update mapping information mapping.Method = $"{invocationTarget.Assembly}::{invocationTarget.Type}::{invocationTarget.Method}"; if (mapping.RestApiSource != null) { mapping.RestApiSource.RequestContentType = mapping.RestApiSource.RequestContentType ?? invocationTarget.RequestContentType; mapping.RestApiSource.RequestSchema = mapping.RestApiSource.RequestSchema ?? invocationTarget.RequestSchema; mapping.RestApiSource.RequestSchemaName = mapping.RestApiSource.RequestSchemaName ?? invocationTarget.RequestSchemaName; mapping.RestApiSource.ResponseContentType = mapping.RestApiSource.ResponseContentType ?? invocationTarget.ResponseContentType; mapping.RestApiSource.ResponseSchema = mapping.RestApiSource.ResponseSchema ?? invocationTarget.ResponseSchema; mapping.RestApiSource.ResponseSchemaName = mapping.RestApiSource.ResponseSchemaName ?? invocationTarget.ResponseSchemaName; mapping.RestApiSource.OperationName = mapping.RestApiSource.OperationName ?? invocationTarget.Method; // determine which uri parameters come from the request path vs. the query-string var uriParameters = new Dictionary <string, bool>(invocationTarget.UriParameters ?? Enumerable.Empty <KeyValuePair <string, bool> >()); foreach (var pathParameter in mapping.RestApiSource.Path .Where(segment => segment.StartsWith("{", StringComparison.Ordinal) && segment.EndsWith("}", StringComparison.Ordinal)) .Select(segment => segment.ToIdentifier()) .ToArray() ) { uriParameters.Remove(pathParameter); } // remaining uri parameters must be supplied as query parameters if (uriParameters.Any()) { if (mapping.RestApiSource.QueryStringParameters == null) { mapping.RestApiSource.QueryStringParameters = new Dictionary <string, bool>(); } foreach (var uriParameter in uriParameters) { // either record new query-string parameter or upgrade requirements for an existing one if (!mapping.RestApiSource.QueryStringParameters.TryGetValue(uriParameter.Key, out var existingRequiredValue) || !existingRequiredValue) { mapping.RestApiSource.QueryStringParameters[uriParameter.Key] = uriParameter.Value; } } } } if (mapping.WebSocketSource != null) { mapping.WebSocketSource.RequestContentType = mapping.WebSocketSource.RequestContentType ?? invocationTarget.RequestContentType; mapping.WebSocketSource.RequestSchema = mapping.WebSocketSource.RequestSchema ?? invocationTarget.RequestSchema; mapping.WebSocketSource.RequestSchemaName = mapping.WebSocketSource.RequestSchemaName ?? invocationTarget.RequestSchemaName; mapping.WebSocketSource.ResponseContentType = mapping.WebSocketSource.ResponseContentType ?? invocationTarget.ResponseContentType; mapping.WebSocketSource.ResponseSchema = mapping.WebSocketSource.ResponseSchema ?? invocationTarget.ResponseSchema; mapping.WebSocketSource.ResponseSchemaName = mapping.WebSocketSource.ResponseSchemaName ?? invocationTarget.ResponseSchemaName; mapping.WebSocketSource.OperationName = mapping.WebSocketSource.OperationName ?? invocationTarget.Method; } } } catch (Exception e) { LogError("unable to read create-invoke-methods-schema output", e); return(false); } } finally { try { File.Delete(tmpSchemaFile); } catch { LogWarn($"unable to delete temporary file: {tmpSchemaFile}"); } } return(true); }
private bool CheckDotNetLambdaToolIsInstalled() { // only run check once if (_dotnetLambdaToolVersionChecked) { return(_dotnetLambdaToolVersionValid); } _dotnetLambdaToolVersionChecked = true; // check if dotnet executable can be found var dotNetExe = ProcessLauncher.DotNetExe; if (string.IsNullOrEmpty(dotNetExe)) { LogError("failed to find the \"dotnet\" executable in path."); return(false); } // check if AWS Lambda Tools extension is installed var result = ProcessLauncher.ExecuteWithOutputCapture( dotNetExe, new[] { "lambda", "tool", "help" }, workingFolder: null ); if (result == null) { // attempt to install the AWS Lambda Tools extension if (!ProcessLauncher.Execute( dotNetExe, new[] { "tool", "install", "-g", "Amazon.Lambda.Tools" }, workingFolder: null, showOutput: false )) { LogError("'dotnet tool install -g Amazon.Lambda.Tools' command failed"); return(false); } // latest version is now installed, we're good to proceed _dotnetLambdaToolVersionValid = true; return(true); } // check version of installed AWS Lambda Tools extension var match = Regex.Match(result, @"\((?<Version>.*)\)"); if (!match.Success || !VersionInfo.TryParse(match.Groups["Version"].Value, out var version)) { LogWarn("proceeding compilation with unknown version of 'Amazon.Lambda.Tools'; please ensure latest version is installed"); _dotnetLambdaToolVersionValid = true; return(true); } if (version.CompareTo(VersionInfo.Parse(MIN_AWS_LAMBDA_TOOLS_VERSION)) < 0) { // attempt to install the AWS Lambda Tools extension if (!ProcessLauncher.Execute( dotNetExe, new[] { "tool", "update", "-g", "Amazon.Lambda.Tools" }, workingFolder: null, showOutput: false )) { LogError("'dotnet tool update -g Amazon.Lambda.Tools' command failed"); return(false); } } _dotnetLambdaToolVersionValid = true; return(true); }