Ejemplo n.º 1
0
 public void StopRecord(NatsService natsService)
 {
     natsService.Connected    -= OnConnected;
     natsService.Disconnected -= OnDisconnected;
     natsService.MessageSent  -= OnMessageSent;
     natsService.Subscribed   -= OnSubscribed;
     natsService.Unsubscribed -= OnUnsubscribed;
 }
Ejemplo n.º 2
0
 public void StartRecord(NatsService natsService, ScriptService scriptService)
 {
     Script = scriptService.Current;
     natsService.Connected    += OnConnected;
     natsService.Disconnected += OnDisconnected;
     natsService.MessageSent  += OnMessageSent;
     natsService.Subscribed   += OnSubscribed;
     natsService.Unsubscribed += OnUnsubscribed;
 }
Ejemplo n.º 3
0
        public void Execute(Job job)
        {
            var natsService = new NatsService();

            job.StartTime = DateTime.Now;
            job.Status    = ExecutionStatus.Running;
            Stopwatch sw             = new Stopwatch();
            var       scriptCommands = job.Commands.ToArray();

            Logger.Info($"Execute: Begin, Nb Commands: {scriptCommands}");
            for (var i = 0; i < scriptCommands.Length; i++)
            {
                var scriptCommand = scriptCommands[i];
                Logger.Info($"Execute[{i+1}/{scriptCommands.Length}]: {scriptCommand}");
                try
                {
                    scriptCommand.TimeStamp = DateTime.Now;
                    sw.Restart();
                    scriptCommand.Status = ExecutionStatus.Running;
                    CommandUpdated?.Invoke(scriptCommand);
                    var result = scriptCommand.Execute(natsService, this);
                    sw.Stop();
                    scriptCommand.Status = ExecutionStatus.Executed;
                    scriptCommand.Result = result;
                    JobUpdated?.Invoke(job);
                    Logger.Info($"Executed: {result}");
                }
                catch (Exception e)
                {
                    sw.Stop();
                    Logger.Error($"Command failed ! {scriptCommand}");
                    scriptCommand.Status = ExecutionStatus.Failed;
                    scriptCommand.Result = e.Message;
                }

                scriptCommand.Duration = sw.Elapsed;
                CommandUpdated?.Invoke(scriptCommand);
            }

            job.EndTime = DateTime.Now;
            job.Status  = ExecutionStatus.Executed;
            Logger.Info($"Execute: End, TotalTime: {job.Duration}");
            JobUpdated?.Invoke(job);
            natsService.Dispose();

            var nextJob = Jobs.FirstOrDefault(aJob => aJob.Status == ExecutionStatus.Waiting);

            if (nextJob != null)
            {
                Execute(nextJob);
            }
        }