Example #1
0
        /// <summary>
        /// Terminates a script specified by its ScriptManager
        /// </summary>
        /// <param name="thisManager"></param>
        private void TerminateScript(SNGScriptManager thisManager)
        {
            bool stopped = false;

            try
            {
                int waitTime = (int)SettingsManager.GetCurrentScriptSettings(this.SNGDataSet).ConnectTimeout.TotalMilliseconds;
                DebugEx.WriteLine(string.Format("Stopping script {0}...", thisManager.GetScriptName()), DebugLevel.Informational);
                stopped = thisManager.StopScript(waitTime);
                thisManager.SetScriptSaved();
                DebugEx.WriteLine(string.Format("Closing form for script {0}...", thisManager.GetScriptName()), DebugLevel.Informational);
                this.Invoke(new MethodInvoker(delegate() { thisManager.CloseForm(); }));
            }
            catch (Exception Ex)
            {
                DebugEx.WriteLine(string.Format("CancelPullOperation : error while closing Form for <{0}> : {1}", thisManager.GetScriptName() + Ex.Message));
            }
            if (!stopped)
            {
                Invoke(new MethodInvoker(delegate
                {
                    if (pbPullProgress.Value < pbPullProgress.Maximum)
                    {
                        pbPullProgress.Value += 1;
                    }
                }));
            }
        }
Example #2
0
        private void _ScriptManager_OnScriptFinished(object sender, Common.ScriptEventArgs e)
        {
            DebugEx.WriteLine("ConfigurationManager : OnScriptFinished - " + e.Reason.ToString(), DebugLevel.Informational);
            SNGScriptManager thisManager = null;

            if (sender is ScriptExecutor)
            {
                thisManager = ScriptingFormManager.GetScriptManager(sender as ScriptExecutor);
            }
            else if (sender is ScriptingForm)
            {
                thisManager = (sender as ScriptingForm).ScriptManager;
            }
            if (ScriptManagers.Contains(thisManager))
            {
                lock (_lckObject) // locking is required to synchronize potential parallel calls
                {
                    ScriptManagers.Remove(thisManager);
                    if (e.Reason != ScriptEventReason.UserAborted)
                    {
                        Invoke(new MethodInvoker(delegate()
                        {
                            if (pbPullProgress.Value < pbPullProgress.Maximum)
                            {
                                pbPullProgress.Value += 1;
                            }
                            DialogResult saveConfig = DialogResult.Yes;
                            if (cbAutoSave.Checked || (saveConfig = MessageBox.Show(String.Format("Script <{0}> finished. Do you want to auto-save script results to database ?", thisManager.GetScriptName()), "Auto-save", MessageBoxButtons.YesNo, MessageBoxIcon.Question)) == System.Windows.Forms.DialogResult.Yes)
                            {
                                SaveScriptResults(thisManager);
                            }
                            if (saveConfig == DialogResult.Yes)
                            {
                                thisManager.CloseForm();
                            }
                            if (ScriptManagers.Count == 0)
                            {
                                EnableControls();
                                btnPullConfig.Enabled       = true;
                                lblOperationInProgress.Text = "Operation completed";
                                RefreshScriptManagers();
                            }
                            btnCancelPull.Visible = !btnPullConfig.Enabled;
                        }));
                    }
                    else
                    {
                        Invoke(new MethodInvoker(delegate() { if (!IsDisposed && pbPullProgress.Value < pbPullProgress.Maximum)
                                                              {
                                                                  pbPullProgress.Value += 1;
                                                              }
                                                 }));
                    }
                }
            }
        }