Ejemplo n.º 1
0
        public RbacRoleWeb Get(int id)
        {
            RbacRole role = Rbac.GetRole(id);

            if (role != null)
            {
                role.ParseMetaData();
                return(new RbacRoleWeb(role));
            }
            return(null);
        }
Ejemplo n.º 2
0
        public RbacRoleWeb Get(string name)
        {
            RbacRole role = Rbac.GetRole(name);

            if (role != null)
            {
                role.ParseMetaData();
                return(new RbacRoleWeb(role));
            }
            return(null);
        }
Ejemplo n.º 3
0
        private void cbRoles_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (cbRoles.SelectedItem != null)
            {
                RbacRole    dbRole = Rbac.GetRole(((RbacRole)cbRoles.SelectedItem).Name);
                RbacRoleWeb role   = new RbacRoleWeb(dbRole);

                tabPage4.Text        = role.Name;
                txtRole.Text         = role.MetaDataRbac;
                txtEntitlements.Text = role.MetaDataEntitlements;

                role.MetaDataRbac         = string.Empty;
                role.MetaDataEntitlements = string.Empty;
                propRole.SelectedObject   = role;
            }
            else
            {
                tabPage4.Tag  = null;
                tabPage4.Text = "Role";
            }
            ParseInline();
        }
Ejemplo n.º 4
0
        public void TestBatch()
        {
            GenericParserAdapter genParser = new GenericParserAdapter(Path.Combine(_rootDir, "Books", "tests.csv"));

            genParser.FirstRowHasHeader = true;
            DataTable table = genParser.GetDataTable();

            if (table.Columns["ParsedQueryStage1"] == null)
            {
                table.Columns.Add("ParsedQueryStage1");
                table.Columns.Add("ParsedQuery");
                table.Columns.Add("Records");
                table.Columns.Add("Errors");
                table.Columns.Add("TestResult");
            }
            bool cleaned = false;

            foreach (DataRow row in table.Rows)
            {
                //if (row["Id"].ToString() == "11")
                //    Debugger.Break();

                Rbac     rbac = new Rbac(row["User"].ToString());
                RbacRole role = Rbac.GetRole(row["Role"].ToString());

                if (!cleaned)
                {
                    CleanDataFromDb(rbac.ConnectionString);
                    cleaned = true;
                }
                SqlQueryParser parser = new SqlQueryParser(rbac);
                try
                {
                    parser.Parse(row["Query"].ToString());
                }
                catch (Exception ex)
                {
                    row["Errors"] = ex.Message;
                    if (row["Expected"].ToString().Equals(row["Errors"].ToString()))
                    {
                        row["TestResult"] = "Passed";
                    }
                    else
                    {
                        row["TestResult"] = "Failed";
                    }
                    continue;
                }
                row["ParsedQueryStage1"] = parser.ParsedQueryStage1;
                row["ParsedQuery"]       = parser.ParsedQuery;
                row["Errors"]           += parser.AllErrors;

                if (string.IsNullOrEmpty(parser.AllErrors))
                {
                    RbacSqlQueryEngine engine = new RbacSqlQueryEngine(parser, true);
                    engine.Execute();
                    if (engine.IsErrored)
                    {
                        row["Records"] = "Errored";
                    }
                    else if ((parser.QueryType == RbacQueryTypes.Select) && (engine.Table == null))
                    {
                        row["Records"] = "Errored";
                    }
                    else if ((parser.QueryType == RbacQueryTypes.Select) && (engine.Table != null))
                    {
                        row["Records"] = engine.Table.Rows.Count + " record(s)";
                    }

                    if (!string.IsNullOrEmpty(parser.AllErrors))
                    {
                        row["Errors"] += parser.AllErrors + Environment.NewLine;
                    }

                    if (!string.IsNullOrEmpty(engine.AllErrors))
                    {
                        row["Errors"] += engine.AllErrors + Environment.NewLine;
                    }
                }

                if (row["Expected"].ToString().Equals(row["Errors"].ToString()))
                {
                    row["TestResult"] = "Passed";
                }
                else
                {
                    row["TestResult"] = "Failed";
                }

                CleanDataFromDb(rbac.ConnectionString);
            }

            string outFile = Path.Combine(_rootDir, "Books", "tests_result.csv");

            table.ToCsv(outFile);

            WriteColor(ConsoleColor.Green, outFile + " is generated!");
            Console.WriteLine();
            ToCsvMarkdownFormat(table, Path.Combine(_rootDir, "Books", "tests_result.md"));
        }