예제 #1
0
        internal ExpandedPath.Action LocateNodeByExpandedPath(ExpandedPath ep, NodeProvider node, out NodeProvider?handlingNode)
        {
            var action = node.HandlePath(ep);

            switch (action)
            {
            case Unknown:
                throw new NotImplementedException($"handler for {node.GetType().ToString()} returned Unknown");

            case NotFound:
                // TODO
                handlingNode = null;
                return(ExpandedPath.Action.NotFound);

            case PassThrough:
                // TODO
                foreach (var child in node.Children)
                {
                    var res = LocateNodeByExpandedPath(ep.NextLevel(), child, out handlingNode);
                    if (res == ExpandedPath.Action.Handle)
                    {
                        return(ExpandedPath.Action.Handle);
                    }
                }
                handlingNode = null;
                return(ExpandedPath.Action.NotFound);

            case Handle:
                handlingNode = node;
                return(ExpandedPath.Action.Handle);
            }

            handlingNode = null;
            return(ExpandedPath.Action.Unknown);
        }
예제 #2
0
        public override sealed Errno OnOpenHandle(ExpandedPath file, PathInfo info)
        {
            var descriptor = 0x2a000000 + new Random().Next(0x1000000);

            info.Handle = new IntPtr(descriptor);
            return(0);
        }
예제 #3
0
        public override ExpandedPath.Action HandlePath(ExpandedPath ep)
        {
            LoadChromosomeList(ep);

            if (ep.Level > ep.Components.Count)
            {
                return(ExpandedPath.Action.Unknown);
            }
            else if (ep.Level == ep.Components.Count)
            {
                return(ExpandedPath.Action.Handle);
            }
            else
            {
                return(ExpandedPath.Action.PassThrough);
            }
        }
예제 #4
0
        public Errno OnOpenHandle(
            string file,
            PathInfo info)
        {
            var          ep = new ExpandedPath(file);
            NodeProvider?node;
            var          action = LocateNodeByExpandedPath(ep, Root, out node);

            if (action == ExpandedPath.Action.Handle && node != null)
            {
                return(node.OnOpenHandle(ep, info));
            }
            else
            {
                return(Errno.ENOENT);
            }
        }
예제 #5
0
        public void LoadChromosomeList(ExpandedPath ep)
        {
            if (chromosomes.ContainsKey(ep.Components[0]))
            {
                return;
            }

            var speciesDbName  = ep.Components[0];
            var chromosomeList = Slice.GetSpeciesChromosomeList(speciesDbName);

            var chromosomeForSpecies = chromosomeList
                                       .Select(name =>
            {
                return(new NamedStat(name, Extensions.StandardDir()));
            }).ToList();

            chromosomes[speciesDbName] = chromosomeForSpecies;
        }
예제 #6
0
        public override Errno OnGetPathStatus(ExpandedPath path, out NamedStat entry)
        {
            LoadChromosomeList(path);

            var species    = path.Components[0];
            var chromosome = path.Components.Last();

            if (chromosomes.ContainsKey(species))
            {
                entry = chromosomes[species].Where(ns => ns.Name == chromosome).First();
                return(0);
            }
            else
            {
                entry = new NamedStat();
                return(Errno.ENOENT);
            }
        }
예제 #7
0
        public Errno OnGetPathStatus(
            string path,
            out Stat entry)
        {
            var          ep = new ExpandedPath(path);
            NodeProvider?node;
            var          action = LocateNodeByExpandedPath(ep, Root, out node);

            if (action == ExpandedPath.Action.Handle && node != null)
            {
                NamedStat nstat;
                var       res = node.OnGetPathStatus(ep, out nstat);
                entry = nstat.Stat;
                return(res);
            }
            else
            {
                entry = new Stat();
                return(Errno.ENOENT);
            }
        }
예제 #8
0
        public Errno OnReadHandle(
            string file,
            PathInfo info,
            byte[] buf,
            long offset,
            out int bytesRead)
        {
            var          ep = new ExpandedPath(file);
            NodeProvider?node;
            var          action = LocateNodeByExpandedPath(ep, Root, out node);

            if (action == ExpandedPath.Action.Handle && node != null)
            {
                return(node.OnReadHandle(ep, info, buf, offset, out bytesRead));
            }
            else
            {
                bytesRead = 0;
                return(Errno.ENOENT);
            }
        }
예제 #9
0
        public override Errno OnReadDirectory(ExpandedPath directory, PathInfo info, out IEnumerable <NamedStat> paths)
        {
            LoadChromosomeList(directory);

            if (directory.Components.Count < Level)
            {
                if (chromosomes.ContainsKey(directory.Components[0]))
                {
                    paths = chromosomes[directory.Components[0]];
                    return(0);
                }
                else
                {
                    paths = new List <NamedStat>();
                    return(Errno.ENOENT);
                }
            }
            else
            {
                return(Children[0].OnReadDirectory(directory, info, out paths));
            }
        }
예제 #10
0
        public Errno OnReadDirectory(
            string directory,
            PathInfo info,
            out IEnumerable <DirectoryEntry> paths)
        {
            var          ep = new ExpandedPath(directory);
            NodeProvider?node;
            var          action = LocateNodeByExpandedPath(ep, Root, out node);

            if (action == ExpandedPath.Action.Handle && node != null)
            {
                IEnumerable <NamedStat> nstats;
                var res = node.OnReadDirectory(ep, info, out nstats);
                paths = nstats.Select(ns => new DirectoryEntry(ns.Name));
                return(res);
            }
            else
            {
                paths = new List <DirectoryEntry>();
                return(Errno.ENOENT);
            }
        }
예제 #11
0
 public abstract Errno OnGetPathStatus(
     ExpandedPath path,
     out NamedStat entry);
예제 #12
0
 public override sealed Errno OnReadDirectory(ExpandedPath directory, PathInfo info, out IEnumerable <NamedStat> paths)
 {
     throw new System.NotImplementedException("FileProvider.OnReadDirectory marked as sealed, not implemented");
 }
예제 #13
0
 public abstract Errno OnReadHandle(
     ExpandedPath file,
     PathInfo info,
     byte[] buf,
     long offset,
     out int bytesRead);
예제 #14
0
 public ExpandedPath(ExpandedPath ep, int newLevel)
 {
     FullPath   = ep.FullPath;
     Level      = newLevel;
     Components = ep.Components;
 }
예제 #15
0
 public abstract Errno OnReadDirectory(
     ExpandedPath directory,
     PathInfo info,
     out IEnumerable <NamedStat> paths);
예제 #16
0
 public abstract Errno OnOpenHandle(
     ExpandedPath file,
     PathInfo info);
예제 #17
0
 public override sealed Errno OnOpenHandle(ExpandedPath file, PathInfo info)
 {
     throw new System.NotImplementedException($"DirectoryProvider.OnOpenHandle({file.FullPath}) marked as sealed, not implemented");
 }
예제 #18
0
 public abstract ExpandedPath.Action HandlePath(ExpandedPath ep);
예제 #19
0
 public override sealed Errno OnReadHandle(ExpandedPath file, PathInfo info, byte[] buf, long offset, out int bytesRead)
 {
     throw new System.NotImplementedException("DirectoryProvider.OnReadHandle marked as sealed, not implemented");
 }