Example #1
0
        public virtual File copyTo(File to, Map options)
        {
            // sanity
            if (isDir() != to.isDir())
            {
                if (isDir())
                {
                    throw ArgErr.make("copyTo must be dir `" + to + "`").val;
                }
                else
                {
                    throw ArgErr.make("copyTo must not be dir `" + to + "`").val;
                }
            }

            // options
            object exclude = null, overwrite = null;

            if (options != null)
            {
                exclude   = options.get(optExclude);
                overwrite = options.get(optOverwrite);
            }

            // recurse
            doCopyTo(to, exclude, overwrite);
            return(to);
        }
Example #2
0
        //////////////////////////////////////////////////////////////////////////
        // Factory
        //////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Parse the signature into a loaded type.
        /// </summary>
        public static Type load(string sig, bool check, Pod loadingPod)
        {
            // if last character is ?, then parse a nullable
            int len  = sig.Length;
            int last = len > 1 ? sig[len - 1] : 0;

            if (last == '?')
            {
                return(load(sig.Substring(0, len - 1), check, loadingPod).toNullable());
            }

            // if the last character isn't ] or |, then this a non-generic
            // type and we don't even need to allocate a parser
            if (last != ']' && last != '|')
            {
                string podName, typeName;
                try
                {
                    int colon = sig.IndexOf(':');
                    if (sig[colon + 1] != ':')
                    {
                        throw new System.Exception();
                    }
                    podName  = sig.Substring(0, colon);
                    typeName = sig.Substring(colon + 2);
                    if (podName.Length == 0 || typeName.Length == 0)
                    {
                        throw new System.Exception();
                    }
                }
                catch (System.Exception)
                {
                    throw ArgErr.make("Invalid type signature '" + sig + "', use <pod>::<type>").val;
                }

                // if the type is from the pod being loaded then return to the pod
                if (loadingPod != null && podName == loadingPod.name())
                {
                    return(loadingPod.type(typeName, check));
                }

                // do a straight lookup
                return(find(podName, typeName, check));
            }

            // we got our work cut out for us - create parser
            try
            {
                return(new TypeParser(sig, check, loadingPod).LoadTop());
            }
            catch (Err.Val e)
            {
                throw e;
            }
            catch (System.Exception)
            {
                throw Err(sig).val;
            }
        }
Example #3
0
        public virtual File moveInto(File dir)
        {
            if (!dir.isDir())
            {
                throw ArgErr.make("Not a dir: `" + dir + "`").val;
            }

            return(moveTo(dir.plusNameOf(this)));
        }
Example #4
0
        public virtual File copyInto(File dir, Map options)
        {
            if (!dir.isDir())
            {
                throw ArgErr.make("Not a dir: `" + dir + "`").val;
            }

            return(copyTo(dir.plusNameOf(this), options));
        }
Example #5
0
        //////////////////////////////////////////////////////////////////////////
        // Retype
        //////////////////////////////////////////////////////////////////////////

        public Func retype(Type t)
        {
            try
            {
                return(new Wrapper((FuncType)t, this));
            }
            catch (System.InvalidCastException)
            {
                throw ArgErr.make("Not a Func type: " + t).val;
            }
        }
Example #6
0
        public void send(UdpSocket fan, UdpPacket packet)
        {
            // map buf bytes to packet
            MemBuf data = (MemBuf)packet.data();

            byte[] buf = data.m_buf;
            int    off = data.m_pos;
            int    len = data.m_size - off;

            // map address, port
            IpAddr addr = packet.addr();
            Long   port = packet.port();

            if (isConnected(fan))
            {
                if (addr != null || port != null)
                {
                    throw ArgErr.make("Address and port must be null to send while connected").val;
                }

                try
                {
                    m_dotnet.Send(buf, off, len, SocketFlags.None);
                }
                catch (SocketException e)
                {
                    throw IOErr.make(e).val;
                }
            }
            else
            {
                if (addr == null || port == null)
                {
                    throw ArgErr.make("Address or port is null").val;
                }

                try
                {
                    if (m_dotnet == null)
                    {
                        m_dotnet = createSocket();
                    }
                    IPEndPoint endPoint = new IPEndPoint(addr.m_peer.m_dotnet, port.intValue());
                    m_dotnet.SendTo(buf, off, len, SocketFlags.None, endPoint);
                }
                catch (SocketException e)
                {
                    throw IOErr.make(e).val;
                }
            }

            // lastly drain buf
            data.m_pos += len;
        }
Example #7
0
 public static IpAddr makeBytes(Buf bytes)
 {
     try
     {
         MemBuf    mb     = bytes as MemBuf;
         IPAddress dotnet = new IPAddress(mb.bytes());
         return(make(dotnet.ToString(), dotnet));
     }
     catch (SocketException e)
     {
         throw ArgErr.make(e.Message).val;
     }
 }
Example #8
0
        private CachedProps refresh(Key key, CachedProps cp)
        {
            List files = m_env.findAllFiles(Uri.fromStr("etc/" + key.m_pod + "/" + key.m_uri));

            if (cp != null && !cp.isStale(files))
            {
                return(cp);
            }
            if (key.m_uri.isPathAbs())
            {
                throw ArgErr.make("Env.props Uri must be relative: " + key.m_uri).val;
            }
            cp           = new CachedProps(key, files);
            m_cache[key] = cp;
            return(cp);
        }
Example #9
0
        public string toLocale(string pattern)
        {
            if (pattern == null)
            {
                return(localeAbbr());
            }
            if (FanStr.isEveryChar(pattern, 'W'))
            {
                switch (pattern.Length)
                {
                case 3: return(localeAbbr());

                case 4: return(localeFull());
                }
            }
            throw ArgErr.make("Invalid pattern: " + pattern).val;
        }
Example #10
0
        //////////////////////////////////////////////////////////////////////////
        // Bind
        //////////////////////////////////////////////////////////////////////////

        public Func bind(List args)
        {
            if (args.sz() == 0)
            {
                return(this);
            }
            if (args.sz() > @params().sz())
            {
                throw ArgErr.make("args.size > params.size").val;
            }

            Type[] newParams = new Type[@params().sz() - args.sz()];
            for (int i = 0; i < newParams.Length; ++i)
            {
                newParams[i] = ((Param)@params().get(args.sz() + i)).m_type;
            }

            FuncType newType = new FuncType(newParams, this.returns());

            return(new BindFunc(newType, this, args));
        }
Example #11
0
        public override object get(Uri uri, object @base)
        {
            // don't support anything but relative fan: URIs right now
            if (uri.auth() == null)
            {
                throw ArgErr.make("Invalid format for fan: URI - " + uri).val;
            }

            // lookup pod
            string podName = (string)uri.auth();
            Pod    pod     = Pod.find(podName, false);

            if (pod == null)
            {
                throw UnresolvedErr.make(uri.toStr()).val;
            }
            if (uri.pathStr().Length == 0)
            {
                return(pod);
            }

            // dive into file of pod
            return(pod.file(uri));
        }
Example #12
0
 private static Err Err(string sig)
 {
     return(ArgErr.make("Invalid type signature '" + sig + "'"));
 }