make() public static method

public static make ( ) : ArgErr
return ArgErr
Example #1
0
        public static void make_(Log self, string name, bool register)
        {
            // verify valid name
            Uri.checkName(name);
            self.m_name = name;

            if (register)
            {
                lock (lockObj)
                {
                    // verify unique
                    if (byName[name] != null)
                    {
                        throw ArgErr.make("Duplicate log name: " + name).val;
                    }

                    // init and put into map
                    byName[name] = self;

                    // check for initial level
                    string val = (string)Sys.m_sysPod.props(Uri.fromStr("log.props"), Duration.m_oneMin).get(name);
                    if (val != null)
                    {
                        self.m_level = LogLevel.fromStr(val);
                    }
                }
            }
        }
Example #2
0
            private int checkArgs(int args, bool isStatic, bool isCallOn)
            {
                // compuate min/max parameters - reflect contains all the method versions
                // with full pars at index zero, and full defaults at reflect.Length-1
                int max = m_params.sz();

                if (!isStatic)
                {
                    max--;
                }
                int min = max - m.m_reflect.Length + 1;

                // do checking
                if (isStatic || isCallOn)
                {
                    if (args < min)
                    {
                        throw ArgErr.make("Too few arguments: " + args + " < " + min + ".." + max).val;
                    }
                }
                else
                {
                    if (args < min + 1)
                    {
                        throw ArgErr.make("Too few arguments: " + args + " < instance+" + min + ".." + max).val;
                    }
                    args--;
                }

                // return size of arguments to pass to java method
                return(args <= max ? args : max);
            }
Example #3
0
 /// <summary>
 /// If not valid year range 1901 to 2099 throw ArgErr.
 /// </summary>
 static void checkYear(int year)
 {
     if (year < 1901 || year > 2099)
     {
         throw ArgErr.make("Year out of range " + year).val;
     }
 }
Example #4
0
        private static object doTrap(object self, string name, List args, Type type)
        {
            Slot slot = type.slot(name, true);

            if (slot is Method)
            {
                Method m = (Method)slot;
                return(m.m_func.callOn(self, args));
            }
            else
            {
                Field f       = (Field)slot;
                int   argSize = (args == null) ? 0 : args.sz();
                if (argSize == 0)
                {
                    return(FanUtil.box(f.get(self)));
                }

                if (argSize == 1)
                {
                    object val = args.get(0);
                    f.set(self, val);
                    return(FanUtil.box(val));
                }

                throw ArgErr.make("Invalid number of args to get or set field '" + name + "'").val;
            }
        }
Example #5
0
        public static long random(Range r)
        {
            rand.GetBytes(randBytes);
            long v = BitConverter.ToInt64(randBytes, 0);

            if (r == null)
            {
                return(v);
            }
            if (v < 0)
            {
                v = -v;
            }
            long start = r.start();
            long end   = r.end();

            if (r.inclusive())
            {
                ++end;
            }
            if (end <= start)
            {
                throw ArgErr.make("Range end < start: " + r).val;
            }
            return(start + (v % (end - start)));
        }
Example #6
0
 public OutStream writeNext(Uri path, DateTime modifyTime)
 {
     if (m_zipOut == null)
     {
         throw UnsupportedErr.make("Zip not opened for writing").val;
     }
     if (path.frag() != null)
     {
         throw ArgErr.make("Path must not contain fragment: " + path).val;
     }
     if (path.queryStr() != null)
     {
         throw ArgErr.make("Path must not contain query: " + path).val;
     }
     try
     {
         string zipPath = path.ToString();
         if (zipPath.StartsWith("/"))
         {
             zipPath = zipPath.Substring(1);
         }
         ZipEntry entry = new ZipEntry(zipPath);
         entry.DateTime = new System.DateTime(modifyTime.dotnet());
         m_zipOut.PutNextEntry(entry);
         return(new ZipSysOutStream(m_zipOut));
     }
     catch (System.IO.IOException e)
     {
         throw IOErr.make(e).val;
     }
 }
Example #7
0
 public void level(LogLevel level)
 {
     if (level == null)
     {
         throw ArgErr.make("level cannot be null").val;
     }
     this.m_level = level;
 }
Example #8
0
 public void dir(File v)
 {
     checkRun();
     if (v != null && (!v.exists() || !v.isDir()))
     {
         throw ArgErr.make("Invalid working directory: " + v).val;
     }
     this.m_dir = v;
 }
Example #9
0
        public virtual void set(object instance, object value, bool checkConst)
        {
            m_parent.finish();

            // check const
            if ((m_flags & FConst.Const) != 0)
            {
                if (checkConst)
                {
                    throw ReadonlyErr.make("Cannot set const field " + qname()).val;
                }
                else if (value != null && !isImmutable(value))
                {
                    throw ReadonlyErr.make("Cannot set const field " + qname() + " with mutable value").val;
                }
            }

            // check static
            if ((m_flags & FConst.Static) != 0)
            {
                throw ReadonlyErr.make("Cannot set static field " + qname()).val;
            }

            // check generic type (the .NET runtime will check non-generics)
            if (m_type.isGenericInstance() && value != null)
            {
                if (!@typeof(value).@is(m_type.toNonNullable()))
                {
                    throw ArgErr.make("Wrong type for field " + qname() + ": " + m_type + " != " + @typeof(value)).val;
                }
            }

            if (m_setter != null)
            {
                m_setter.invoke(instance, new object[] { value });
                return;
            }

            try
            {
                m_reflect.SetValue(instance, unbox(value));
            }
            catch (ArgumentException e)
            {
                throw ArgErr.make(e).val;
            }
            catch (Exception e)
            {
                if (m_reflect == null)
                {
                    throw Err.make("Field not mapped to System.Reflection correctly").val;
                }

                throw Err.make(e).val;
            }
        }
Example #10
0
 public static string toCode(long self, long b)
 {
     if (b == 10)
     {
         return(self.ToString());
     }
     if (b == 16)
     {
         return("0x" + toHex(self));
     }
     throw ArgErr.make("Invalid base " + b).val;
 }
Example #11
0
        public override sealed void capacity(long c)
        {
            int newCapacity = (int)c;

            if (newCapacity < m_size)
            {
                throw ArgErr.make("capacity < size").val;
            }
            byte[] temp = new byte[newCapacity];
            System.Array.Copy(m_buf, 0, temp, 0, Math.Min(m_size, newCapacity));
            m_buf = temp;
        }
Example #12
0
        public void capacity(long c)
        {
            modify();
            int newCapacity = (int)c;

            if (newCapacity < m_size)
            {
                throw ArgErr.make("capacity < m_size").val;
            }
            object[] temp = new object[newCapacity];
            Array.Copy(m_values, 0, temp, 0, m_size);
            m_values = temp;
        }
Example #13
0
        private Date plus(long ticks)
        {
            // check even number of days
            if (ticks % Duration.nsPerDay != 0)
            {
                throw ArgErr.make("Duration must be even num of days").val;
            }

            int year  = this.m_year;
            int month = this.m_month;
            int day   = this.m_day;

            int numDays = (int)(ticks / Duration.nsPerDay);
            int dayIncr = numDays < 0 ? +1 : -1;

            while (numDays != 0)
            {
                if (numDays > 0)
                {
                    day++;
                    if (day > numDaysInMon(year, month))
                    {
                        day = 1;
                        month++;
                        if (month >= 12)
                        {
                            month = 0; year++;
                        }
                    }
                    numDays--;
                }
                else
                {
                    day--;
                    if (day <= 0)
                    {
                        month--;
                        if (month < 0)
                        {
                            month = 11; year--;
                        }
                        day = numDaysInMon(year, month);
                    }
                    numDays++;
                }
            }

            return(new Date(year, month, day));
        }
Example #14
0
        public virtual Type parameterize(Map pars)
        {
            if (this == Sys.ListType)
            {
                Type v = (Type)pars.get(FanStr.m_ascii['V']);
                if (v == null)
                {
                    throw ArgErr.make("List.parameterize - V undefined").val;
                }
                return(v.toListOf());
            }

            if (this == Sys.MapType)
            {
                Type v = (Type)pars.get(FanStr.m_ascii['V']);
                Type k = (Type)pars.get(FanStr.m_ascii['K']);
                if (v == null)
                {
                    throw ArgErr.make("Map.parameterize - V undefined").val;
                }
                if (k == null)
                {
                    throw ArgErr.make("Map.parameterize - K undefined").val;
                }
                return(new MapType(k, v));
            }

            if (this == Sys.FuncType)
            {
                Type r = (Type)pars.get(FanStr.m_ascii['R']);
                if (r == null)
                {
                    throw ArgErr.make("Map.parameterize - R undefined").val;
                }
                ArrayList p = new ArrayList();
                for (int i = 'A'; i <= 'H'; ++i)
                {
                    Type x = (Type)pars.get(FanStr.m_ascii[i]);
                    if (x == null)
                    {
                        break;
                    }
                    p.Add(x);
                }
                return(new FuncType((Type[])p.ToArray(System.Type.GetType("Fan.Sys.Type")), r));
            }

            throw UnsupportedErr.make("not generic: " + this).val;
        }
Example #15
0
        internal Date(int year, int month, int day)
        {
            if (month < 0 || month > 11)
            {
                throw ArgErr.make("month " + month).val;
            }
            if (day < 1 || day > DateTime.numDaysInMonth(year, month))
            {
                throw ArgErr.make("day " + day).val;
            }

            this.m_year  = (short)year;
            this.m_month = (byte)month;
            this.m_day   = (byte)day;
        }
Example #16
0
        public override Buf toDigest(string algorithm)
        {
            string alg = algorithm;

            if (alg == "SHA-1")
            {
                alg = "SHA1";            // to make .NET happy
            }
            HashAlgorithm ha = HashAlgorithm.Create(alg);

            if (ha == null)
            {
                throw ArgErr.make("Unknown digest algorthm: " + algorithm).val;
            }
            return(new MemBuf(ha.ComputeHash(m_buf, 0, m_size)));
        }
Example #17
0
        public static void make_(ActorPool self, Func itBlock)
        {
            if (itBlock != null)
            {
                itBlock.enterCtor(self);
                itBlock.call(self);
                itBlock.exitCtor();
            }
            if (self.m_maxThreads < 1)
            {
                throw ArgErr.make("ActorPool.maxThreads must be >= 1, not " + self.m_maxThreads).val;
            }

            self.m_threadPool = new ThreadPool((int)self.m_maxThreads);
            self.m_scheduler  = new Scheduler();
        }
Example #18
0
        internal void open(string name, string mode, bool existing, uint size)
        {
            // file mode
            FileRights fr; FileProtection fp;

            if (mode == "r")
            {
                fr = FileRights.Read; fp = FileProtection.ReadOnly;
            }
            else if (mode == "rw")
            {
                fr = FileRights.ReadWrite; fp = FileProtection.ReadWrite;
            }
            else if (mode == "p")
            {
                throw ArgErr.make("Private mode not supported.").val;
            }
            else
            {
                throw ArgErr.make("Invalid mode: " + mode).val;
            }

            if (existing)
            {
                m_fileHandle = OpenFileMapping(fr, false, name);
                if (m_fileHandle == IntPtr.Zero)
                {
                    throw IOErr.make("Open error: " + Marshal.GetLastWin32Error()).val;
                }
            }
            else
            {
                m_fileHandle = CreateFileMapping(NoFileHandle, 0, fp, 0, size, name);
                if (m_fileHandle == IntPtr.Zero)
                {
                    throw IOErr.make("Create error: " + Marshal.GetLastWin32Error()).val;
                }
            }

            // Obtain a read/write map for the entire file
            m_fileMap = MapViewOfFile(m_fileHandle, fr, 0, 0, 0);

            if (m_fileMap == IntPtr.Zero)
            {
                throw IOErr.make("MapViewOfFile error: " + Marshal.GetLastWin32Error()).val;
            }
        }
Example #19
0
        public static Version make(List segments)
        {
            bool valid = segments.sz() > 0;

            for (int i = 0; i < segments.sz(); i++)
            {
                if (((Long)segments.get(i)).longValue() < 0)
                {
                    valid = false;
                }
            }
            if (!valid)
            {
                throw ArgErr.make("Invalid Version: '" + segments + "'").val;
            }
            return(new Version(segments));
        }
Example #20
0
        public static int weekdayInMonth(int year, int mon, int weekday, int pos)
        {
            // argument checking
            checkYear(year);
            if (pos == 0)
            {
                throw ArgErr.make("Pos is zero").val;
            }

            // compute the weekday of the 1st of this month (0-6)
            int fw = firstWeekday(year, mon);

            // get number of days in this month
            int numDays = numDaysInMonth(year, mon);

            if (pos > 0)
            {
                int day = weekday - fw + 1;
                if (day <= 0)
                {
                    day = 8 - fw + weekday;
                }
                day += (pos - 1) * 7;
                if (day > numDays)
                {
                    throw ArgErr.make("Pos out of range " + pos).val;
                }
                return(day);
            }
            else
            {
                int lastWeekday = (fw + numDays - 1) % 7;
                int off         = lastWeekday - weekday;
                if (off < 0)
                {
                    off = 7 + off;
                }
                off -= (pos + 1) * 7;
                int day = numDays - off;
                if (day < 1)
                {
                    throw ArgErr.make("Pos out of range " + pos).val;
                }
                return(day);
            }
        }
Example #21
0
 public Map add(object key, object val)
 {
     modify();
     if (key == null)
     {
         throw NullErr.make("key is null").val;
     }
     if (!isImmutable(key))
     {
         throw NotImmutableErr.make("key is not immutable: " + @typeof(key)).val;
     }
     if (containsKey(key))
     {
         throw ArgErr.make("Key already mapped: " + key).val;
     }
     m_map[key] = val;
     return(this);
 }
Example #22
0
        //////////////////////////////////////////////////////////////////////////
        // Find Files
        //////////////////////////////////////////////////////////////////////////

        public override File findFile(Uri uri, bool check)
        {
            if (uri.isPathAbs())
            {
                throw ArgErr.make("Uri must be relative: " + uri).val;
            }
            File f = m_homeDir.plus(uri, false);

            if (f.exists())
            {
                return(f);
            }
            if (!check)
            {
                return(null);
            }
            throw UnresolvedErr.make("File not found in Env: " + uri).val;
        }
Example #23
0
        public static long pow(long self, long pow)
        {
            if (pow < 0)
            {
                throw ArgErr.make("pow < 0").val;
            }
            long result = 1;

            for (; pow > 0; pow >>= 1)
            {
                if ((pow & 1) == 1)
                {
                    result *= self;
                }
                self *= self;
            }
            return(result);
        }
Example #24
0
        public override File moveTo(File to)
        {
            if (isDir() != to.isDir())
            {
                if (isDir())
                {
                    throw ArgErr.make("moveTo must be dir `" + to + "`").val;
                }
                else
                {
                    throw ArgErr.make("moveTo must not be dir `" + to + "`").val;
                }
            }

            if (!(to is LocalFile))
            {
                throw IOErr.make("Cannot move LocalFile to " + to.@typeof()).val;
            }
            LocalFile dest = (LocalFile)to;

            if (dest.exists())
            {
                throw IOErr.make("moveTo already exists: " + to).val;
            }

            try
            {
                if (m_file is FileInfo)
                {
                    (m_file as FileInfo).MoveTo((dest.m_file as FileInfo).FullName);
                }
                else
                {
                    (m_file as DirectoryInfo).MoveTo((dest.m_file as DirectoryInfo).FullName);
                }
            }
            catch (System.IO.IOException)
            {
                throw IOErr.make("moveTo failed: " + to).val;
            }

            return(to);
        }
Example #25
0
        //////////////////////////////////////////////////////////////////////////
        // Misc
        //////////////////////////////////////////////////////////////////////////

        public static Time fromDuration(Duration d)
        {
            long ticks = d.m_ticks;

            if (ticks == 0)
            {
                return(m_defVal);
            }

            if (ticks < 0 || ticks > Duration.nsPerDay)
            {
                throw ArgErr.make("Duration out of range: " + d).val;
            }

            int hour = (int)(ticks / Duration.nsPerHr);  ticks %= Duration.nsPerHr;
            int min  = (int)(ticks / Duration.nsPerMin); ticks %= Duration.nsPerMin;
            int sec  = (int)(ticks / Duration.nsPerSec); ticks %= Duration.nsPerSec;
            int ns   = (int)ticks;

            return(new Time(hour, min, sec, ns));
        }
Example #26
0
 public Fan.Sys.File file(Uri uri, bool check)
 {
     loadFiles();
     if (!uri.isPathAbs())
     {
         throw ArgErr.make("Pod.files Uri must be path abs: " + uri).val;
     }
     if (uri.auth() != null && !uri.toStr().StartsWith(this.uri().toStr()))
     {
         throw ArgErr.make("Invalid base uri `" + uri + "` for `" + this.uri() + "`").val;
     }
     else
     {
         uri = this.uri().plus(uri);
     }
     Fan.Sys.File f = (Fan.Sys.File)m_filesMap[uri];
     if (f != null || !check)
     {
         return(f);
     }
     throw UnresolvedErr.make(uri.toStr()).val;
 }
Example #27
0
        public static FileSystemInfo uriToFile(Uri uri)
        {
            if (uri.scheme() != null && uri.scheme() != "file")
            {
                throw ArgErr.make("Invalid Uri scheme for local file: " + uri).val;
            }
            string path = uriToPath(uri);

            if (System.IO.Directory.Exists(path))
            {
                return(new DirectoryInfo(path));
            }
            if (System.IO.File.Exists(path))
            {
                return(new FileInfo(path));
            }
            if (uri.isDir())
            {
                return(new DirectoryInfo(path));
            }
            return(new FileInfo(path));
        }
Example #28
0
        public virtual string readChars(long n)
        {
            if (n < 0)
            {
                throw ArgErr.make("readChars n < 0: " + n).val;
            }
            if (n == 0)
            {
                return("");
            }
            StringBuilder buf = new StringBuilder(256);

            for (int i = (int)n; i > 0; --i)
            {
                int ch = rChar();
                if (ch < 0)
                {
                    throw IOErr.make("Unexpected end of stream").val;
                }
                buf.Append((char)ch);
            }
            return(buf.ToString());
        }
Example #29
0
        public static void make_(Actor self, ActorPool pool, Func receive)
        {
            // check pool
            if (pool == null)
            {
                throw NullErr.make("pool is null").val;
            }

            // check receive method
            if (receive == null && self.@typeof().qname() == "concurrent::Actor")
            {
                throw ArgErr.make("must supply receive func or subclass Actor").val;
            }
            if (receive != null && !receive.isImmutable())
            {
                throw NotImmutableErr.make("Receive func not immutable: " + receive).val;
            }

            // init
            self.m_pool    = pool;
            self.m_receive = receive;
            self.m_queue   = new Queue();
        }
Example #30
0
        public override Buf toDigest(string algorithm)
        {
            string alg = algorithm;

            if (alg == "SHA-1")
            {
                alg = "SHA1";            // to make .NET happy
            }
            HashAlgorithm ha = HashAlgorithm.Create(alg);

            if (ha == null)
            {
                throw ArgErr.make("Unknown digest algorthm: " + algorithm).val;
            }

            try
            {
                long   oldPos = getPos();
                long   size   = getSize();
                byte[] temp   = this.temp();

                setPos(0);
                long total = 0;
                while (total < size)
                {
                    int n = m_stream.Read(temp, (int)total, (int)(size - total));
                    total += n;
                }

                setPos(oldPos);
                return(new MemBuf(ha.ComputeHash(temp, 0, (int)size)));
            }
            catch (IOException e)
            {
                throw IOErr.make(e).val;
            }
        }