コード例 #1
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;
                }
            }
        }
コード例 #2
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);
     }
 }