예제 #1
0
        public RbacEngineWebResponse Post([FromBody] RbacEngineWebRequest request)
        {
            RbacEngineWebResponse response = new RbacEngineWebResponse();

            try
            {
                response.UserName = request.UserName;
                response.RoleName = request.RoleName;
                using (Rbac ctx = new Rbac(request.UserName, request.RbacName, request.RoleName))
                {
                    response.RbacName = request.RbacName;
                    SqlQueryParser parser = new SqlQueryParser(ctx, request.SkipParsing);
                    parser.Parse(request.Query);

                    using (RbacSqlQueryEngine eng = new RbacSqlQueryEngine(parser, request.DebugMode))
                    {
                        eng.SkipExecution = request.SkipExecution;
                        eng.Execute();
                        response.SetResult(eng);
                    }
                }
            }
            catch (Exception ex)
            {
                response.SetResult(ex.Message);
            }

            return(response);
        }
예제 #2
0
        private void btnExecute_Click(object sender, EventArgs e)
        {
            SetStatusText("Parsing...");

            txtErrors.Text        = string.Empty;
            txtParsedQuerys1.Text = string.Empty;
            txtParsedQuery.Text   = string.Empty;
            txtErrors.Visible     = false;
            RbacEngineWebResponse response = new RbacEngineWebResponse();

            this.Cursor = Cursors.WaitCursor;
            try
            {
                _Request.RbacName          = ((Rbac)cbInstances.SelectedItem).Name;
                _Request.UserName          = ((RbacUser)cbUsers.SelectedItem).UserName;
                _Request.RoleName          = ((RbacRole)cbRoles.SelectedItem).Name;
                _Request.Query             = txtQuery.Text;
                engineInput.SelectedObject = _Request;

                using (Rbac ctx = new Rbac(_Request.UserName, _Request.RbacName, _Request.RoleName))
                {
                    SqlQueryParser parser = new SqlQueryParser(ctx, _Request.SkipParsing);
                    parser.Parse(_Request.Query);
                    response.SetResult(parser);
                    BindResult(response);
                    SetStatusText("Parsing...Done.", response);


                    if (parser.QueryType == RbacQueryTypes.Select)
                    {
                        SetStatusText("Parsing...Done. Executing...", response);

                        using (RbacSqlQueryEngine eng = new RbacSqlQueryEngine(parser, _Request.DebugMode))
                        {
                            eng.SkipExecution = _Request.SkipExecution;
                            eng.Execute();
                            response.SetResult(eng);
                            SetStatusText("Parsing...Done. Executing...Done.", response);
                        }
                    }
                }
            }
            catch (RbacException ex)
            {
                txtErrors.Text    = ex.Message;
                txtErrors.Visible = true;
                SetStatusText("Done.");
            }

            BindResult(response);
            tabControl1.SelectedIndex = 0;
            this.Cursor = Cursors.Default;
        }
예제 #3
0
        private void btnExecuteAll_Click(object sender, EventArgs e)
        {
            Cursor = Cursors.WaitCursor;
            toolStripProgressBar1.Visible = true;
            if (lvwQueries.Tag != null)
            {
                DataTable table = lvwQueries.Tag as DataTable;
                toolStripProgressBar1.Maximum = table.Rows.Count;
                if (table.Columns["ParsedQueryStage1"] == null)
                {
                    table.Columns.Add("ParsedQueryStage1");
                    table.Columns.Add("ParsedQuery");
                    table.Columns.Add("Errors");
                }
                foreach (DataRow row in table.Rows)
                {
                    try
                    {
                        Rbac rbac = new Rbac(row["User"].ToString(), "Books", row["Role"].ToString());

                        RbacEngineWebResponse response = new RbacEngineWebResponse();
                        this.Cursor       = Cursors.WaitCursor;
                        _Request.RbacName = rbac.Name;
                        _Request.UserName = rbac.User.UserName;
                        _Request.RoleName = rbac.User.Role.Name;
                        _Request.Query    = row["Query"].ToString();

                        SqlQueryParser parser = new SqlQueryParser(rbac);
                        parser.Parse(_Request.Query);
                        response.SetResult(parser);
                        SetStatusText("Parsing...Done.", response);

                        if (parser.QueryType == RbacQueryTypes.Select)
                        {
                            SetStatusText("Parsing...Done. Executing...", response);
                            RbacSqlQueryEngine engine = new RbacSqlQueryEngine(parser, true);
                            engine.Execute();
                            response.SetResult(engine);
                            SetStatusText("Parsing...Done. Executing...Done.", response);
                        }
                        row["ParsedQueryStage1"] = parser.ParsedQueryStage1;
                        row["ParsedQuery"]       = parser.ParsedQuery;
                        row["Errors"]            = parser.AllErrors + Environment.NewLine;
                        SetStatusText("Done.", response);
                    }
                    catch (Exception ex)
                    {
                        row["Errors"] = ex.Message;
                    }

                    toolStripProgressBar1.PerformStep();
                    Application.DoEvents();
                }
                toolStripProgressBar1.Visible = false;
                string fileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, table.TableName + "_out.csv");
                try
                {
                    table.ToCsv(fileName);
                    MessageBox.Show("Test results are saved on " + fileName + "!", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    Cursor = Cursors.Default;
                    MessageBox.Show(ex.Message,
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                tabControl1.SelectedIndex = 0;
                Cursor = Cursors.Default;
            }
        }