Beispiel #1
0
 private void PullConfig()
 {
     _workInProgressCaption = "Please wait...";
     _workInProgressText    = "Generating script...";
     _workInProgress.Run();
     DisableControls();
     try
     {
         if (cbCreateNewSet.Checked)
         {
             DateTime d = DateTime.Now;
             object   o = qTA.CloneConfigSet(_configurationSetID, string.Format("{0}_{1}{2}{3}{4}{5}{6}", tbSelConfigSetName.Text, d.Year, d.Month, d.Day, d.Hour, d.Minute, d.Second));
             _configurationSetID = Convert.ToInt32(o);
         }
         PGTDataSet.ScriptSettingRow _scriptSettings = PGT.Common.SettingsManager.GetCurrentScriptSettings(this.pgtDataSet);
         string sepChar         = _scriptSettings.CSVSeparator;
         string sExtendedHeader = string.Join(sepChar, Enum.GetNames(typeof(InputFileHeader)));
         sExtendedHeader += "SetTargetID";
         PGT.PGTScriptManager _ScriptManager = ScriptingFormManager.OpenNewScriptingForm();
         if (_ScriptManager != null)
         {
             ScriptManagers.Add(_ScriptManager);
             _ScriptManager.UpdateHeader(sExtendedHeader.Split(sepChar.ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
             _ScriptManager.OnScriptAborted  += _ScriptManager_OnScriptAborted;
             _ScriptManager.OnScriptFinished += _ScriptManager_OnScriptFinished;
             string thisLine = string.Empty;
             _ScriptManager.BeginAddingEntries();
             try
             {
                 int lastConfigTargetID = -1;
                 int targetCount        = clbTargets.CheckedItems.Count;
                 int targetNum          = 1;
                 foreach (var target in configDS.SetTargets)
                 {
                     if (IsTargetSelected(target.ConfigTargetID))
                     {
                         if (lastConfigTargetID == -1)
                         {
                             lastConfigTargetID = target.ConfigTargetID;
                         }
                         // Open a new ScriptinForm if script needs to be generated per configuration target
                         if (target.ConfigTargetID != lastConfigTargetID && cbScriptPerHost.Checked && (targetNum % (numHostPerForm.Value + 1) == 0))
                         {
                             if (_ScriptManager != null)
                             {
                                 _ScriptManager.EndAddingEntries();
                                 _ScriptManager.ExecuteScript(null, false);
                             }
                             _ScriptManager = ScriptingFormManager.OpenNewScriptingForm();
                             if (_ScriptManager == null)
                             {
                                 break;
                             }
                             _ScriptManager.OnScriptAborted  += _ScriptManager_OnScriptAborted;
                             _ScriptManager.OnScriptFinished += _ScriptManager_OnScriptFinished;
                             ScriptManagers.Add(_ScriptManager);
                             _ScriptManager.UpdateHeader(sExtendedHeader.Split(sepChar.ToCharArray(), StringSplitOptions.RemoveEmptyEntries));
                             _ScriptManager.BeginAddingEntries();
                             lastConfigTargetID = target.ConfigTargetID;
                         }
                         int configSetTargetID = cbCreateNewSet.Checked ? (int)qTA.GetConfigSetTargetID(_configurationSetID, target.ConfigTargetID) : target.ConfigSetTargetID;
                         thisLine = "1," + string.Concat(target.IsJumpServerIPNull() ? "" : target.JumpServerIP.Trim()) + "," + target.DeviceVendor + "," + target.TargetIP + string.Concat(target.IsPortNull() ? "," : string.Format(":{0},", target.Port)) + "" + "," + target.Protocol + "," + "sh run" + ",yes,,,"
                                    + ",,," + configSetTargetID;
                         if (!string.IsNullOrEmpty(thisLine))
                         {
                             bool added = _ScriptManager.AddEntry(thisLine, false);
                             if (!added)
                             {
                                 if (MessageBox.Show("There was an error adding a script line. Do you want to continue ?", "Script generation error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
                                 {
                                     break;
                                 }
                             }
                         }
                         targetNum++;
                     }
                 }
             }
             finally
             {
                 if (_ScriptManager != null)
                 {
                     _ScriptManager.EndAddingEntries();
                     _ScriptManager.ExecuteScript(null, false);
                 }
             }
         }
     }
     finally
     {
         _workInProgress.Cancel();
         _workInProgressSupportCancellation = false;
         btnPullConfig.Enabled       = ScriptManagers.Count == 0;
         lblOperationInProgress.Text = "Pulling configuration...";
         pbPullProgress.Value        = 0;
         pbPullProgress.Maximum      = ScriptManagers.Count;
         pbPullProgress.Visible      = ScriptManagers.Count > 1;
         btnCancelPull.Visible       = !btnPullConfig.Enabled;
     }
 }
Beispiel #2
0
 private void Deploy()
 {
     _workInProgress.Caption = "Please wait...";
     _workInProgress.Text    = "Generating script...";
     _workInProgress.Run();
     try
     {
         PGTDataSet.ScriptSettingRow _scriptSettings = PGT.Common.SettingsManager.GetCurrentScriptSettings(this.pgtDataSet);
         string sepChar         = _scriptSettings.CSVSeparator;
         string sExtendedHeader = string.Join(sepChar, Enum.GetNames(typeof(InputFileHeader)));
         sExtendedHeader += "ConfigLineID";
         PGT.PGTScriptManager _ScriptManager = ScriptingFormManager.OpenNewScriptingForm();
         if (_ScriptManager != null)
         {
             string thisLine = string.Empty;
             _ScriptManager.SetSavePrompt(false);
             _ScriptManager.BeginAddingEntries();
             try
             {
                 int lastConfigTargetID = (configDS.Deploy.Rows[0] as ConfigDS.DeployRow).ConfigTargetID;
                 int targetCount        = clbTargets.CheckedItems.Count;
                 int targetNum          = 0;
                 foreach (var configLine in configDS.Deploy)
                 {
                     if (IsTargetSelected(configLine.ConfigTargetID))
                     {
                         if (configLine.ConfigTargetID != lastConfigTargetID)
                         {
                             targetNum++;
                         }
                         // Open a new ScriptinForm if script needs to be generated per configuration target
                         if (configLine.ConfigTargetID != lastConfigTargetID && cbScriptPerHost.Checked && (targetNum > 0 && targetNum % numHostPerForm.Value == 0))
                         {
                             #region Open a new Scripting Form
                             if (_ScriptManager != null)
                             {
                                 _ScriptManager.EndAddingEntries();
                                 if (cbStartScripts.Checked)
                                 {
                                     _ScriptManager.ExecuteScript(null, false);
                                 }
                             }
                             _ScriptManager = ScriptingFormManager.OpenNewScriptingForm();
                             if (_ScriptManager == null)
                             {
                                 break;
                             }
                             _ScriptManager.SetSavePrompt(false);
                             _ScriptManager.BeginAddingEntries();
                             lastConfigTargetID = configLine.ConfigTargetID;
                             #endregion
                         }
                         thisLine = "1," + string.Concat(configLine.IsJumpServerIPNull() ? "" : configLine.JumpServerIP.Trim()) + "," + configLine.DeviceVendor + "," + configLine.TargetIP + string.Concat(configLine.IsPortNull() ? "," : string.Format(":{0},", configLine.Port)) + "" + "," + configLine.Protocol + "," + configLine.ConfigLine + ",yes,,,"
                                    + ",,,," + configLine.ConfigLineID;
                         if (!string.IsNullOrEmpty(thisLine))
                         {
                             bool added = _ScriptManager.AddEntry(thisLine, false);
                             if (!added)
                             {
                                 if (MessageBox.Show("There was an error adding a script line. Do you want to continue ?", "Script generation error", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No)
                                 {
                                     break;
                                 }
                             }
                         }
                     }
                     if (configLine.ConfigTargetID != lastConfigTargetID)
                     {
                         lastConfigTargetID = configLine.ConfigTargetID;
                     }
                 }
             }
             finally
             {
                 if (_ScriptManager != null)
                 {
                     _ScriptManager.EndAddingEntries();
                     if (cbStartScripts.Checked)
                     {
                         _ScriptManager.ExecuteScript(null, false);
                     }
                 }
             }
         }
     }
     finally
     {
         _workInProgress.Cancel();
         _workInProgressSupportCancellation = false;
         DialogResult = DialogResult.OK;
     }
 }