Exemple #1
0
 private static void TryReconnectMClientPark(object sender, EventArgs e)
 {
     mutexReconnect.WaitOne();
     if (mClientPark == null || !mClientPark.IsConnected)
     {
         Console.WriteLine("##############Try to reconnect mClientPark#############");
         mClientPark = Mosquitto.connectMosquittoGuaranteeThatTryToConnect(ipsParkDACE);
         if (mClientPark == null || !mClientPark.IsConnected)
         {
             System.Environment.Exit(1);
         }
         mClientPark.ConnectionClosed += TryReconnectMClientPark;
         Mosquitto.configFunctionMosquitto(mClientPark, mClientPark_MqttMsgPublishReceived);
         Mosquitto.subscribedMosquitto(mClientPark, topicsParkDACE[0]);
     }
     mutexReconnect.ReleaseMutex();
     mutex.ReleaseMutex();
 }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("#################################################################################");
            Console.WriteLine("###################################   INIT   ####################################");
            Console.WriteLine("#################################################################################\n\n");
            parkingsNameSubscribed = new List <string>();
            Console.WriteLine("#####################MOSQUITTO#####################");

            Console.WriteLine("####Connect to the topic " + topicsParkDACE[0] + "####");
            mClientPark = Mosquitto.connectMosquittoGuaranteeThatTryToConnect(ipsParkDACE);
            if (mClientPark == null || !mClientPark.IsConnected)
            {
                return;
            }
            mClientPark.ConnectionClosed += TryReconnectMClientPark;
            Console.WriteLine("####Connect to the other topics ####");
            mClient = Mosquitto.connectMosquittoGuaranteeThatTryToConnect(ipsParkDACE);
            if (mClient == null || !mClient.IsConnected)
            {
                return;
            }
            mClient.ConnectionClosed += TryReconnectMClient;
            Console.WriteLine("#####################END-Connection##################\n");

            String topicsSubscribe = "";

            Console.WriteLine("#######Config the mClientPark on topic " + topicsParkDACE[0] + "#######");
            Mosquitto.configFunctionMosquitto(mClientPark, mClientPark_MqttMsgPublishReceived);
            topicsSubscribe += "\n\t\t\t-'" + topicsParkDACE[0] + "'";
            Console.WriteLine("#####################END-Config##################\n");

            Console.WriteLine("#######Config the mClient on new topics#######");
            Mosquitto.configFunctionMosquitto(mClient, mClient_MqttMsgPublishReceived);
            Console.WriteLine("#####################END-Config##################\n");

            Console.WriteLine("You will be subscribe to the topic:" + topicsSubscribe);
            Console.WriteLine("#################END-Config-MOSQUITTO###############\n");
            Console.WriteLine("\n\n\n#################################################################################");
            Console.WriteLine("###########################   Starting Application   ############################");
            Console.WriteLine("#################################################################################\n\n");
            Mosquitto.subscribedMosquitto(mClientPark, topicsParkDACE[0]);
            mutexReconnect.ReleaseMutex();
            mutex.ReleaseMutex();
        }
Exemple #3
0
        private static void TryReconnect(object sender, EventArgs e)
        {
            if (mClient == null || !mClient.IsConnected)
            {
                Console.WriteLine("#####################MOSQUITTO#####################");
                mClient = Mosquitto.connectMosquittoGuaranteeThatTryToConnect(ips);
                if (mClient == null || !mClient.IsConnected)
                {
                    return;
                }
                mClient.ConnectionClosed += TryReconnect;
                Console.WriteLine("###################END-MOSQUITTO###################\n");
            }

            if (mClient == null || !mClient.IsConnected)
            {
                return;
            }
            mutex.ReleaseMutex();
        }
Exemple #4
0
 private static void TryReconnectMClient(object sender, EventArgs e)
 {
     mutexReconnect.WaitOne();
     if (mClient == null || !mClient.IsConnected)
     {
         Console.WriteLine("##############Try to reconnect mClient#############");
         mClient = Mosquitto.connectMosquittoGuaranteeThatTryToConnect(ipsParkDACE);
         if (mClient == null || !mClient.IsConnected)
         {
             System.Environment.Exit(1);
         }
         mClient.ConnectionClosed += TryReconnectMClient;
         Mosquitto.configFunctionMosquitto(mClient, mClient_MqttMsgPublishReceived);
         foreach (String parkingInformation in parkingsNameSubscribed)
         {
             Mosquitto.subscribedMosquitto(mClient, topicsParkDACE[0] + "" + parkingInformation);
         }
     }
     mutexReconnect.ReleaseMutex();
     mutex.ReleaseMutex();
 }
Exemple #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("#################################################################################");
            Console.WriteLine("###################################   INIT   ####################################");
            Console.WriteLine("#################################################################################\n\n");
            providers      = new List <Provider>();
            locationCampus = new List <LocationExcel>();
            timers         = new List <Timer>();
            Console.WriteLine("######################SETTINGS#####################");
            if (!FunctionHelper.ValidXMLParkingLocation("ParkingLocation.xml", "ParkingLocation.xsd"))
            {
                Console.WriteLine("####################END-SETTINGS###################\n");
                Console.WriteLine("Press any key to exit!");
                Console.ReadKey();
                return;
            }
            int time = ReadXMLParkingLocation("ParkingLocation.xml");

            if (providers == null || providers.ToArray().Length == 0)
            {
                Console.WriteLine("####################END-SETTINGS###################\n");
                Console.WriteLine("Press any key to exit!");
                Console.ReadKey();
                return;
            }
            Console.WriteLine("Xml is valid!");
            string topicsString = "ParkDACE\\, ParkDACE\\all";


            foreach (Provider provider in providers)
            {
                Console.WriteLine("");
                Console.WriteLine("Connection Type: " + provider.connectionType);
                Console.WriteLine("Endpoint: " + provider.endpoint);
                Console.WriteLine("parkInfo: ");
                Console.WriteLine("\tID: " + provider.parkInfoID);
                Console.WriteLine("\tDescription: " + provider.parkInfoDescription);
                Console.WriteLine("\tNumberOfSpots: " + provider.parkInfoNumberOfSpecialSpots);
                Console.WriteLine("\tOperatingHours: " + provider.parkInfoOperatingHours);
                Console.WriteLine("\tNumberOfSpecialSpots: " + provider.parkInfoNumberOfSpecialSpots);
                Console.WriteLine("\tGeoLocationFile: " + provider.parkInfoGeoLocationFile);
                Console.WriteLine("");

                topicsString += ", ParkDACE\\" + provider.parkInfoID;
            }
            Console.WriteLine("####################END-SETTINGS###################\n");

            Console.WriteLine("#####################MOSQUITTO#####################");
            mClient = Mosquitto.connectMosquittoGuaranteeThatTryToConnect(ips);
            if (mClient == null || !mClient.IsConnected)
            {
                Console.WriteLine("###################END-MOSQUITTO###################\n");
                Console.WriteLine("Press any key to exit!");
                Console.ReadKey();
                return;
            }
            mClient.ConnectionClosed += TryReconnect;
            Console.WriteLine("Topics that will be send data " + topicsString + "!");
            Console.WriteLine("###################END-MOSQUITTO###################\n");

            Console.WriteLine("\n\n\n#################################################################################");
            Console.WriteLine("###########################   Starting Application   ############################");
            Console.WriteLine("#################################################################################\n\n");
            foreach (Provider provider in providers)
            {
                locationCampus.Add(new LocationExcel(provider.parkInfoGeoLocationFile));
                if (provider.connectionType.Equals("DLL") || provider.endpoint.Equals("ParkingSensorNodeDll"))
                {
                    ParkingSensorNodeDll.ParkingSensorNodeDll dll = new ParkingSensorNodeDll.ParkingSensorNodeDll();
                    dll.Initialize(ComputeResponse, time);
                }
                else if (provider.connectionType.Equals("SOAP"))
                {
                    timers.Add(new Timer(new TimerCallback(timer_SOAP), provider, 1, time));
                }
            }
            timerParks = new Timer(new TimerCallback(timer_park_information_and_update), providers, 1, time);
            mutex.ReleaseMutex();
        }