示例#1
0
        public static void Main(string[] Args)
        {
            QConnection q = new QBasicConnection(Args.Length >= 1 ? Args[0] : "localhost",
                                                 Args.Length >= 2 ? int.Parse(Args[1]) : 5001, null, null);

            try
            {
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);
                Console.WriteLine("WARNING: this application overwrites: .u.upd function on q process");
                Console.WriteLine("Press <ENTER> to close application");
                q.Sync(".u.upd:{[x;y] show (x;y)};");

                var pt           = new PublisherTask(q);
                var workerThread = new Thread(pt.Run);
                workerThread.Start();

                Console.ReadLine();
                pt.Stop();
                workerThread.Join();
            }
            catch (Exception e)
            {
                Console.WriteLine("`" + e.Message);
            }
            finally
            {
                q.Close();
            }
        }
示例#2
0
        public static void Main(String[] Args)
        {
            QConnection q = new QBasicConnection(Args.Length >= 1 ? Args[0] : "localhost",
                                                 Args.Length >= 2 ? int.Parse(Args[1]) : 5001, null, null);
            try
            {
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);
                Console.WriteLine("WARNING: this application overwrites: .u.upd function on q process");
                Console.WriteLine("Press <ENTER> to close application");
                q.Sync(".u.upd:{[x;y] show (x;y)};");

                PublisherTask pt = new PublisherTask(q);
                Thread workerThread = new Thread(pt.Run);
                workerThread.Start();

                Console.ReadLine();
                pt.Stop();
                workerThread.Join();
            }
            catch (Exception e)
            {
                Console.WriteLine("`" + e.Message);
            }
            finally
            {
                q.Close();
            }
        }
示例#3
0
        private void ReadSpringfieldAccessControlDb()
        {
            using (var connection = new QBasicConnection(port: 5010))
            {
                connection.Open();

                var userPrincipals = connection.QueryObjects <Acl.UserPrincipal>("select from .acl.userPrincipal")
                                     .ToLookup(u => u.User);

                // Pull out the users and initialise the objects with all relevant principal Ids
                var users = connection.QueryObjects <Auth.User>("select from .auth.user")
                            .Select(u =>
                {
                    u.PrincipalIds = userPrincipals[u.Id].Select(p => p.Principal).ToArray();
                    return(u);
                })
                            .ToDictionary(u => u.Id);

                // pull out the grant acl and restructure the data for rapid in-proc queries
                var grantResourceAcl = connection.QueryObjects <Acl.GrantResourceAcl>("select from .acl.grantResourceAcl")
                                       .GroupBy(row => row.Resource)
                                       .ToDictionary(group => group.Key,
                                                     group => group.ToLookup(entry => entry.Operation,
                                                                             entry => entry.Principal));

                var denyResourceAcl = connection.QueryObjects <Acl.DenyResourceAcl>("select from .acl.denyResourceAcl")
                                      .GroupBy(row => row.Resource)
                                      .ToDictionary(group => group.Key,
                                                    group => group.ToLookup(entry => entry.Operation,
                                                                            entry => entry.Principal));

                // Now we can test our ACL

                Auth.User dbUser = users[Users.Bart.Id];

                var denyOutcome  = denyResourceAcl.OnResource(Resources.SimpsonHome).PermissionTo(Operations.Enter).ExistsFor(dbUser);
                var grantOutcome = grantResourceAcl.OnResource(Resources.SimpsonHome).PermissionTo(Operations.Enter).ExistsFor(dbUser);

                Console.WriteLine($"{dbUser.Name} is {IsPermitted(denyOutcome, grantOutcome)} to Enter the Simpson Home");

                // We gave Smithers specific access to enter the Simpsons Home
                dbUser = users[Users.Smithers.Id];

                denyOutcome  = denyResourceAcl.OnResource(Resources.SimpsonHome).PermissionTo(Operations.Leave).ExistsFor(dbUser);
                grantOutcome = grantResourceAcl.OnResource(Resources.SimpsonHome).PermissionTo(Operations.Leave).ExistsFor(dbUser);

                Console.WriteLine($"{dbUser.Name} is {IsPermitted(denyOutcome, grantOutcome)} specifically to Enter the Simpson Home");

                dbUser = users[Users.MrBurns.Id];

                denyOutcome  = denyResourceAcl.OnResource(Resources.HeadOffice).PermissionTo(Operations.Leave).ExistsFor(dbUser);
                grantOutcome = grantResourceAcl.OnResource(Resources.HeadOffice).PermissionTo(Operations.Leave).ExistsFor(dbUser);

                Console.WriteLine($"{dbUser.Name} is {IsPermitted(denyOutcome, grantOutcome)} to Leave the office");

                Console.ReadKey();
            }
        }
示例#4
0
        // ReSharper disable InconsistentNaming
        public object qOpen(string alias, string hostname, object port, string username = null, string password = null)
        // ReSharper restore InconsistentNaming
        {
            try
            {
                if (String.IsNullOrEmpty(alias))
                {
                    return("Invalid alias");
                }
                var c = GetConnection(alias);
                if (c != null)
                {
                    return(alias);
                }

                if (String.IsNullOrEmpty(hostname))
                {
                    return("Invalid hostname");
                }

                int prt;
                try
                {
                    prt = Int32.Parse(port.ToString());
                }
                catch
                {
                    return("Invalid port");
                }

                try
                {
                    c = new QBasicConnection(hostname, prt, username, password);
                    c.Open();
                    Connections[alias] = c;
                }
                catch (QException e)
                {
                    return("ERR: " + e.Message);
                }
            }
            catch (Exception e)
            {
                return("ERR: " + e.Message);
            }
            return(alias);
        }
        public void BuildDb()
        {
            using (var connection = new QBasicConnection(port: 5010))
            {
                connection.Open();

                DefineSchema(connection);

                AddUsers(connection);
                AddPrincipals(connection);
                AddOperations(connection);
                AddResources(connection);
                AddUserPrincipals(connection);
                AddGrantAcl(connection);
                AddDenyAcl(connection);
            }
        }
示例#6
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllersWithViews();

            // open a connection to kdb process
            var q = new QBasicConnection(
                _kdbConnectorOptions.Host,
                _kdbConnectorOptions.Port,
                _kdbConnectorOptions.UserName,
                _kdbConnectorOptions.Password,
                _kdbConnectorOptions.Encoding
                );

            q.Open();

            // pass it to controllers via dependency injection
            services.AddSingleton <QBasicConnection>(q);
        }
        public static void GetKDBResults(string host, int port, Func <string, Task> func)
        {
            QConnection q = new QBasicConnection(host: host,
                                                 port: port);

            try
            {
                //var result = "";
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);

                while (true)
                {
                    Console.Write("Q)");
                    var line = Console.ReadLine();

                    if (line.Equals("\\\\"))
                    {
                        break;
                    }
                    else
                    {
                        try
                        {
                            PrintResult(q.Sync(line), func);
                        }
                        catch (QException e)
                        {
                            Console.WriteLine("`" + e.Message);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                Console.ReadLine();
            }
            finally
            {
                q.Close();
            }
        }
示例#8
0
        private static void Main(string[] args)
        {
            IList <string> x = args;

            QConnection q = new QBasicConnection((args.Length >= 1) ? args[0] : "localhost",
                                                 (args.Length >= 2) ? int.Parse(args[1]) : 5000);

            try
            {
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);

                while (true)
                {
                    Console.Write("Q)");
                    var line = Console.ReadLine();

                    if (line.Equals("\\\\"))
                    {
                        break;
                    }
                    try
                    {
                        PrintResult(q.Sync(line));
                    }
                    catch (QException e)
                    {
                        Console.WriteLine("`" + e.Message);
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                Console.ReadLine();
            }
            finally
            {
                q.Close();
            }
        }
示例#9
0
        static void Main(string[] args)
        {
            QConnection q = new QBasicConnection(host: (args.Length >= 1) ? args[0] : "localhost",
                                                 port: (args.Length >= 2) ? Int32.Parse(args[1]) : 5000);
            try
            {
                q.Open();
                Console.WriteLine("conn: " + q + "  protocol: " + q.ProtocolVersion);

                while (true)
                {
                    Console.Write("Q)");
                    var line = Console.ReadLine();

                    if (line.Equals("\\\\"))
                    {
                        break;
                    }
                    else
                    {
                        try
                        {
                            PrintResult(q.Sync(line));
                        }
                        catch (QException e)
                        {
                            Console.WriteLine("`" + e.Message);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                Console.ReadLine();
            }
            finally
            {
                q.Close();
            }
        }