public static void Connect(string collectionName)
        {
            if (Collection != null)
            {
                throw new TraceStateException("Connection already established.");
            }

            ArangoDatabase.ChangeSetting(s =>
            {
                s.Database = "test";
                s.Url      = "http://localhost:8529";

                // you can set other settings if you need
                s.Credential = new NetworkCredential("root", "");
                s.SystemDatabaseCredential = new NetworkCredential("root", "");
            });

            client = ArangoDatabase.CreateWithSetting();

            //client.CreateDatabase(Dns.GetHostName());


            //just to update the description state
            var databases = client.ListDatabases();

            if (client.Connection == null)
            {
                throw new TraceStateException("Local db is unreachable.");
            }

            //client.CreateCollection("logggs");

            Collection = client.Collection(collectionName);

            Buffers = new LogBuffer[NumberOfBuffers];
            for (int i = 0; i < NumberOfBuffers; i++)
            {
                Buffers[i] = new LogBuffer();
            }

            Arbiter = new Arbiter2(Buffers);
            //I create a new delegate in order to call a method with a Conditional Attribute
            Arbiter.OnAllBuffersFilled += delegate { Flush(); };

            timer           = new Timer(2000);
            timer.AutoReset = true;
            timer.Elapsed  += delegate { Timer_Elapsed(null, null); };
            timer.Start();
        }
Ejemplo n.º 2
0
        public static async Task <bool> IsGroupMember(this IArangoDatabase database, string userId, string groupId)
        {
            if (groupId == null || userId == null)
            {
                return(false);
            }
            var group = await database.Collection("Group").DocumentAsync <Group>(groupId);

            if (group == null)
            {
                return(false);
            }

            var isMember = await database.CreateStatement <bool>(
                $@"return (FOR v in 1 INBOUND 'Group/{groupId}' Graph 'GroupUsersGraph' 
FILTER v._key == '{userId}'
return v) != []").ToListAsync();

            return(isMember.FirstOr(false) || await database.IsAdmin(userId, groupId));
        }