Ejemplo n.º 1
0
        private async ValueTask deleteFromParentFolder(NodeID nid, IDatabaseSession db)
        {
            var parentPath = ParentPath(new Uri(nid.Iri));

            // avoid recursive loops
            if (parentPath.Equals(nid))
            {
                return;
            }
            var parent = await db.Read(parentPath);

            await RemoveFromParentsChildrenCollection(parent, nid, db);
        }
Ejemplo n.º 2
0
        public override async IAsyncEnumerable <object> Query(IDatabaseSession db)
        {
            var traversed = 0;
            var parResult = System.Threading.Tasks.Parallel.For(0, 10, async(i) =>
            {
                var item = db.Read(Utils.Id("ekati:/etc/assembly"));

                if (item.IsCompletedSuccessfully)
                {
                    var res = item.Result;
                    var it  = res.Attributes.Items.FirstOrDefault(i => i.Key.TryGet <NodeID>(out var nid) && nid.Iri == "ekati:attr/children");
                    if (it != null)
                    {
                        if (it.Value.TryGet <Map>(out var kids) && kids != null)
                        {
                            foreach (var k in kids.Items)
                            {
                                if (k.Key.TryGet <NodeID>(out var doc))
                                {
                                    var sub = await db.Read(doc);
                                    traversed++;
                                }
                            }
                        }
                    }
                    traversed++;
                }
                else
                {
                    await item;
                    traversed++;
                }
            });

            yield return(new { traversed, parResult });
        }
Ejemplo n.º 3
0
        private async ValueTask AddToParentsChildrenCollection(NodeID parentPath, NodeID requested, FileTypes.Ft fileType, IDatabaseSession db)
        {
            var parentDir = await db.Read(parentPath);

            var alreadyPresent = parentDir?.Attributes.Items
                                 .FirstOrDefault(kv => kv.Key.Equals(Attr.Children))
                                 ?.Value.Map?.Items?.Any(x => x.Key.Equals(requested)) ?? false;

            if (!alreadyPresent)
            {
                var dataToAdd = new Node
                {
                    Id         = parentPath,
                    Attributes = new Map
                    {
                        Items = new List <KeyValue>()
                        {
                            Utils.Prop(DateTime.UtcNow.Ticks,
                                       Attr.Children,
                                       new Map
                            {
                                Items = new List <KeyValue>()
                                {
                                    Utils.Prop(DateTime.UtcNow.Ticks, requested,
                                               FileTypes.FromFt(fileType))
                                }
                            })
                        }
                    }
                };
                if (parentDir == null)
                {
                    dataToAdd.Attributes.Items.Add(
                        Utils.Prop(DateTime.UtcNow.Ticks,
                                   Attr.Type, FileTypes.TypeFolder
                                   )
                        );
                }

                // Merge these new fields into the existing node.
                await db.Merge(dataToAdd);
            }
        }
Ejemplo n.º 4
0
        public override async IAsyncEnumerable <object> Query(IDatabaseSession db)
        {
            var item = await db.Read(Utils.Id("ekati:/etc/assembly"));

            yield return(item);
        }