コード例 #1
0
        //TODO mettre cette methode dans la Config en static
        //TODO tester avec 2 users pour voir les accès concurent
        /// <summary>
        /// Recupere le fichier de configuration en local (config.remote.json)
        /// ou dans le repertoire ProgramData\HylaNotify\config.remote.json
        /// permettant de recuperer les donnees essentielles au fonctionnement du programme
        /// (menu, adresse Api, Adresse RabbitMQ, etc...)
        /// </summary>
        /// <returns>La config locale</returns>
        private void SetupConfiguration()
        {
            // Fichier %ALLUSERSPROFILE%
            allUserPath = Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData)
                          + @"\HylaNotify\config.remote.json";

            //conf dans l'exe
            exePath = Application.StartupPath + @"\" + "config.local.json";
            Log.Info(File.Exists(allUserPath) ?
                     "fichier config %ALLUSERS% existe"
                : "fichier config %ALLUSERS% existe pas");
            Log.Info(File.Exists(exePath) ?
                     "fichier config EXE Hylanotify existe"
                : "fichier config EXE Hylanotify existe pas");

            bool allUserExist = File.Exists(allUserPath);

            // Recupère la config local soit dans %ALLUSERSPROFILE% soit dans l'EXE
            Config = Config.getLocalFileConfig(allUserPath, exePath);

            //Si pas de config ni dans %ALLUSER% ni dans l'exe
            if (Config == null)
            {
                string            message = "Aucun fichier de configuration détecté\nArrêt de HylaNotify !";
                string            caption = "Erreur de démarrage";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                MessageBox.Show(message, caption, buttons);
                ExitApplication();
            }
            ////////////////////////////METTRE DANS GETLOCALCONFIG
            // On recupere un serveur valide ayant acces a l'API
            Api.Server = Api.GetServer();

            // TODO on recupere les 2IPs et on fait un appel a l'API
            // Tant que la config n'est pas a jour
            while (!IsConfigUpdate)
            {
                Log.Debug("Checksum locale: " + Config.items.conf.checksum);
                Log.Debug("Préparation de la configuration");
                CheckConfig();
                System.Threading.Thread.Sleep(1000);
                if (!IsConfigUpdate)
                {
                    //Si le fichier dans alluser n'existe pas on attend sa réecriture
                    if (!allUserExist)
                    {
                        CheckConfig();
                        System.Threading.Thread.Sleep(3000);
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(3000);
                    }
                }
            }
        }