Пример #1
0
        void ChangePORT()
        {
            if (TxtBx_PtChoix.Text != "")
            {
                if (TxtBx_PtChoix.Text != TxtBx_PtAct.Text)
                {
                    if (EntryVerificationPORT() == true)
                    {
                        try
                        {
                            string PT = TxtBx_PtChoix.Text;

                            string        String  = string.Format("Server = {0}; Database = {1}; User Id = {2}; Password = {3}", SQL_IP, SQL_DataBase, SQL_User, SQL_Pswd);
                            SqlConnection SQL_Cxn = new SqlConnection(String);

                            string        REQUETE = string.Format("UPDATE Table_Checkpoint SET NumPort = {0} WHERE IPCheckpoint = \'{1}\'", Convert.ToInt32(PT), IPLocal);
                            SqlCommand    CMD     = new SqlCommand();
                            SqlDataReader READER;

                            CMD.CommandText = REQUETE;
                            CMD.CommandType = CommandType.Text;
                            CMD.Connection  = SQL_Cxn;

                            SQL_Cxn.Open();

                            READER = CMD.ExecuteReader();

                            while (READER.Read())
                            {
                                if (!READER.IsDBNull(0))
                                {
                                }
                            }
                            SQL_Cxn.Close();

                            ChangementEffectue = true;
                        }
                        catch (SqlException)
                        {
                            MsgALERTAsync("Une erreur s'est produite lors de la connexion a la BDD.\nVérifiez si l'adresse de la BDD est correct et si vous êtes bien sur le bon réseau.");
                            ChangementEffectue = false;
                            throw;
                        }
                    }
                    else
                    {
                        TxtBx_IPChoix.Text = "";
                        MsgALERTAsync("PORT inutilisable..\nLes Ports utilisables sont compris entre 1024 et 49 151.");
                        ChangementEffectue = false;
                    }
                }
                else
                {
                    TxtBx_IPChoix.Text = "";
                    MsgALERTAsync("Le PORT est le même que celui déjà attribué.");
                    ChangementEffectue = false;
                }
            }
        }
Пример #2
0
        void GetPORT()
        {
            try
            {
                string        String  = string.Format("Server = {0}; Database = {1}; User Id = {2}; Password = {3}", SQL_IP, SQL_DataBase, SQL_User, SQL_Pswd);
                SqlConnection SQL_Cxn = new SqlConnection(String);

                string        REQUETE = string.Format("SELECT NumPort FROM Table_Checkpoint WHERE IPCheckpoint = '{0}'", IPLocal);
                SqlCommand    CMD     = new SqlCommand();
                SqlDataReader READER;

                CMD.CommandText = REQUETE;
                CMD.CommandType = CommandType.Text;
                CMD.Connection  = SQL_Cxn;

                SQL_Cxn.Open();

                READER = CMD.ExecuteReader();

                while (READER.Read())
                {
                    if (!READER.IsDBNull(0))
                    {
                        TxtBx_PtAct.Text = READER.GetInt32(0).ToString();
                        PORT             = READER.GetInt32(0);
                    }
                }

                SQL_Cxn.Close();
            }
            catch (SqlException)
            {
                MsgALERTAsync("Une erreur s'est produite lors de la récupération du PORT dans la BDD.\nVérifiez si l'adresse de la BDD est correct et si vous êtes bien sur le bon réseau.");
                throw;
            }
        }
Пример #3
0
        async void ChangeIPAddress(string ipAddress)
        {
            if (TxtBx_IPChoix.Text != "")
            {
                if (TxtBx_IPChoix.Text != IPLocal)
                {
                    if (EntryVerificationIP() == true)
                    {
                        try
                        {
                            string        String  = string.Format("Server = {0}; Database = {1}; User Id = {2}; Password = {3}", SQL_IP, SQL_DataBase, SQL_User, SQL_Pswd);
                            SqlConnection SQL_Cxn = new SqlConnection(String);

                            string        REQUETE = string.Format("UPDATE Table_Checkpoint SET IPCheckpoint = \'{0}\' WHERE IPCheckpoint = \'{1}\'", TxtBx_IPChoix.Text, IPLocal);
                            SqlCommand    CMD     = new SqlCommand();
                            SqlDataReader READER;

                            CMD.CommandText = REQUETE;
                            CMD.CommandType = CommandType.Text;
                            CMD.Connection  = SQL_Cxn;

                            SQL_Cxn.Open();

                            READER = CMD.ExecuteReader();

                            while (READER.Read())
                            {
                                if (!READER.IsDBNull(0))
                                {
                                }
                            }
                            SQL_Cxn.Close();

                            ChangementEffectue = true;
                        }
                        catch (SqlException)
                        {
                            MsgALERTAsync("Une erreur s'est produite lors du changement d'IP dans la BDD.\nVérifiez si l'adresse de la BDD est correct et si vous êtes bien sur le bon réseau.");
                            ChangementEffectue = false;
                            throw;
                        }

                        try
                        {
                            HttpClient client = new HttpClient();
                            client.BaseAddress = new System.Uri("http://127.0.0.1:8080/", UriKind.RelativeOrAbsolute);
                            client.DefaultRequestHeaders.Authorization =
                                new AuthenticationHeaderValue(
                                    "Basic",
                                    Convert.ToBase64String(
                                        System.Text.ASCIIEncoding.ASCII.GetBytes(
                                            string.Format("{0}:{1}", "administrator", "admin"))));

                            NetworkConfiguration networkConfiguration = new NetworkConfiguration()
                            {
                                AdapterName    = AdapterNamePI,
                                IPAddress      = ipAddress,
                                SubnetMask     = "255.255.255.0",
                                DefaultGateway = "192.168.0.254",
                                PrimaryDNS     = "192.168.0.254",
                                SecondryDNS    = "8.8.8.8"
                            };
                            string      json    = JsonConvert.SerializeObject(networkConfiguration);
                            HttpContent content = new StringContent(json);
                            var         result  = await client.PutAsync("api/networking/ipv4config", content);

                            ChangementEffectue = true;
                        }
                        catch (Exception)
                        {
                            ChangementEffectue = false;
                            throw;
                        }
                    }
                    else
                    {
                        MsgALERTAsync("L'IP rentrée est incorrect.\nL'IP doit etre sous forme : 192.168.0.X\nAvec X compris entre 1 et 254.\n");
                        TxtBx_IPChoix.Text = "";
                        ChangementEffectue = false;
                    }
                }
                else
                {
                    MsgALERTAsync("L'IP rentrée est la même que celle de la RPI.");
                    TxtBx_IPChoix.Text = "";
                    ChangementEffectue = false;
                }
            }
        }