Exemple #1
0
        private void BtnSaveClick(object sender, EventArgs e)
        {
            //Ricarica i parametri e li salva cifrati
            if (_currentConfiguration == null)
            {
                return;
            }

            // appSettings
            // Resetto i parametri
            _currentConfiguration.AppSettings.Settings.Clear();

            foreach (DataRow dr in ((DataTable)(((BindingSource)Parameters.DataSource).DataSource)).Rows)
            {
                var key   = dr["Key"].ToString();
                var value = dr["Value"].ToString();
                _currentConfiguration.AppSettings.Settings.Add(key, value);
            }

            //connectionStrings
            _currentConfiguration.ConnectionStrings.ConnectionStrings.Clear();

            foreach (DataRow dr in ((DataTable)(((BindingSource)ConnectionStrings.DataSource).DataSource)).Rows)
            {
                var key   = dr["Key"].ToString();
                var value = dr["Value"].ToString();
                _currentConfiguration.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings(key, value, "System.Data.SqlClient"));
            }

            // Endpoints
            var serviceModelSectionGroup = ServiceModelSectionGroup.GetSectionGroup(_currentConfiguration);

            if (serviceModelSectionGroup != null)
            {
                var endpointCollection = serviceModelSectionGroup.Client.Endpoints;
                endpointCollection.Clear();

                foreach (DataRow dr in ((DataTable)(((BindingSource)Clients.DataSource).DataSource)).Rows)
                {
                    var address = dr["address"].ToString();
                    var binding = dr["binding"].ToString();
                    var bindingConfiguration = dr["bindingConfiguration"].ToString();
                    var contract             = dr["contract"].ToString();
                    var name = dr["name"].ToString();
                    endpointCollection.Add(new ChannelEndpointElement
                    {
                        Address = new Uri(address),
                        Binding = binding,
                        BindingConfiguration = bindingConfiguration,
                        Contract             = contract,
                        Name = name
                    });
                }
            }

            // Salvo tutto il file
            ConfigurationManagerHelper.SaveConfiguration(_currentConfiguration, _liveUpdateClient, chkEncrypt.Checked);
        }