cur() public static method

public static cur ( ) : Env
return Env
Ejemplo n.º 1
0
        public static String toLocale(long self, string pattern)
        {
            // if pattern is "B" format as bytes
            if (pattern != null && pattern.Length == 1 && pattern[0] == 'B')
            {
                return(toLocaleBytes(self));
            }

            // get current locale
            Locale           locale = Locale.cur();
            NumberFormatInfo df     = locale.dec();

            // get default pattern if necessary
            if (pattern == null)
            {
                pattern = Env.cur().locale(Sys.m_sysPod, "int", "#,###");
            }

            // parse pattern and get digits
            NumPattern p = NumPattern.parse(pattern);
            NumDigits  d = new NumDigits(self);

            // route to common FanNum method
            return(FanNum.toLocale(p, d, df));
        }
Ejemplo n.º 2
0
        public static UriScheme find(string scheme, bool check)
        {
            // check cache
            lock (m_cache)
            {
                UriScheme cached = (UriScheme)m_cache[scheme];
                if (cached != null)
                {
                    return(cached);
                }
            }

            try
            {
                // lookup scheme type (avoid building index for common types)
                Type t = null;
                if (scheme == "fan")
                {
                    t = Sys.FanSchemeType;
                }
                if (scheme == "file")
                {
                    t = Sys.FileSchemeType;
                }
                if (t == null)
                {
                    string qname = (string)Env.cur().index("sys.uriScheme." + scheme).first();
                    if (qname == null)
                    {
                        throw UnresolvedErr.make().val;
                    }
                    t = Type.find(qname);
                }

                // allocate instance
                UriScheme s = (UriScheme)t.make();
                s.m_scheme = scheme;

                // add to cache
                lock (m_cache)
                {
                    UriScheme cached = (UriScheme)m_cache[scheme];
                    if (cached != null)
                    {
                        return(cached);
                    }
                    m_cache[scheme] = s;
                }

                return(s);
            }
            catch (UnresolvedErr.Val) {}
            catch (System.Exception e) { Err.dumpStack(e); }

            if (!check)
            {
                return(null);
            }
            throw UnresolvedErr.make("Unknown scheme: " + scheme).val;
        }
Ejemplo n.º 3
0
 public static List list()
 {
     lock (m_podsByName)
     {
         // TODO - eventually we need a faster way to load
         //  pod meta-data into memory without actually loading
         //  every pod into memory
         if (m_allPodsList == null)
         {
             List names = Env.cur().findAllPodNames();
             List pods  = new List(Sys.PodType);
             for (int i = 0; i < names.sz(); ++i)
             {
                 string name = (string)names.get(i);
                 try
                 {
                     pods.add(doFind(name, true, null));
                 }
                 catch (Exception e)
                 {
                     System.Console.WriteLine("ERROR: Invalid pod file: " + name);
                     Err.dumpStack(e);
                 }
             }
             m_allPodsList = pods.ro();
         }
         return(m_allPodsList);
     }
 }
Ejemplo n.º 4
0
        private static List loadDatabase()
        {
            InStream input         = null;
            List     quantityNames = new List(Sys.StrType);

            try
            {
                // parse etc/sys/units.fog as big serialized list which contains
                // lists for each quantity (first item being the name)
                String path = "etc/sys/units.txt";
                input = Env.cur().findFile(path).@in();

                // parse each line
                string curQuantityName = null;
                List   curQuantityList = null;
                string line;
                while ((line = input.readLine()) != null)
                {
                    // skip comment and blank lines
                    line = line.Trim();
                    if (line.StartsWith("//") || line.Length == 0)
                    {
                        continue;
                    }

                    // quanity sections delimited as "-- name (dim)"
                    if (line.StartsWith("--"))
                    {
                        if (curQuantityName != null)
                        {
                            m_quantities[curQuantityName] = curQuantityList.toImmutable();
                        }
                        curQuantityName = line.Substring(2, line.IndexOf('(') - 2).Trim();
                        curQuantityList = new List(Sys.UnitType);
                        quantityNames.add(curQuantityName);
                        continue;
                    }

                    // must be a unit
                    try
                    {
                        Unit unit = Unit.define(line);
                        curQuantityList.add(unit);
                    }
                    catch (Exception e)
                    {
                        System.Console.WriteLine("WARNING: Init unit in etc/sys/units.txt: " + line);
                        System.Console.WriteLine("  " + e);
                    }
                }
                m_quantities[curQuantityName] = curQuantityList.toImmutable();
            }
            catch (Exception e)
            {
                try { input.close(); } catch (Exception) {}
                System.Console.WriteLine("WARNING: Cannot load lib/units.txt");
                Err.dumpStack(e);
            }
            return((List)quantityNames.toImmutable());
        }
Ejemplo n.º 5
0
        //////////////////////////////////////////////////////////////////////////
        // Utils
        //////////////////////////////////////////////////////////////////////////

        public File tempDir()
        {
            if (m_tempDir == null)
            {
                m_tempDir = Env.cur().tempDir().plus(Uri.fromStr("test/"), false);
                m_tempDir.delete();
                m_tempDir.create();
            }
            return(m_tempDir);
        }
Ejemplo n.º 6
0
        public static string toLocale(double self, string pattern)
        {
            try
            {
                // get current locale
                Locale           locale = Locale.cur();
                NumberFormatInfo df     = locale.dec();

                // handle special values
                if (System.Double.IsNaN(self))
                {
                    return(df.NaNSymbol);
                }
                if (self == System.Double.PositiveInfinity)
                {
                    return(df.PositiveInfinitySymbol);
                }
                if (self == System.Double.NegativeInfinity)
                {
                    return(df.NegativeInfinitySymbol);
                }

                // get default pattern if necessary
                if (pattern == null)
                {
                    pattern = Env.cur().locale(Sys.m_sysPod, "float", "#,###.0##");
                }

                // TODO: if value is < 10^-3 or > 10^7 it will be
                // converted to exponent string, so just bail on that
                string str = Double.toString(self);
                if (str.IndexOf('E') > 0)
                {
                    str = self.ToString("0.#########");
                }

                // parse pattern and get digits
                NumPattern p = NumPattern.parse(pattern);
                NumDigits  d = new NumDigits(str);

                // route to common FanNum method
                return(FanNum.toLocale(p, d, df));
            }
            catch (Exception e)
            {
                Err.dumpStack(e);
                return(self.ToString());
            }
        }
Ejemplo n.º 7
0
        public string toLocale(string pattern)
        {
            // locale specific default
            Locale locale = null;

            if (pattern == null)
            {
                if (locale == null)
                {
                    locale = Locale.cur();
                }
                pattern = Env.cur().locale(Sys.m_sysPod, m_localeKey, "D-MMM-YYYY", locale);
            }

            return(new DateTimeStr(pattern, locale, this).format());
        }
Ejemplo n.º 8
0
        //////////////////////////////////////////////////////////////////////////
        // Init Env
        //////////////////////////////////////////////////////////////////////////

        private static bool initEnv()
        {
            try
            {
                string var = (string)Env.cur().vars().get("FAN_ENV");
                if (var == null)
                {
                    return(true);
                }
                m_curEnv = (Env)Type.find(var).make();
            }
            catch (Exception e)
            {
                initWarn("curEnv", e);
            }
            return(true);
        }
Ejemplo n.º 9
0
        public static FPod readFPod(string name)
        {
            FStore store = null;

            // handle sys specially for bootstrapping the VM
            if (name == "sys")
            {
                store = new FStore(new ZipFile(FileUtil.combine(Sys.m_podsDir, name + ".pod")));
            }

            // otherwise delegate to Env.cur to find the pod file
            else
            {
                FileSystemInfo file = null;
                Fan.Sys.File   f    = Env.cur().findPodFile(name);
                if (f != null)
                {
                    file = ((LocalFile)f).m_file;
                }

                // if null or doesn't exist then its a no go
                if (file == null || !file.Exists)
                {
                    throw UnknownPodErr.make(name).val;
                }

                // verify case since Windoze is case insensitive
                String actualName = file.Name; //getCanonicalFile().getName();
                actualName = actualName.Substring(0, actualName.Length - 4);
                if (actualName != name)
                {
                    throw UnknownPodErr.make("Mismatch case: " + name + " != " + actualName).val;
                }

                store = new FStore(new ZipFile(file.FullName));
            }

            // read in the FPod tables
            FPod fpod = new FPod(name, store);

            fpod.read();
            return(fpod);
        }
Ejemplo n.º 10
0
        public static string toLocale(BigDecimal self, string pattern)
        {
            // get current locale
            Locale           locale = Locale.cur();
            NumberFormatInfo df     = locale.dec();

            // get default pattern if necessary
            if (pattern == null)
            {
                pattern = Env.cur().locale(Sys.m_sysPod, "decimal", "#,###.0##");
            }

            // parse pattern and get digits
            NumPattern p = NumPattern.parse(pattern);
            NumDigits  d = new NumDigits(self);

            // route to common FanNum method
            return(FanNum.toLocale(p, d, df));
        }
Ejemplo n.º 11
0
        //////////////////////////////////////////////////////////////////////////
        // Locale
        //////////////////////////////////////////////////////////////////////////

        public string toLocale()
        {
            long          ticks  = this.m_ticks;
            Pod           pod    = Sys.m_sysPod;
            Env           env    = Env.cur();
            Locale        locale = Locale.cur();
            StringBuilder s;

            // less than 1000ns Xns
            if (ticks < 1000L)
            {
                return(ticks + env.locale(pod, "nsAbbr", "ns", locale));
            }

            // less than 2ms X.XXXms
            if (ticks < 2 * nsPerMilli)
            {
                s = new StringBuilder();
                long ms = ticks / nsPerMilli;
                long us = (ticks - ms * nsPerMilli) / 1000L;
                s.Append(ms);
                s.Append('.');
                if (us < 100)
                {
                    s.Append('0');
                }
                if (us < 10)
                {
                    s.Append('0');
                }
                s.Append(us);
                if (s[s.Length - 1] == '0')
                {
                    s.Length = s.Length - 1;
                }
                if (s[s.Length - 1] == '0')
                {
                    s.Length = s.Length - 1;
                }
                s.Append(env.locale(pod, "msAbbr", "ms", locale));
                return(s.ToString());
            }

            // less than 2sec Xms
            if (ticks < 2L * nsPerSec)
            {
                return((ticks / nsPerMilli) + env.locale(pod, "msAbbr", "ms", locale));
            }

            // less than 2min Xsec
            if (ticks < 1L * nsPerMin)
            {
                return((ticks / nsPerSec) + env.locale(pod, "secAbbr", "sec", locale));
            }

            // [Xdays] [Xhr] Xmin Xsec
            long days = ticks / nsPerDay; ticks -= days * nsPerDay;
            long hr   = ticks / nsPerHr;    ticks -= hr * nsPerHr;
            long min  = ticks / nsPerMin;   ticks -= min * nsPerMin;
            long sec  = ticks / nsPerSec;

            s = new StringBuilder();
            if (days > 0)
            {
                s.Append(days).Append(days == 1 ? env.locale(pod, "dayAbbr", "day", locale) : env.locale(pod, "daysAbbr", "days", locale)).Append(" ");
            }
            if (hr > 0)
            {
                s.Append(hr).Append(env.locale(pod, "hourAbbr", "hr", locale)).Append(" ");
            }
            if (min > 0)
            {
                s.Append(min).Append(env.locale(pod, "minAbbr", "min", locale)).Append(" ");
            }
            if (sec > 0)
            {
                s.Append(sec).Append(env.locale(pod, "secAbbr", "sec", locale)).Append(" ");
            }
            s.Length = s.Length - 1;
            return(s.ToString());
        }
Ejemplo n.º 12
0
 public string config(string key, string def)
 {
     return(Env.cur().config(this, key, def));
 }
Ejemplo n.º 13
0
 public Map props(Uri uri, Duration maxAge)
 {
     return(Env.cur().props(this, uri, maxAge));
 }
Ejemplo n.º 14
0
        static TimeZone()
        {
            try
            {
                loadIndex();
            }
            catch (Exception e)
            {
                System.Console.WriteLine("ERROR: Cannot load timezone database");
                Err.dumpStack(e);
            }

            try
            {
                m_utc = fromStr("Etc/UTC");
            }
            catch (Exception e)
            {
                System.Console.WriteLine("ERROR: Cannot init UTC timezone");
                Err.dumpStack(e);

                m_utc = loadFallback("Etc/UTC", "UTC");
            }

            try
            {
                m_rel = fromStr("Etc/Rel");
            }
            catch (Exception e)
            {
                System.Console.WriteLine("ERROR: Cannot init Rel timezone");
                Err.dumpStack(e);

                m_rel = loadFallback("Etc/Rel", "Rel");
            }

            try
            {
                // first check system property
                string sysProp = (string)Env.cur().vars().get("fan.timezone");
                if (sysProp != null)
                {
                    m_cur = fromStr(sysProp);
                }

                // we assume Java default uses Olson name
                else
                {
                    // TODO - no clue how to auto map this yet
                    //cur = fromStr(java.util.TimeZone.getDefault().getID());
                    m_cur = fromStr("America/New_York");
                }
            }
            catch (Exception e)
            {
                System.Console.WriteLine("ERROR: Cannot init current timezone");
                Err.dumpStack(e);

                m_cur = m_utc;
            }
        }
Ejemplo n.º 15
0
        //////////////////////////////////////////////////////////////////////////
        // Identity
        //////////////////////////////////////////////////////////////////////////

        public static long hash(Service self)
        {
            return(Env.cur().idHash(self));
        }
Ejemplo n.º 16
0
 public string config(string key)
 {
     return(Env.cur().config(this, key));
 }
Ejemplo n.º 17
0
 public Err trace()
 {
     return(trace(Env.cur().@err(), null, 0, true));
 }
Ejemplo n.º 18
0
 public string locale(string key, string def)
 {
     return(Env.cur().locale(this, key, def));
 }
Ejemplo n.º 19
0
 public static string toLocale(bool self)
 {
     return(Env.cur().locale(Sys.m_sysPod, self ? "boolTrue" : "boolFalse", toStr(self)));
 }
Ejemplo n.º 20
0
 public void print()
 {
     print(Env.cur().@out());
 }
Ejemplo n.º 21
0
 public string locale(string key)
 {
     return(Env.cur().locale(this, key));
 }