private void SendLogsToServer(string mainScriptFilePath, JobExecutionParams jobExecutionParams)
        {
            var logger = new Logging().GetLogger(jobExecutionParams);

            try
            {
                // Get Log File Path
                var logsFilePath = Directory.GetFiles(Directory.GetParent(mainScriptFilePath).FullName,
                                                      Path.GetFileNameWithoutExtension(mainScriptFilePath) + "*.log").FirstOrDefault();

                if (logsFilePath != null && File.Exists(logsFilePath))
                {
                    var logs = File.ReadAllLines(logsFilePath).ToList();
                    foreach (var log in logs)
                    {
                        if (log.Trim() == string.Empty ||
                            log.ToLower().StartsWith("start - automation started") ||
                            log.ToLower().StartsWith("finish - automation finished"))
                        {
                            continue;
                        }

                        logger.Information(log.Trim());
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                logger.Dispose();
            }
        }
        public void ExecuteScript(JobExecutionParams executionParams)
        {
            var engineContext = GetEngineContext(executionParams);
            var engine        = new AutomationEngineInstance(engineContext);

            engine.ExecuteScriptSync();
        }
示例#3
0
        private Logger GetLogger(JobExecutionParams executionParams)
        {
            Logger logger = null;

            // Get Minimum Log Level
            LogEventLevel minLogLevel;

            Enum.TryParse(executionParams.ServerConnectionSettings.TracingLevel, out minLogLevel);

            // Get Log Sink Type (File, HTTP)
            SinkType sinkType;

            Enum.TryParse(executionParams.ServerConnectionSettings.SinkType, out sinkType);

            switch (sinkType)
            {
            case SinkType.File:
                string logFile = Path.Combine(executionParams.ServerConnectionSettings.LoggingValue1);
                logger = new Logging().CreateFileLogger(logFile, Serilog.RollingInterval.Day, minLogLevel);

                break;

            case SinkType.Http:
                logger = new Logging().CreateHTTPLogger(executionParams,
                                                        executionParams.ServerConnectionSettings.LoggingValue1, minLogLevel);

                break;
            }

            return(logger);
        }
示例#4
0
        private string GetExecutionParams(string mainScriptFilePath, ServerConnectionSettings settings, List <string> projectDependencies)
        {
            var executionParams = new JobExecutionParams()
            {
                MainFilePath             = mainScriptFilePath,
                ProjectDirectoryPath     = Path.GetDirectoryName(mainScriptFilePath),
                ProjectDependencies      = projectDependencies,
                ServerConnectionSettings = settings
            };
            var paramsJsonString = JsonConvert.SerializeObject(executionParams);

            return(DataFormatter.CompressString(paramsJsonString));
        }
示例#5
0
        static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                // Get Execution Parameters
                var paramsJsonString = DataFormatter.DecompressString(args[0].ToString());
                JobExecutionParams executionParams = JsonConvert.DeserializeObject <JobExecutionParams>(paramsJsonString);

                EngineHandler executor = new EngineHandler();
                executor.LoadProjectAssemblies(executionParams.ProjectDependencies);
                executor.ExecuteScript(executionParams);
            }
        }
 private EngineContext GetEngineContext(JobExecutionParams executionParams)
 {
     return(new EngineContext
     {
         FilePath = executionParams.MainFilePath,
         ProjectPath = executionParams.ProjectDirectoryPath,
         EngineLogger = new Logging().GetLogger(executionParams),
         Container = _container,
         Arguments = executionParams.JobParameters?.Select(arg =>
                                                           new ScriptArgument
         {
             ArgumentName = arg.Name,
             ArgumentValue = arg.Value
         }).ToList()
     });
 }
        private string GetExecutionParams(Job job, Automation automation, string mainScriptFilePath, List <string> projectDependencies)
        {
            var executionParams = new JobExecutionParams()
            {
                JobId                    = job.Id.ToString(),
                AutomationId             = automation.Id.ToString(),
                AutomationName           = automation.Name,
                MainFilePath             = mainScriptFilePath,
                ProjectDirectoryPath     = Path.GetDirectoryName(mainScriptFilePath),
                JobParameters            = GetJobParameters(job.Id.ToString()),
                ProjectDependencies      = projectDependencies,
                ServerConnectionSettings = _connectionSettingsManager.ConnectionSettings
            };
            var paramsJsonString = JsonConvert.SerializeObject(executionParams);

            return(DataFormatter.CompressString(paramsJsonString));
        }
示例#8
0
        public Logger CreateHTTPLogger(JobExecutionParams executionParams, string uri, LogEventLevel minLogLevel = LogEventLevel.Verbose)
        {
            try
            {
                var levelSwitch = new LoggingLevelSwitch();
                levelSwitch.MinimumLevel = minLogLevel;

                return(new LoggerConfiguration()
                       .Enrich.WithProperty("JobId", executionParams.JobId)
                       .Enrich.WithProperty("AutomationId", executionParams.AutomationId)
                       .Enrich.WithProperty("AutomationName", executionParams.AutomationName)
                       .Enrich.WithProperty("AgentId", executionParams.ServerConnectionSettings.AgentId)
                       .Enrich.WithProperty("AgentName", executionParams.ServerConnectionSettings.AgentName)
                       .Enrich.WithProperty("MachineName", executionParams.ServerConnectionSettings.MachineName)
                       .MinimumLevel.ControlledBy(levelSwitch)
                       .WriteTo.Http(uri)
                       .CreateLogger());
            }
            catch (Exception)
            {
                return(null);
            }
        }