Exemplo n.º 1
0
        public override string Execute(NatsService natsService, ExecutorService executorService)
        {
            if (executorService.Message == null)
            {
                throw new ScriptCommandException("No received message !");
            }
            if (executorService.Message.Data == null)
            {
                throw new ScriptCommandException("No data in message !");
            }

            string data = executorService.Message.Data;
            IReadOnlyList <JsonElement> resultJson = JsonPath.ExecutePath(Param1, data);
            var result = JsonSerializer.Serialize(resultJson, new JsonSerializerOptions {
                WriteIndented = true
            });

            if (result == Param2)
            {
                return("Ok.");
            }

            Logger.Error($"Pattern: {Param1}");
            Logger.Error($"Data: {data}");
            Logger.Error($"Result: {result}");
            Logger.Error($"Expected: {Param2}");
            throw new ScriptCommandException("Result and Expected values are different !");
        }
Exemplo n.º 2
0
        public override string Execute(NatsService natsService, ExecutorService executorService)
        {
            var connection = new Connection($"{Param1}:{Param2}", Param1, int.Parse(Param2));
            var conn       = natsService.Connect(connection);

            return($"{conn.ConnectedUrl}: {conn.State}");
        }
Exemplo n.º 3
0
        public override string Execute(NatsService natsService, ExecutorService executorService)
        {
            var connection = new Connection($"{Param1}:{Param2}", Param1, int.Parse(Param2));

            natsService.Disconnect(connection);
            return($"Disconnect: {connection.Url}");
        }
Exemplo n.º 4
0
        public override string Execute(NatsService natsService, ExecutorService executorService)
        {
            if (executorService.Message == null)
            {
                throw new ScriptCommandException("No received message !");
            }
            if (executorService.Message.Data == null)
            {
                throw new ScriptCommandException("No data in message !");
            }

            string data  = executorService.Message.Data;
            Regex  regex = new Regex(Param1);
            var    match = regex.Match(data);

            if (match.Success && match.Groups.Count > 1)
            {
                var capture = match.Groups[1];
                if (capture.Value == Param2)
                {
                    return("Ok.");
                }

                Logger.Error($"Pattern: {Param1}");
                Logger.Error($"Data: {data}");
                Logger.Error($"Capture: {capture.Value}");
                Logger.Error($"Expected: {Param2}");
                throw new ScriptCommandException("Result and Expected values are different !");
            }
            Logger.Error($"Pattern: {Param2}");
            Logger.Error($"Data: {data}");
            throw new ScriptCommandException("No match for regex !");
        }
Exemplo n.º 5
0
        protected void SaveCapture()
        {
            var dataCapture = new DataCapture {
                Expression = Model.Expression, Name = Model.Name, Type = Model.CaptureType
            };

            NatsService.Configuration.DataCaptures.Add(dataCapture);
            NatsService.Save();
            DataCaptureGrid.Insert(0, dataCapture);
        }
Exemplo n.º 6
0
        protected void SaveMessage()
        {
            var message = new NatsMessage
            {
                Url     = Model.Url,
                Subject = Model.Url,
                Data    = Model.Data
            };

            NatsService.Save(message);
        }
Exemplo n.º 7
0
        protected void SaveMessage()
        {
            var message = new NatsMessage
            {
                TimeStamp = DateTime.Now,
                Subject   = Model.Subject,
                Data      = Model.Data
            };

            NatsService.Save(message);
        }
Exemplo n.º 8
0
        protected void CreateConnection()
        {
            Logger.Info($"CreateConnection: {null}");
            var connection = new Connection(Model.Name, Model.Host, Model.Port);

            if (NatsService.Create(connection, out var msg))
            {
                Connections.Insert(0, connection);
            }

            Status = msg;
            InvokeAsync(StateHasChanged);
        }
Exemplo n.º 9
0
        private void OnItemClicked(string colName, Session session)
        {
            switch (colName)
            {
            case nameof(Session.Trash):
                RemoveSession(session);
                break;

            case nameof(Session.Run):
                NatsService.Init(session);
                break;
            }
        }
Exemplo n.º 10
0
        protected void CreateSession()
        {
            Logger.Info($"{nameof(CreateSession)}: {Model}");
            var session = new Session(Model.Name)
            {
                Checked = false,
            };

            NatsService.Create(session, out _);
            NatsService.Save();
            Sessions.SetData(NatsService.Configuration.Sessions);
            OnSelectedItemChanged(session);
        }
Exemplo n.º 11
0
        private void OnItemClicked(string colName, NatsMessage message)
        {
            switch (colName)
            {
            case nameof(NatsMessage.Inspect):
                Inspector.Data = message.Data;
                NavMgr.NavigateTo("/inspector");
                break;

            case nameof(NatsMessage.Pin):
                NatsService.Save(message.Clone());
                break;
            }
        }
Exemplo n.º 12
0
        private void Publish(string subject, string data)
        {
            foreach ((int i, Connection item)connection in UrlGrid.GetCheckedItems())
            {
                var msg = new NatsMessage
                {
                    TimeStamp = DateTime.Now,
                    Url       = connection.item.Url,
                    Subject   = subject,
                    Data      = data
                };

                NatsService.Publish(msg);
            }
        }
Exemplo n.º 13
0
        public override string Execute(NatsService natsService, ExecutorService executorService)
        {
            foreach (var connection in natsService.Connections)
            {
                NatsMessage msg = new NatsMessage
                {
                    Subject = Param1,
                    Data    = Param2,
                    Url     = connection.Url
                };
                natsService.Publish(msg);
            }

            return("Message sent.");
        }
Exemplo n.º 14
0
        protected void CreateSubscription()
        {
            Logger.Info($"{nameof(CreateSubscription)}: {Model}");
            var natsSubscription = new NatsSubscription(Model.Subject)
            {
                Checked    = false,
                Subscribed = false
            };

            if (NatsService.Create(natsSubscription, out _))
            {
                Subscriptions.Insert(0, natsSubscription);
            }
            Subscribe(natsSubscription);
        }
Exemplo n.º 15
0
        protected void RequestMessage()
        {
            foreach ((int i, Connection item)connection in UrlGrid.GetCheckedItems())
            {
                var message = new NatsMessage
                {
                    TimeStamp = DateTime.Now,
                    Url       = connection.item.Url,
                    Subject   = Model.Subject,
                    Data      = Model.Data
                };

                NatsService.Request(message);
            }
        }
Exemplo n.º 16
0
        private void OnItemClicked(string colName, DataCapture dataCapture)
        {
            switch (colName)
            {
            case nameof(DataCapture.Trash):
                NatsService.Configuration.DataCaptures.Remove(dataCapture);
                NatsService.Save();
                DataCaptureGrid.Remove(dataCapture);
                break;

            case nameof(DataCapture.Run):
                OnSelectedItemChanged(dataCapture);
                TestCapture();
                break;
            }
            InvokeAsync(StateHasChanged);
        }
Exemplo n.º 17
0
        private void OnItemClicked(string colName, NatsSubscription subscription)
        {
            switch (colName)
            {
            case nameof(NatsSubscription.Unsubscribe):
                Unsubscribe(subscription);
                break;

            case nameof(NatsSubscription.Subscribe):
                Subscribe(subscription);
                break;

            case nameof(NatsSubscription.Trash):
                Logger.Info($"{nameof(NatsSubscription.Trash)}: {subscription}");
                NatsService.Remove(subscription);
                Subscriptions.Remove(subscription);
                break;
            }
        }
Exemplo n.º 18
0
        private void OnItemClicked(string colName, NatsMessage message)
        {
            switch (colName)
            {
            case nameof(NatsMessage.Inspect):
                Inspector.Data = message.Data;
                NavMgr.NavigateTo("/inspector");
                break;

            case nameof(NatsMessage.Run):
                Publish(message.Subject, message.Data);
                break;

            case nameof(NatsMessage.Trash):
                NatsService.Configuration.SavedMessages.Remove(message);
                NatsService.Save();
                MessageGrid.Remove(message);
                break;
            }
        }
Exemplo n.º 19
0
        public override string Execute(NatsService natsService, ExecutorService executorService)
        {
            natsService.MessageReceived += OnMessageReceived;
            var      nbMs = (int)(1000 * double.Parse(Param1));
            DateTime now  = DateTime.Now;

            while (Message == null && (DateTime.Now - now).TotalMilliseconds < nbMs)
            {
                Thread.Sleep(10);
            }

            natsService.MessageReceived -= OnMessageReceived;
            if (Message == null)
            {
                throw new TimeoutException("No message received !");
            }

            executorService.Message = Message;
            return("Message received !");
        }
Exemplo n.º 20
0
        public override string Execute(NatsService natsService, ExecutorService executorService)
        {
            var result = "";

            foreach (var connection in natsService.Connections)
            {
                NatsMessage msg = new NatsMessage
                {
                    Subject = Param1,
                    Data    = Param2,
                    Url     = connection.Url
                };
                var reply = natsService.Request(msg, 1000);
                result += $"Url: {connection.Url} ";
                result += $"Data: {reply?.Data ?? "No data !"}";
                executorService.Message = reply;
            }

            return(result);
        }
Exemplo n.º 21
0
        protected NatsResponder(NatsService natsService)
        {
            _natsService = natsService;

            var methods = GetType().GetMethods();

            foreach (var methodInfo in methods)
            {
                if (!methodInfo.IsPublic || methodInfo.IsStatic)
                {
                    continue;
                }

                var methodParams = methodInfo.GetParameters();
                if (methodParams.Length == 1 && typeof(INatsRequest).IsAssignableFrom(methodParams.First().ParameterType))
                {
                    var eventName = methodParams.First().ParameterType.FullName;
                    _natsService.Subscribe(eventName, methodInfo, this, methodParams.First().ParameterType);
                }
            }
        }
Exemplo n.º 22
0
        private void OnItemClicked(string colName, Connection connection)
        {
            switch (colName)
            {
            case nameof(Connection.Trash):
                Logger.Info($"RemoveConnection: {connection}");
                NatsService.Remove(connection);
                Connections.Remove(connection);
                break;

            case nameof(Connection.Run):
                Connect(connection);
                Connections.Update(connection);
                break;

            case nameof(Connection.Stop):
                Disconnect(connection);
                Connections.Update(connection);
                break;
            }
        }
Exemplo n.º 23
0
 public DiscordResponder(DiscordService discordService, NatsService natsService) : base(natsService)
 {
     _discordService = discordService;
 }
Exemplo n.º 24
0
 private void Subscribe(NatsSubscription subscription)
 {
     Logger.Info($"{nameof(NatsSubscription.Subscribe)}: {subscription}");
     NatsService.Subscribe(subscription);
     Subscriptions.Update(subscription);
 }
Exemplo n.º 25
0
 public override string Execute(NatsService natsService, ExecutorService executorService)
 {
     return(Param1);
 }
Exemplo n.º 26
0
 public override string Execute(NatsService natsService, ExecutorService executorService)
 {
     natsService.Subscribe(new NatsSubscription(Param1));
     return("Subscribed.");
 }
Exemplo n.º 27
0
 protected void RemoveSession(Session session)
 {
     Logger.Info($"{nameof(RemoveSession)}: {session}");
     NatsService.Remove(session);
     Sessions.Remove(session);
 }
Exemplo n.º 28
0
 private void Connect(Connection connection)
 {
     Logger.Info($"{nameof(Connect)}: {connection.Url}");
     NatsService.Connect(connection);
 }
Exemplo n.º 29
0
 private void OnItemDoubleClicked(string colName, Session session)
 {
     NatsService.Init(session);
 }
Exemplo n.º 30
0
 public QuotesResponder(QuoteService quoteService, NatsService natsService) : base(natsService)
 {
     _quoteService = quoteService;
 }