Exemple #1
0
        static void Main()
        {
            try
            {
                // Inizializzazione configurazione Log4Net
                var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
                XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

                //Inizializzazione configurazione
                _config = Utils.Utils.ReadConfiguration();

                //Inizializzazione modulo di monitoring
                Modulo modulo = _config.Monitoring.Modules.Find(x => x.Name.Contains("Hub"));
                AliveServer(modulo.Ip, modulo.Port);

                //Inizializzazione client AMQP
                _amqpconn = new ClientAMQP();
                _amqpconn.CreateExchange(_config.Communications.AMQP.Exchange, ExchangeType.Direct.ToString());

                //Inizializzazione server MQTT e ricezione messaggi
                ServerMQTT mqttC = new ServerMQTT();
                mqttC.MessageReceived += OnMQTTMessageReceived;
                mqttC.StartAsync();
                mqttC.ReceiveAsync();

                _log.Info("HUB INIZIALIZZATO CORRETTAMENTE!");

                Console.ReadLine();
            }
            catch (Exception e)
            {
                _log.ErrorFormat("!ERROR: {0}", e.ToString());
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            try
            {
                _amqpconn = new ClientAMQP();
                _config   = Utils.Utils.ReadConfiguration();

                Modulo modulo = _config.Monitoring.Modules.Find(x => x.Name.Contains("Alerting"));
                AliveServer(modulo.Ip, modulo.Port);


                // Inizializzazione configurazione Log4Net
                var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
                XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

                var exchange = _config.Communications.AMQP.Exchange;
                var queue    = _config.Communications.AMQP.Queue;

                _amqpconn.CreateExchange(exchange, ExchangeType.Direct.ToString());

                //creo coda database
                _amqpconn.CreateQueue(queue);

                //bind coda database a exchange ed routing key 'common'
                //canale generale per la ricezione delle telemetrie da parte dell'hub
                _amqpconn.BindQueue(queue, exchange, "common");

                //bind coda database a exchange e routing key 'database'
                //riservato per le comunicazioni al modulo alerting (es. risposta query al modulo Dabase)
                _amqpconn.BindQueue(queue, exchange, "alerting");

                //imposto evento ricezione messaggi AMQP
                _amqpconn.AMQPMessageReceived += OnAMQPMessageReceived;
                _amqpconn.ReceiveMessageAsync(queue);

                //inizializzo connessione con MongoDB
                _client          = new MongoClient(_config.MongoDB.ConnectionString);
                _database        = _client.GetDatabase("MiniIoT");
                _rulesCollection = _database.GetCollection <Rule>("Rules");

                var currentPath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
                var filePath    = $"{currentPath}\\rules.json";

                // avvio timer regole ed email

                refreshRule      = new Timer(StartTasksToDB, null, 0, 10000);             // 10 secondi
                sendMailsInstant = new Timer(Communications.SendAll, null, 60000, 60000); // 1 minuto

                log.Info("ALERTING INIZIALIZZATO CORRETTAMENTE!");

                Console.ReadLine();
            }
            catch (Exception e)
            {
                log.Error($"Error: {e.Message}");
            }
        }
Exemple #3
0
        static void Main(string[] args)
        {
            try
            {
                // Inizializzazione configurazione Log4Net
                var logRepository = LogManager.GetRepository(Assembly.GetEntryAssembly());
                XmlConfigurator.Configure(logRepository, new FileInfo("log4net.config"));

                //Inizializzazione configurazione
                _config = Utils.Utils.ReadConfiguration();

                //Inizializzazione connessione con InfluxDB
                _dbconnection = new DBConnection();

                //Inizializzazione modulo di monitoring
                Modulo modulo = _config.Monitoring.Modules.Find(x => x.Name.Contains("Database"));
                AliveServer(modulo.Ip, modulo.Port);

                //Inizializzazione client AMQP
                _amqpconn = new ClientAMQP();
                var exchange = _config.Communications.AMQP.Exchange;
                var queue    = _config.Communications.AMQP.Queue;

                _amqpconn.CreateExchange(exchange, ExchangeType.Direct.ToString());

                //creo coda database
                _amqpconn.CreateQueue(queue);

                //bind coda database a exchange ed routing key 'common'
                //canale generale per la ricezione delle telemetrie da parte dell'hub
                _amqpconn.BindQueue(queue, exchange, "common");

                //bind coda database a exchange e routing key 'database'
                //riservato per le comunicazioni al database (es. richieste telemetrie da parte del modulo Alerting)
                _amqpconn.BindQueue(queue, exchange, "database");

                //imposto evento ricezione messaggi AMQP
                _amqpconn.AMQPMessageReceived += OnAMQPMessageReceived;
                _amqpconn.ReceiveMessageAsync(queue);

                log.Info("DATABASE INIZIALIZZATO CORRETTAMENTE!");
                Console.ReadLine();
            }
            catch (Exception e)
            {
                log.ErrorFormat("!ERROR: {0}", e.ToString());
            }
        }
Exemple #4
0
        public RulesController(IWebHostEnvironment hostEnvironment)
        {
            try
            {
                _hostingEnvironment = hostEnvironment;
                _config = Utils.Utils.ReadConfiguration();

                //inizializzo connessione con MongoDB
                _client = new MongoClient(_config.MongoDB.ConnectionString);
                _database = _client.GetDatabase("MiniIoT");
                _rulesCollection = _database.GetCollection<Models.Rule>("Rules");

                //Inizializzazione client AMQP 
                _amqpconn = new ClientAMQP();
                _amqpconn.CreateExchange(_config.Communications.AMQP.Exchange, ExchangeType.Direct.ToString());

                //creo coda management
                _amqpconn.CreateQueue("management");
                                
                //bind coda database a exchange e routing key 'database' 
                //riservato per le comunicazioni al database (es. richieste telemetrie da parte del modulo Alerting)
                _amqpconn.BindQueue("management", "direct_message", "management");

                //imposto evento ricezione messaggi AMQP
                _amqpconn.AMQPMessageReceived += OnAMQPMessageReceived;
                _amqpconn.ReceiveMessageAsync("management");


                taskCompletionSource = new TaskCompletionSource<string>();
            }
            catch(Exception e)
            {
                log.Error($"Error: {e.Message}");
            }
            
        }