/// <summary>
        /// Run loads assembly in <see cref="_assemblyPath"/> then:
        /// |> GetExportedTypes
        /// |> GetMethods
        /// |> Where method is SDK method
        /// |> Convert that to function.json
        /// |> Create folder \{functionName}\
        /// |> Write \{functionName}\function.json
        ///
        /// This means that every <see cref="MethodInfo"/> will be N binding objects on <see cref="FunctionJsonSchema"/>
        /// Where N == total number of SDK attributes on the method parameters.
        /// </summary>
        internal bool TryRun()
        {
            try
            {
                CleanOutputPath();
#if NET46
                var assembly = Assembly.LoadFrom(_assemblyPath);
#else
                var assembly = System.Runtime.Loader.AssemblyLoadContext.Default.LoadFromAssemblyPath(_assemblyPath);
#endif
                var relativeAssemblyPath = PathUtility.MakeRelativePath(Path.Combine(_outputPath, "dummyFunctionName"), assembly.Location);
                foreach (var type in assembly.GetExportedTypes())
                {
                    foreach (var method in type.GetMethods())
                    {
                        if (method.IsWebJobsSdkMethod())
                        {
                            var functionJson = method.ToFunctionJson(relativeAssemblyPath);
                            var functionName = method.GetSdkFunctionName();
                            var path         = Path.Combine(_outputPath, functionName, "function.json");
                            functionJson.Serialize(path);
                        }
                        else if (method.HasFunctionNameAttribute())
                        {
                            _log.LogWarning($"Method {method.Name} is missing a trigger attribute. Both a trigger attribute and FunctionName attribute are required for an Azure function definition.");
                        }
                        else if (method.HasWebJobSdkAttribute())
                        {
                            _log.LogWarning($"Method {method.Name} is missing the 'FunctionName' attribute. Both a trigger attribute and 'FunctionName' are required for an Azure function definition.");
                        }
                    }
                }

                return(true);
            }
            catch (Exception e)
            {
                _log.LogErrorFromException(e);
                return(false);
            }
        }
        private void CopyFunctionArtifacts()
        {
            var sourceFile = string.Empty;
            var targetFile = string.Empty;

            var assemblyDir = Path.GetDirectoryName(_assemblyPath);

            foreach (var file in _functionsArtifacts)
            {
                sourceFile = Path.Combine(assemblyDir, file);
                targetFile = Path.Combine(_outputPath, file);
                if (File.Exists(sourceFile) && !sourceFile.Equals(targetFile, StringComparison.OrdinalIgnoreCase))
                {
                    try
                    {
                        File.Copy(sourceFile, targetFile, overwrite: true);
                    }
                    catch (Exception e)
                    {
                        _log.LogWarning($"Unable to copy '{sourceFile}' to '{targetFile}'");
                        _log.LogWarningFromException(e);
                    }
                }
            }
        }
 public BuildArtifactsLog(string outputPath, FakeLogger logger)
 {
     _logger    = logger;
     _artifacts = new HashSet <string>(StringComparer.OrdinalIgnoreCase);
     _logPath   = Path.Combine(outputPath, buildArtifactsLogName);
     try
     {
         if (File.Exists(_logPath))
         {
             foreach (var line in File.ReadAllLines(_logPath))
             {
                 _artifacts.Add(line);
             }
         }
     }
     catch (Exception e)
     {
         _logger.LogWarning($"Unable to read file {_logPath}");
         _logger.LogWarningFromException(e);
     }
 }
 private bool Try(Action action, string message, bool isError)
 {
     try
     {
         action();
         return(true);
     }
     catch (Exception e)
     {
         if (isError)
         {
             _logger.LogError(message);
             _logger.LogErrorFromException(e);
         }
         else
         {
             _logger.LogWarning(message);
             _logger.LogWarningFromException(e);
         }
         return(!isError);
     }
 }