示例#1
0
        public ApiConnexionMQTTMngr(string Url, int Port, string Username, string Password, ISpoolerPCComApi pSpooler)
        {
            // Create certificates
            _pSpooler = pSpooler;

            // Establish connexion
            _client = new MqttClient(Url, Port, false, null, null, MqttSslProtocols.None, null);
            var connectcode = _client.Connect(Guid.NewGuid().ToString(), Username, Password);

            _client.MqttMsgSubscribed      += this.MqttMsgSubscribed;
            _client.MqttMsgPublishReceived += this.MqttMsgPublishRecieved;
            _client.MqttMsgPublished       += this.MqttMsgPublished;
            Token = connectcode.ToString();
        }
        protected override void OnStart(string[] args)
        {
            // create dbconnexion from configuration file
            pSessionMgr = GetDBConnexion();

            // create spooler from factory
            pSpooler = (ISpoolerPCComApi)FactoryPccomApi.CreateSpooler(pSessionMgr);

            // register as observer
            pSpooler.register(this);

            // initialize spooler -> get operation cyclique
            mapSiteOperationCycliques = pSpooler.initialize(pSessionMgr);

            // démarrer le timer according to cyclic operations
            foreach (var listeSite in mapSiteOperationCycliques)
            { //on lance toutes les opérations cycliques par site
                var heures   = listeSite.Key.Heure;
                var minutes  = listeSite.Key.Minute;
                var secondes = listeSite.Key.Seconde;

                int periode = 24; // A lancer toutes les 24 heures
                int heure   = 0;
                int minute  = 0;
                int seconde = 0;
                var date    = DateTime.Now;

                if (heures == "*")
                {
                    periode = 1; // A lancer chaque heure
                    heure   = date.Hour;
                }
                else
                {
                    Int32.TryParse(heures, out heure);
                    Int32.TryParse(minutes, out minute);
                    Int32.TryParse(secondes, out seconde);
                }

                timers = new CyclicOperationTimer(date.Hour, date.Minute, date.Second + 20, periode, listeSite.Value, this);
                //       timers = new CyclicOperationTimer(heure, minute, seconde, periode, listeSite.Value, this);
            }
        }