Пример #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_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e)
        {
            if (snapshot == null)
            {
                snapshot = DgvSnapshot(lbSysVariables, dgvSysVariables);
                if (snapshot.Name == "[Current]")
                {
                    EnvironmentVariableManager.Begin(snapshot.Target);
                }
            }
            var variable = snapshot.Variables[e.Row.Index];

            if (snapshot.Name == "[Current]")
            {
                EnvironmentVariableManager.DeleteEnvironmentVariable(variable.Name, snapshot.Target);
            }
            snapshot.Variables.Remove(variable);
        }