/*
 * Automatically generated by jrpcgen 1.0.7 on 29.11.2012
 * jrpcgen is part of the "Remote Tea.Net" ONC/RPC package for C#
 * See http://remotetea.sourceforge.net for details
 */
/**
 * Enumeration (collection of constants).
 */
using System;

namespace NFSLibrary.Protocols.Commons.Exceptions
{
    public class ExceptionHelpers
    {
        private static System.Collections.Generic.Dictionary<NFSStats, String> ExceptionList()
        {
            System.Collections.Generic.Dictionary<NFSStats, String> rDictionary =
                new System.Collections.Generic.Dictionary<NFSStats, String>();

            rDictionary.Add(NFSStats.NFS_OK, "Indicates the call completed successfully");
            rDictionary.Add(NFSStats.NFSERR_PERM, "Not owner. The operation was not allowed because the caller is either not a privileged user (root) or not the owner of the target of the operation.");
            rDictionary.Add(NFSStats.NFSERR_NOENT, "No such file or directory. The file or directory name specified does not exist.");
            rDictionary.Add(NFSStats.NFSERR_IO, "I/O error. A hard error (for example, a disk error) occurred while processing the requested operation.");
            rDictionary.Add(NFSStats.NFSERR_NXIO, "I/O error. No such device or address");
            rDictionary.Add(NFSStats.NFSERR_ACCES, "Permission denied. The caller does not have the correct permission to perform the requested operation. Contrast this with NFS3ERR_PERM, which restricts itself to owner or privileged user permission failures.");
            rDictionary.Add(NFSStats.NFSERR_EXIST, "File exists. The file specified already exists.");
            rDictionary.Add(NFSStats.NFSERR_XDEV, "Attempt to do a cross-device hard link.");
            rDictionary.Add(NFSStats.NFSERR_NODEV, "No such device.");
            rDictionary.Add(NFSStats.NFSERR_NOTDIR, "Not a directory. The caller specified a non-directory in a directory operation.");
            rDictionary.Add(NFSStats.NFSERR_ISDIR, "Is a directory. The caller specified a directory in a non-directory operation.");
            rDictionary.Add(NFSStats.NFSERR_INVAL, "Invalid argument or unsupported argument for an operation. Two examples are attempting a READLINK on an object other than a symbolic link or attempting to SETATTR a time field on a server that does not support this operation.");
            rDictionary.Add(NFSStats.NFSERR_FBIG, "File too large. The operation would have caused a file to grow beyond the server's limit.");
            rDictionary.Add(NFSStats.NFSERR_NOSPC, "No space left on device. The operation would have caused the server's file system to exceed its limit.");
            rDictionary.Add(NFSStats.NFSERR_ROFS, "Read-only file system. A modifying operation was attempted on a read-only file system.");
            rDictionary.Add(NFSStats.NFSERR_MLINK, "Too many hard links.");
            rDictionary.Add(NFSStats.NFSERR_NAMETOOLONG, "The filename in an operation was too long.");
            rDictionary.Add(NFSStats.NFSERR_NOTEMPTY, "An attempt was made to remove a directory that was not empty.");
            rDictionary.Add(NFSStats.NFSERR_DQUOT, "Resource (quota) hard limit exceeded. The user's resource limit on the server has been exceeded.");
            rDictionary.Add(NFSStats.NFSERR_STALE, "Invalid file handle. The file handle given in the arguments was invalid. The file referred to by that file handle no longer exists or access to it has been revoked.");
            rDictionary.Add(NFSStats.NFSERR_REMOTE, "Too many levels of remote in path. The file handle given in the arguments referred to a file on a non-local file system on the server.");
            rDictionary.Add(NFSStats.NFSERR_WFLUSH, "The server's write cache used in the WRITECACHE call got flushed to disk.");
            rDictionary.Add(NFSStats.NFSERR_BADHANDLE, "Illegal NFS file handle. The file handle failed internal consistency checks.");
            rDictionary.Add(NFSStats.NFSERR_NOT_SYNC, "Update synchronization mismatch was detected during a SETATTR operation.");
            rDictionary.Add(NFSStats.NFSERR_BAD_COOKIE, "READDIR or READDIRPLUS cookie is stale.");
            rDictionary.Add(NFSStats.NFSERR_NOTSUPP, "Operation is not supported.");
            rDictionary.Add(NFSStats.NFSERR_TOOSMALL, "Buffer or request is too small.");
            rDictionary.Add(NFSStats.NFSERR_SERVERFAULT, "An error occurred on the server which does not map to any of the legal NFS version 3 protocol error values.  The client should translate this into an appropriate error. UNIX clients may choose to translate this to EIO.");
            rDictionary.Add(NFSStats.NFSERR_BADTYPE, "An attempt was made to create an object of a type not supported by the server.");
            rDictionary.Add(NFSStats.NFSERR_JUKEBOX, "The server initiated the request, but was not able to complete it in a timely fashion. The client should wait and then try the request with a new RPC transaction ID. For example, this error should be returned from a server that supports hierarchical storage and receives a request to process a file that has been migrated. In this case, the server should start the immigration process and respond to client with this error.");

            return rDictionary;
        }

        public static void ThrowException(NFSStats ErrorCode)
        {
            if (ErrorCode != NFSStats.NFS_OK)
            {
                System.Collections.Generic.Dictionary<NFSStats, String> exceptionMessages =
                    ExceptionHelpers.ExceptionList();

                if (exceptionMessages.ContainsKey(ErrorCode))
                {
                    String Message = exceptionMessages[ErrorCode];

                    switch (ErrorCode)
                    {
                        case NFSStats.NFSERR_ACCES:
                            throw new NFSAuthenticationException(Message);                      
                        
                        case NFSStats.NFSERR_DQUOT:
                        case NFSStats.NFSERR_EXIST:
                        case NFSStats.NFSERR_FBIG:
                        case NFSStats.NFSERR_IO:
                        case NFSStats.NFSERR_ISDIR:
                        case NFSStats.NFSERR_NAMETOOLONG:
                        case NFSStats.NFSERR_NOENT:
                        case NFSStats.NFSERR_NOSPC:
                        case NFSStats.NFSERR_NOTDIR:
                        case NFSStats.NFSERR_NOTEMPTY:
                        case NFSStats.NFSERR_NXIO:
                            throw new NFSIOException(Message);

                        case NFSStats.NFSERR_PERM:
                        case NFSStats.NFSERR_ROFS:
                            throw new NFSUnauthorizedAccessException(Message);

                        case NFSStats.NFSERR_BADHANDLE:
                        case NFSStats.NFSERR_BADTYPE:
                        case NFSStats.NFSERR_TOOSMALL:
                        case NFSStats.NFSERR_SERVERFAULT:
                        case NFSStats.NFSERR_JUKEBOX:
                            throw new NFSCommunicationException(Message);

                        case NFSStats.NFSERR_XDEV:
                        case NFSStats.NFSERR_REMOTE:
                        case NFSStats.NFSERR_NOTSUPP:
                        case NFSStats.NFSERR_NOT_SYNC:
                        case NFSStats.NFSERR_NODEV:
                        case NFSStats.NFSERR_MLINK:
                        case NFSStats.NFSERR_INVAL:
                        case NFSStats.NFSERR_BAD_COOKIE:
                        case NFSStats.NFSERR_STALE:
                        case NFSStats.NFSERR_WFLUSH:
                            throw new NFSGeneralException(Message);

                        default:
                            throw new NFSGeneralException("General Exception Occured!");

                    }
                }
                else
                { throw new NFSGeneralException("Unknown Exception Occured!"); }
            }
        }
    }

    public class NFSGeneralException
        : System.Exception
    {
        public NFSGeneralException(string Message)
            : base(Message)
        { }
    }

    public class NFSAuthenticationException
        : System.Security.Authentication.AuthenticationException
    {
        public NFSAuthenticationException(string Message)
            : base(Message)
        { }
    }

    public class NFSUnauthorizedAccessException
        : System.UnauthorizedAccessException
    {
        public NFSUnauthorizedAccessException(string Message)
            : base(Message)
        { }
    }

    public class NFSIOException
        : System.IO.IOException
    {
        public NFSIOException(string Message)
            : base(Message)
        { }
    }

    public class NFSConnectionException
        : System.Exception
    {
        public NFSConnectionException(string Message)
            : base(Message)
        { }
    }

    public class NFSCommunicationException
        : System.Exception
    {
        public NFSCommunicationException(string Message)
            : base(Message)
        { }
    }
}

namespace NFSLibrary.Protocols.Commons.Exceptions.Mount
{
    public class MountExceptionHelpers
    {
        private static System.Collections.Generic.Dictionary<NFSMountStats, String> ExceptionList()
        {
            System.Collections.Generic.Dictionary<NFSMountStats, String> rDictionary =
                new System.Collections.Generic.Dictionary<NFSMountStats, String>();

            rDictionary.Add(NFSMountStats.MNT_OK, "Indicates the call completed successfully");
            rDictionary.Add(NFSMountStats.MNTERR_PERM, "Not owner.");
            rDictionary.Add(NFSMountStats.MNTERR_NOENT, "No such file or directory.");
            rDictionary.Add(NFSMountStats.MNTERR_SRCH, "No such process.");
            rDictionary.Add(NFSMountStats.MNTERR_INTR, "Interrupted system call.");
            rDictionary.Add(NFSMountStats.MNTERR_IO, "I/O error");
            rDictionary.Add(NFSMountStats.MNTERR_NXIO, "No such device or address");
            rDictionary.Add(NFSMountStats.MNTERR_TOOBIG, "Arg list too long");
            rDictionary.Add(NFSMountStats.MNTERR_NOEXEC, "Exec format error");
            rDictionary.Add(NFSMountStats.MNTERR_BADF, "Bad file number");
            rDictionary.Add(NFSMountStats.MNTERR_CHILD, "No child processes");
            rDictionary.Add(NFSMountStats.MNTERR_AGAIN, "Try again (Linux), No more processes (SCO Unix)");
            rDictionary.Add(NFSMountStats.MNTERR_NOMEM, "Out of memory (Linux), Not enough space (SCO Unix)");
            rDictionary.Add(NFSMountStats.MNTERR_ACCES, "Permission denied.");
            rDictionary.Add(NFSMountStats.MNTERR_FAULT, "Bad address.");
            rDictionary.Add(NFSMountStats.MNTERR_NOTBLK, "Block device required.");
            rDictionary.Add(NFSMountStats.MNTERR_BUSY, "Device or resource busy (Linux), Device busy (SCO Unix).");
            rDictionary.Add(NFSMountStats.MNTERR_EXIST, "File exists.");
            rDictionary.Add(NFSMountStats.MNTERR_XDEV, "Cross-device link.");
            rDictionary.Add(NFSMountStats.MNTERR_NODEV, "No such device.");
            rDictionary.Add(NFSMountStats.MNTERR_NOTDIR, "Not a directory.");
            rDictionary.Add(NFSMountStats.MNTERR_ISDIR, "Is a directory.");
            rDictionary.Add(NFSMountStats.MNTERR_INVAL, "Invalid argument.");
            rDictionary.Add(NFSMountStats.MNTERR_NFILE, "File table overflow.");
            rDictionary.Add(NFSMountStats.MNTERR_MFILE, "Too many open files.");
            rDictionary.Add(NFSMountStats.MNTERR_NOTTY, "Not a typewriter.");
            rDictionary.Add(NFSMountStats.MNTERR_TXTBSY, "Text file busy.");
            rDictionary.Add(NFSMountStats.MNTERR_FBIG, "File too large.");
            rDictionary.Add(NFSMountStats.MNTERR_NOSPC, "No space left on device.");
            rDictionary.Add(NFSMountStats.MNTERR_SPIPE, "Illegal seek.");
            rDictionary.Add(NFSMountStats.MNTERR_ROFS, "Read-only file system.");
            rDictionary.Add(NFSMountStats.MNTERR_MLINK, "Too many links.");
            rDictionary.Add(NFSMountStats.MNTERR_PIPE, "Broken pipe.");
            rDictionary.Add(NFSMountStats.MNTERR_NAMETOOLONG, "Filename too long.");
            rDictionary.Add(NFSMountStats.MNTERR_NOTSUPP, "Operation not supported.");
            rDictionary.Add(NFSMountStats.MNTERR_SERVERFAULT, "A failure on the server.");

            return rDictionary;
        }

        public static void ThrowException(NFSMountStats ErrorCode)
        {
            if (ErrorCode != NFSMountStats.MNT_OK)
            {
                System.Collections.Generic.Dictionary<NFSMountStats, String> exceptionMessages =
                    MountExceptionHelpers.ExceptionList();

                if (exceptionMessages.ContainsKey(ErrorCode))
                {
                    String Message = exceptionMessages[ErrorCode];

                    switch (ErrorCode)
                    {
                        case NFSMountStats.MNTERR_ACCES:
                            throw new NFSMountAuthenticationException(Message);
                                                    
                        case NFSMountStats.MNTERR_EXIST:
                        case NFSMountStats.MNTERR_FBIG:
                        case NFSMountStats.MNTERR_IO:
                        case NFSMountStats.MNTERR_ISDIR:
                        case NFSMountStats.MNTERR_NAMETOOLONG:
                        case NFSMountStats.MNTERR_NOENT:
                        case NFSMountStats.MNTERR_NOSPC:
                        case NFSMountStats.MNTERR_NOTDIR:
                        case NFSMountStats.MNTERR_NXIO:
                            throw new NFSMountIOException(Message);

                        case NFSMountStats.MNTERR_PERM:
                        case NFSMountStats.MNTERR_ROFS:
                            throw new NFSMountUnauthorizedAccessException(Message);

                        case NFSMountStats.MNTERR_FAULT:
                        case NFSMountStats.MNTERR_BUSY:
                        case NFSMountStats.MNTERR_AGAIN:
                        case NFSMountStats.MNTERR_SERVERFAULT:
                            throw new NFSMountCommunicationException(Message);

                        case NFSMountStats.MNTERR_TXTBSY:
                        case NFSMountStats.MNTERR_TOOBIG:
                        case NFSMountStats.MNTERR_SRCH:
                        case NFSMountStats.MNTERR_NOTTY:
                        case NFSMountStats.MNTERR_NOTBLK:
                        case NFSMountStats.MNTERR_NOMEM:
                        case NFSMountStats.MNTERR_NOEXEC:
                        case NFSMountStats.MNTERR_INVAL:
                        case NFSMountStats.MNTERR_INTR:
                        case NFSMountStats.MNTERR_CHILD:
                        case NFSMountStats.MNTERR_BADF:
                        case NFSMountStats.MNTERR_XDEV:
                        case NFSMountStats.MNTERR_NOTSUPP:
                        case NFSMountStats.MNTERR_NODEV:
                        case NFSMountStats.MNTERR_MLINK:
                        case NFSMountStats.MNTERR_MFILE:
                        case NFSMountStats.MNTERR_NFILE:
                        case NFSMountStats.MNTERR_PIPE:
                        case NFSMountStats.MNTERR_SPIPE:
                            throw new NFSMountGeneralException(Message);

                        default:
                            throw new NFSMountGeneralException("General Exception Occured!");

                    }
                }
                else
                { throw new NFSMountGeneralException("Unknown Exception Occured!"); }
            }
        }
    }

    public class NFSMountGeneralException
        : System.Exception
    {
        public NFSMountGeneralException(string Message)
            : base(Message)
        { }
    }

    public class NFSMountAuthenticationException
        : System.Security.Authentication.AuthenticationException
    {
        public NFSMountAuthenticationException(string Message)
            : base(Message)
        { }
    }

    public class NFSMountUnauthorizedAccessException
        : System.UnauthorizedAccessException
    {
        public NFSMountUnauthorizedAccessException(string Message)
            : base(Message)
        { }
    }

    public class NFSMountIOException
        : System.IO.IOException
    {
        public NFSMountIOException(string Message)
            : base(Message)
        { }
    }

    public class NFSMountConnectionException
        : System.Exception
    {
        public NFSMountConnectionException(string Message)
            : base(Message)
        { }
    }

    public class NFSMountCommunicationException
        : System.Exception
    {
        public NFSMountCommunicationException(string Message)
            : base(Message)
        { }
    }
}