Ejemplo n.º 1
0
        public async Task <bool> ExecuteCode(string code, CancellationToken token = default, IScriptWriter sender = null)
        {
            string result = null; object returnedValue = null; bool isError = false; bool isCancelled = false;

            ScriptExecuted?.Invoke(this, new ScriptRequest {
                Script = code, Writer = sender
            });

            try
            {
                if (!await InitScript(token))
                {
                    return(false);
                }

                using (await _scriptStateLock.LockAsync(token))
                {
                    if (_executionContext != null)
                    {
                        await _executionContext(async() => _scriptState = await _scriptState.ContinueWithAsync(code, cancellationToken: token));
                    }
                    else
                    {
                        _scriptState = await _scriptState.ContinueWithAsync(code, cancellationToken : token);
                    }

                    returnedValue = _scriptState.ReturnValue;
                    result        = _scriptState.ReturnValue?.ToString();
                    if (_scriptState.ReturnValue != null && _scriptState.ReturnValue.GetType() == typeof(string))
                    {
                        result = $"\"{result}\"";
                    }
                }
            }
            catch (CompilationErrorException e)
            {
                result  = e.Message;
                isError = true;
            }
            catch (OperationCanceledException)
            {
                result      = string.Empty;
                isCancelled = true;
            }

            if (result != null)
            {
                var scriptResult = new ScriptResult {
                    Result = result, ReturnedValue = returnedValue, IsError = isError, IsCancelled = isCancelled
                };
                Results.Add(scriptResult);
                ScriptResultReceived?.Invoke(this, scriptResult);
            }

            return(!isError && !isCancelled);
        }
Ejemplo n.º 2
0
        private async Task ExecuteInner(EventArgs e, string statusBarMessage, bool commit, string successMessage = null)
        {
            try
            {
                OperationStarted?.Invoke(statusBarMessage, e);

                using (var cn = GetConnection.Invoke(tbDest.Text))
                {
                    await SqlDialect.ExecuteAsync(cn, tbScriptOutput.Text, commit);

                    if (commit)
                    {
                        ScriptExecuted?.Invoke(this, new EventArgs());
                        if (_manualEdits)
                        {
                            MessageBox.Show("Changes applied successfully.", "Script Executed", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        }
                    }

                    if (!string.IsNullOrEmpty(successMessage))
                    {
                        MessageBox.Show(successMessage, "SQL Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }

                    if (!_manualEdits && commit)
                    {
                        await GenerateScriptAsync();
                    }
                }
            }
            catch (Exception exc)
            {
                if (MessageBox.Show(exc.Message + "\r\n\r\nClick OK to create test case.", "Script Error", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    frmSaveTestCase.PromptSaveZipFile(false, exc.Message, _sourceModel, _destModel, _diff);
                }
            }
            finally
            {
                OperationComplete?.Invoke(this, new EventArgs());
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Invokes the <see cref="ScriptExecuted"/> event; called whenever a script is executed.
 /// </summary>
 /// <param name="e"></param>
 protected virtual void OnScriptExecuted(ScriptExecutedEventArgs e)
 {
     ScriptExecuted?.Invoke(this, e);
 }