예제 #1
0
        private void BreadthFirstReadInfo(Queue <DirectoryInfo> q,
                                          GraphBuilder g, INodeFactory f, int maxDepth = -1)
        {
            var contains       = f.Uri("app:contains");
            var itemType       = f.Uri("app:type");
            var itemTypeFolder = f.New("folder");
            var itemTypeFile   = f.New("file");

            var lastModify = f.Uri(PosixStat.LastModified);
            var size       = f.Uri(PosixStat.Size);

            var depth = 0;

            while (q.Count > 0)
            {
                var root = q.Dequeue();

                var subject = f.Uri(root.AsUri());
                try
                {
                    foreach (var file in root.EnumerateFiles())
                    {
                        g.For(subject)
                        .With(contains).To(f.Uri(file.AsUri()))
                        .With(itemType).Add(itemTypeFile)
                        .Then()
                        .With(lastModify).Add(f.New(file.LastWriteTime))
                        .Then()
                        .With(size).Add(f.New(file.Length));
                    }

                    foreach (var dir in root.EnumerateDirectories())
                    {
                        g.For(subject).With(contains).To(f.Uri(dir.AsUri()))
                        .With(itemType).Add(itemTypeFolder);
                    }

                    if (maxDepth > 0 && depth < maxDepth)
                    {
                        foreach (var subDir in root.GetDirectories())
                        {
                            q.Enqueue(subDir);
                        }
                        depth++;
                    }
                }
                catch (UnauthorizedAccessException ex)
                {
                    g.For(subject)
                    .With("app:AccessGranted", out _).Add(false)
                    .Then().With("app:error", out _)
                    .Add(ex.Message)
                    .Add(ex);
                }
            }
        }
예제 #2
0
 /// <inheritdoc />
 public Node <T> New <T>(T value) where T : notnull =>
 _factory.New(value);