Exemplo n.º 1
0
    // Recursively print the contents of directory "dir" in tree fashion.
    // For files, show the contents of each file. The "depth"
    // parameter is the current nesting level (for indentation).

    static void listRecursive(DirectoryPrx dir, int depth)
    {
        var indent = new string('\t', ++depth);

        NodePrx[] contents = dir.list();

        foreach (var node in contents)
        {
            var subdir = DirectoryPrxHelper.checkedCast(node);
            var file   = FilePrxHelper.uncheckedCast(node);
            Console.WriteLine(indent + node.name() + (subdir != null ? " (directory):" : " (file):"));
            if (subdir != null)
            {
                listRecursive(subdir, depth);
            }
            else
            {
                var text = file.read();
                for (int j = 0; j < text.Length; ++j)
                {
                    Console.WriteLine(indent + "\t" + text[j]);
                }
            }
        }
    }
Exemplo n.º 2
0
    public static int Main(string[] args)
    {
        try
        {
            using (Ice.Communicator ic = Ice.Util.initialize(ref args))
            {
                //
                // Create a proxy for the root directory
                //
                var obj = ic.stringToProxy("RootDir:default -h localhost -p 10000");

                //
                // Down-cast the proxy to a Directory proxy
                //
                var rootDir = DirectoryPrxHelper.checkedCast(obj);
                if (rootDir == null)
                {
                    throw new ApplicationException("Invalid proxy");
                }

                //
                // Recursively list the contents of the root directory
                //
                Console.WriteLine("Contents of root directory:");
                listRecursive(rootDir, 0);
            }
        }
        catch (Exception e)
        {
            Console.Error.WriteLine(e);
            return(1);
        }
        return(0);
    }
Exemplo n.º 3
0
    public static int Main(string[] args)
    {
        try
        {
            //
            // The new communicator is automatically destroyed (disposed) at the end of the
            // using statement
            //
            using (var communicator = Ice.Util.initialize(ref args))
            {
                //
                // Create a proxy for the root directory
                //
                var @base = communicator.stringToProxy("RootDir:default -h localhost -p 10000");

                //
                // Down-cast the proxy to a Directory proxy.
                //
                var rootDir = DirectoryPrxHelper.checkedCast(@base);
                if (rootDir == null)
                {
                    throw new Error("Invalid proxy");
                }

                var p = new Parser(rootDir);
                return(p.parse());
            }
        }
        catch (Exception ex)
        {
            Console.Error.WriteLine(ex);
            return(1);
        }
    }
Exemplo n.º 4
0
    internal virtual void list(Filesystem.DirectoryPrx dir, bool recursive, int depth)
    {
        StringBuilder b = new StringBuilder();

        for (int i = 0; i < depth; ++i)
        {
            b.Append('\t');
        }
        string indent = b.ToString();

        NodeDesc[] contents = dir.list();

        for (int i = 0; i < contents.Length; ++i)
        {
            DirectoryPrx d = contents[i].type == NodeType.DirType
                                ? DirectoryPrxHelper.uncheckedCast(contents[i].proxy) : null;
            Console.Write(indent + contents[i].name + (d != null ? " (directory)" : " (file)"));
            if (d != null && recursive)
            {
                Console.WriteLine(":");
                list(d, true, ++depth);
            }
            else
            {
                Console.WriteLine();
            }
        }
    }
Exemplo n.º 5
0
        public override int run(String[] args)
        {
            //
            // Terminate cleanly on receipt of a signal.
            //
            shutdownOnInterrupt();

            //
            // Create a proxy for the root directory
            //
            Ice.ObjectPrx @base = communicator().stringToProxy("RootDir:default -h localhost -p 10000");

            //
            // Down-cast the proxy to a Directory proxy.
            //
            DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(@base);

            if (rootDir == null)
            {
                throw new Error("Invalid proxy");
            }

            Parser p = new Parser(rootDir);

            return(p.parse());
        }
Exemplo n.º 6
0
    public static int Main(string[] args)
    {
        int status = 0;

        Ice.Communicator ic = null;
        try
        {
            Ice.InitializationData data = new Ice.InitializationData();

            //
            // Create a communicator
            //
            ic = Ice.Util.initialize(ref args, data);

            //
            // Create a proxy for the root directory
            //
            Ice.ObjectPrx obj = ic.stringToProxy("RootDir:default -h localhost -p 10000");

            //
            // Down-cast the proxy to a Directory proxy
            //
            DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(obj);
            if (rootDir == null)
            {
                throw new ApplicationException("Invalid proxy");
            }

            //
            // Recursively list the contents of the root directory
            //
            Console.WriteLine("Contents of root directory:");
            listRecursive(rootDir, 0);
        }
        catch (Exception e)
        {
            Console.Error.WriteLine(e);
            status = 1;
        }
        if (ic != null)
        {
            try
            {
                ic.destroy();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                status = 1;
            }
        }
        return(status);
    }
Exemplo n.º 7
0
        // Slice createDirectory() operation.

        public override DirectoryPrx createDirectory(string name, Current c)
        {
            lock (this)
            {
                if (_destroyed)
                {
                    throw new ObjectNotExistException();
                }

                if (name.Length == 0 || _contents.ContainsKey(name))
                {
                    throw new NameInUse(name);
                }

                var d    = new DirectoryI(name, this);
                var node = c.adapter.add(d, d.id());
                _contents.Add(name, d);
                return(DirectoryPrxHelper.uncheckedCast(node));
            }
        }
Exemplo n.º 8
0
    internal virtual void cd(string name)
    {
        if (name.Equals("/"))
        {
            while (_dirs.Count > 1)
            {
                _dirs.RemoveAt(0);
            }
            return;
        }

        if (name.Equals(".."))
        {
            if (_dirs.Count > 1)
            {
                _dirs.RemoveAt(0);
            }
            return;
        }

        DirectoryPrx dir = (DirectoryPrx)_dirs[0];
        NodeDesc     d;

        try
        {
            d = dir.find(name);
        }
        catch (NoSuchName)
        {
            Console.WriteLine("`" + name + "': no such directory");
            return;
        }
        if (d.type == NodeType.FileType)
        {
            Console.WriteLine("`" + name + "': not a directory");
            return;
        }
        _dirs.Insert(0, DirectoryPrxHelper.uncheckedCast(d.proxy));
    }
Exemplo n.º 9
0
    public static int Main(string[] args)
    {
        int status = 0;

        Ice.Communicator ic = null;
        try
        {
            Ice.InitializationData data = new Ice.InitializationData();
#if COMPACT
            //
            // When using Ice for .NET Compact Framework, we need to specify
            // the assembly so that Ice can locate classes and exceptions.
            //
            data.properties = Ice.Util.createProperties();
            data.properties.setProperty("Ice.FactoryAssemblies", "client,version=1.0.0.0");
#endif

            //
            // Create a communicator
            //
            ic = Ice.Util.initialize(ref args, data);

            //
            // Create a proxy for the root directory
            //
            Ice.ObjectPrx obj = ic.stringToProxy("RootDir:default -h localhost -p 10000");

            //
            // Down-cast the proxy to a Directory proxy
            //
            DirectoryPrx rootDir = DirectoryPrxHelper.checkedCast(obj);
            if (rootDir == null)
            {
                throw new ApplicationException("Invalid proxy");
            }

            //
            // Recursively list the contents of the root directory
            //
            Console.WriteLine("Contents of root directory:");
            listRecursive(rootDir, 0);
        }
        catch (Exception e)
        {
            Console.Error.WriteLine(e);
            status = 1;
        }
        if (ic != null)
        {
            try
            {
                ic.destroy();
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e);
                status = 1;
            }
        }
        return(status);
    }