public Map get(Pod pod, Uri uri, Duration maxAge) { Key key = new Key(pod, uri); CachedProps cp = (CachedProps)m_cache[key]; if (cp == null || Duration.nowTicks() - cp.m_read > maxAge.m_ticks) cp = refresh(key, cp); return cp.m_props; }
private string sig; // signature being parsed #endregion Fields #region Constructors ////////////////////////////////////////////////////////////////////////// // Constructor ////////////////////////////////////////////////////////////////////////// private TypeParser(string sig, bool check, Pod loadingPod) { this.sig = sig; this.len = sig.Length; this.pos = 0; this.cur = sig[pos]; this.peek = sig[pos+1]; this.check = check; this.loadingPod = loadingPod; }
public static Facets mapFacets(Pod pod, FAttrs.FFacet[] ffacets) { if (ffacets == null || ffacets.Length == 0) return empty(); Hashtable map = new Hashtable(); for (int i=0; i<ffacets.Length; ++i) { FAttrs.FFacet ff = ffacets[i]; Type t = pod.findType(ff.type); map[t] = ff.val; } return new Facets(map); }
////////////////////////////////////////////////////////////////////////// // 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; } }
static Map readDef(Pod pod, Uri uri) { uri = Uri.fromStr(pod.uri() + "/" + uri); Fan.Sys.File f = (Fan.Sys.File)pod.file(uri, false); Map map = Sys.m_emptyStrStrMap; try { if (f != null) map = (Map)f.readProps().toImmutable(); } catch (System.Exception e) { System.Console.WriteLine("ERROR: Cannot load props " + pod + "::" + uri); System.Console.WriteLine(" " + e); } return map; }
public virtual string config(Pod pod, string key) { return(config(pod, key, null)); }
public virtual Map props(Pod pod, Uri uri, Duration maxAge) { return(m_props.get(pod, uri, maxAge)); }
private Type[] tests(Pod pod, string testName) { // named test if (testName != "*") return new Type[] { pod.type(testName, true) }; // all types which subclass Test List all = pod.types(); ArrayList acc = new ArrayList(); for (int i=0; i<all.sz(); i++) { Type x = (Type)all.get(i); if (x.@is(Sys.TestType) && !x.isAbstract()) acc.Add(x); } return (Type[])acc.ToArray(System.Type.GetType("Fan.Sys.Type")); }
public static Pod load(InStream @in) { FPod fpod = null; try { fpod = new FPod(null, null); fpod.readFully(new ZipInputStream(SysInStream.dotnet(@in))); } catch (Exception e) { throw Err.make(e).val; } string name = fpod.m_podName; lock (m_podsByName) { // check for duplicate pod name if (m_podsByName[name] != null) throw Err.make("Duplicate pod name: " + name).val; // create Pod and add to master table Pod pod = new Pod(fpod); m_podsByName[name] = pod; //new SoftReference(pod); return pod; } }
public static Pod doFind(string name, bool check, FPod fpod) { try { lock (m_podsByName) { // TODO - .NET does not have soft references, so how could // we implement this? See the Pod.java for the java impl. Pod pod = (Pod)m_podsByName[name]; if (pod == null) { // if fpod is non-null, then we are "creating" this pod in // memory direct from the compiler, otherwise we need to // find the pod zip file and load it's meta-data if (fpod == null) fpod = readFPod(name); // sanity check if (fpod.m_podName != name) throw new Exception("Mismatched pod name b/w pod.def and pod zip filename: " + fpod.m_podName + " != " + name); // create the pod and register it pod = new Pod(fpod); m_podsByName[name] = pod; } return pod; } } catch (UnknownPodErr.Val e) { if (!check) return null; throw e; } catch (Exception e) { Err.dumpStack(e); if (!check) return null; throw UnknownPodErr.make(name, e).val; } }
public virtual string locale(Pod pod, string key, string def) { return(locale(pod, key, def, Locale.cur())); }
public virtual Map props(Pod pod, Uri uri, Duration maxAge) { return m_props.get(pod, uri, maxAge); }
public virtual string locale(Pod pod, string key, string def, Locale locale) { object val; Duration maxAge = Duration.m_maxVal; // 1. 'props(pod, `locale/{locale}.props`)' val = props(pod, locale.m_strProps, maxAge).get(key, null); if (val != null) return (string)val; // 2. 'props(pod, `locale/{lang}.props`)' val = props(pod, locale.m_langProps, maxAge).get(key, null); if (val != null) return (string)val; // 3. 'props(pod, `locale/en.props`)' val = props(pod, m_localeEnProps, maxAge).get(key, null); if (val != null) return (string)val; // 4. Fallback to 'pod::key' unless 'def' specified if (def == m_noDef) return pod + "::" + key; return def; }
public virtual string locale(Pod pod, string key, string def) { return locale(pod, key, def, Locale.cur()); }
public virtual string locale(Pod pod, string key) { return locale(pod, key, m_noDef, Locale.cur()); }
public virtual string config(Pod pod, string key, string def) { return (string)m_props.get(pod, m_configProps, Duration.m_oneMin).get(key, def); }
public virtual string config(Pod pod, string key) { return config(pod, key, null); }
public virtual string config(Pod pod, string key, string def) { return((string)m_props.get(pod, m_configProps, Duration.m_oneMin).get(key, def)); }
public virtual string locale(Pod pod, string key) { return(locale(pod, key, m_noDef, Locale.cur())); }
// parameterized type constructor public ClassType(Pod pod, string name, int flags, Facets facets) { this.m_pod = pod; this.m_name = name; this.m_qname = pod.m_name + "::" + name; this.m_nullable = new NullableType(this); this.m_flags = flags; this.m_facets = facets; }
////////////////////////////////////////////////////////////////////////// // Constructor ////////////////////////////////////////////////////////////////////////// internal ClassType(Pod pod, FType ftype) { this.m_pod = pod; this.m_ftype = ftype; this.m_name = pod.fpod.typeRef(ftype.m_self).typeName; this.m_qname = pod.m_name + "::" + m_name; this.m_nullable = new NullableType(this); this.m_flags = ftype.m_flags; if (Debug) Console.WriteLine("-- init: " + m_qname); }
public Key(Pod p, Uri u) { m_pod = p; m_uri = u; }
////////////////////////////////////////////////////////////////////////// // 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()); }
internal UsingPod(Pod p) { pod = p; }