Exemplo n.º 1
0
        public void Process(Guid scanId, SweepResultViewModel sweepData)
        {
            var factory = new ConnectionFactory()
            {
                HostName = _settings.RabbitMQServer,
                UserName = _settings.RabbitMQUserName,
                Password = _settings.RabbitMQPassword,
            };

            using (var connection = factory.CreateConnection())
                using (var channel = connection.CreateModel())
                {
                    channel.ExchangeDeclare(exchange: "ace_exchange", type: "topic", durable: true);

                    foreach (string message in sweepData.Data)
                    {
                        byte[] body = Encoding.UTF8.GetBytes(message);
                        string key  = sweepData.RoutingKey;

                        if (key.Contains("none"))
                        {
                            key = key.Replace("none.", "");
                        }

                        channel.BasicPublish(exchange: "ace_exchange",
                                             routingKey: key,
                                             basicProperties: null,
                                             body: body);
                    }
                }
        }
Exemplo n.º 2
0
 public IActionResult Post([FromRoute] Guid id, [FromBody] SweepResultViewModel result)
 {
     if (ModelState.IsValid)
     {
         _sweepProcessorService.Process(id, result);
         return(Ok());
     }
     else
     {
         return(BadRequest(ModelState));
     }
 }
Exemplo n.º 3
0
        public void Process(Guid sweepId, SweepResultViewModel scanData)
        {
            string resultsDir      = _sweepResultsDirectory + Path.DirectorySeparatorChar + sweepId + Path.DirectorySeparatorChar + scanData.ScanId;
            string resultsFileName = scanData.ScanType + "_" + scanData.ResultDate + "_" + scanData.ComputerName + "_" + scanData.ScanId + ".json";
            string resultsFile     = resultsDir + Path.DirectorySeparatorChar + Path.GetFileName(resultsFileName); // Prevent directory traversal

            if (!Directory.Exists(resultsDir))
            {
                Directory.CreateDirectory(resultsDir);
            }

            if (File.Exists(resultsFile))
            {
                throw new Exception("Results file already exists. Results file path: " + resultsFile);
            }

            foreach (string message in scanData.Data)
            {
                Console.WriteLine(message);
                File.AppendAllText(resultsFile, string.Format("{0}\r", message), Encoding.UTF8);
            }
        }