コード例 #1
0
        private void DeleteEnvVar(ListBox lb, DataGridView dgv)
        {
            var snapshot  = DgvSnapshot(lb, dgv);
            var variables = DgvVariables(lb, dgv);

            if (snapshot != null && variables != null && variables.Count > 0)
            {
                if (MessageBox.Show("Are you sure to remove these variables?", "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (snapshot.Name == "[Current]")
                    {
                        try
                        {
                            EnvironmentVariableManager.Begin(snapshot.Target);
                            foreach (var variable in variables)
                            {
                                EnvironmentVariableManager.DeleteEnvironmentVariable(variable.Name, snapshot.Target);
                                snapshot.Variables.Remove(variable);
                            }
                            EnvironmentVariableManager.End(snapshot.Target);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                    snapshotManager.SaveSnapshot(ref snapshot);
                    FillEnvironmentVariables(dgv, snapshot);
                }
            }
        }
コード例 #2
0
        private void ActivateSnapshot(ListBox lb)
        {
            int index = lb.SelectedIndex;

            if (index > 0)
            {
                EnvironmentVariableTarget target   = (EnvironmentVariableTarget)lb.Tag;
                EnvironmentSnapshot       snapshot = snapshotManager.GetSnapshot(index, target);
                EnvironmentSnapshot       current  = snapshotManager.GetSnapshot(0, target);
                if (snapshot != null)
                {
                    EnvironmentVariableManager.Begin(snapshot.Target);
                    foreach (var variable in current.Variables)
                    {
                        EnvironmentVariableManager.DeleteEnvironmentVariable(variable.Name, target);
                    }
                    current.Variables.Clear();
                    foreach (var variable in snapshot.Variables)
                    {
                        EnvironmentVariableManager.SetEnvironmentVariable(variable.Name, variable.Value, target);
                        current.Variables.Add(variable.Clone() as EnvironmentVariable);
                    }
                    EnvironmentVariableManager.End(snapshot.Target);
                    lb.SelectedIndex = 0;
                }
            }
        }
コード例 #3
0
 private void SaveEnvironmentVariable()
 {
     try
     {
         StringBuilder value = EnvironmentVariableValue();
         if (variable.Name.Length != 0 && variable.Name != txtVariableName.Text)
         {
             if (snapshot.Name == "[Current]")
             {
                 EnvironmentVariableManager.Begin(snapshot.Target);
                 EnvironmentVariableManager.DeleteEnvironmentVariable(variable.Name, snapshot.Target);
                 EnvironmentVariableManager.End(snapshot.Target);
             }
         }
         if (snapshot.Name == "[Current]")
         {
             EnvironmentVariableManager.Begin(snapshot.Target);
             EnvironmentVariableManager.SetEnvironmentVariable(txtVariableName.Text, value.ToString(), snapshot.Target);
             EnvironmentVariableManager.End(snapshot.Target);
         }
         variable.Name  = txtVariableName.Text;
         variable.Value = value.ToString();
         // Set initial program state
         commandsList.Clear();
         SetBtnState();
         //this.Close();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Validation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
コード例 #4
0
 private void dgvSysVariables_RowsRemoved(object sender, DataGridViewRowsRemovedEventArgs e)
 {
     if (snapshot != null)
     {
         if (snapshot.Name == "[Current]")
         {
             EnvironmentVariableManager.End(snapshot.Target);
         }
         snapshotManager.SaveSnapshot(ref snapshot);
         FillEnvironmentVariables(dgvSysVariables, snapshot);
         snapshot = null;
     }
 }