public OrderedHashtableEnumerator(OrderedHashtable table) { // Make a copy of the dictionary entries currently in the SimpleDictionary object. items = new DictionaryEntry[table.Count]; int i = 0; foreach (object key in table.Keys) { items[i] = new DictionaryEntry(key, table[key]); i++; } System.Array.Sort(items, delegate(DictionaryEntry a, DictionaryEntry b) { int ret = 0; try { ret = (a.Key as System.IComparable).CompareTo(b.Key as System.IComparable); } catch (System.Exception e) { EB.Debug.LogWarning(e); } return(ret); }); }
/** * @param resourceName A path to a resource file provided in the current environment * * @return a dictionary of key/value locale pairs from a file in the resource directory * @throws IOException */ public static OrderedHashtable parseLocaleInput(Stream stream) { // TODO: This might very well fail. Best way to handle? OrderedHashtable locale = new OrderedHashtable(); int chunk = 100; StreamReader isr; isr = new StreamReader(stream); Boolean done = false; char[] cbuf = new char[chunk]; int offset = 0; int curline = 0; String line = ""; while (!done) { int read = isr.Read(cbuf, offset, chunk - offset); if (read == -1) { done = true; if (line != "") { parseAndAdd(locale, line, curline); } break; } String stringchunk = new System.String(cbuf, offset, read); int index = 0; while (index != -1) { int nindex = stringchunk.IndexOf('\n', index); //UTF-8 often doesn't encode with newline, but with CR, so if we //didn't find one, we'll try that if (nindex == -1) { nindex = stringchunk.IndexOf('\r', index); } if (nindex == -1) { line += stringchunk.Substring(index); break; } else { line += stringchunk.Substring(index, nindex); //Newline. process our string and start the next one. curline++; parseAndAdd(locale, line, curline); line = ""; } index = nindex + 1; } } stream.Close(); return(locale); }
public object rewind(ScriptContext context) { this.enumerator = this.storage.GetEnumerator(); this.enumerator.MoveFirst(); this.index = 0; return(null); }
/** * Moves all relevant entries in the source dictionary into the destination dictionary * @param destination A dictionary of key/value locale pairs that will be modified * @param source A dictionary of key/value locale pairs that will be copied into * destination */ private void loadTable(OrderedHashtable destination, OrderedHashtable source) { for (IEnumerator en = source.GetEnumerator(); en.MoveNext();) { String key = (String)en.Current; destination.put(key, (String)source[key]); } }
/** * Get the mappings for a locale, but throw an exception if locale is not defined. * * @param locale Locale * @return Text mappings for locale. * @throws UnregisteredLocaleException If locale is not defined or null. */ public OrderedHashtable getLocaleMap(String locale) { OrderedHashtable mapping = getLocaleData(locale); if (mapping == null) { throw new UnregisteredLocaleException("Attempted to access an undefined locale."); } return(mapping); }
/** * Full constructor. * * @param fallbackDefaultLocale If true, search the default locale when no translation for a particular text handle * is found in the current locale. * @param fallbackDefaultForm If true, search the default text form when no translation is available for the * specified text form ('long', 'short', etc.). Note: form is specified by appending ';[form]' onto the text ID. */ public Localizer(Boolean fallbackDefaultLocale, Boolean fallbackDefaultForm) { localeResources = new OrderedHashtable(); currentLocaleData = new OrderedHashtable(); locales = new ArrayList(); defaultLocale = null; currentLocale = null; observers = new ArrayList(); this.fallbackDefaultLocale = fallbackDefaultLocale; this.fallbackDefaultForm = fallbackDefaultForm; }
public OrderedHashtable GetAllServerData() { OrderedHashtable serverData = new OrderedHashtable(); foreach (BaseDataModel model in _models) { serverData[model.GetId()] = model.GetServerData(); } return(serverData); }
/* === (DE)SERIALIZATION === */ /** * Read the object from stream. */ public void readExternal(System.IO.BinaryReader dis, PrototypeFactory pf) { fallbackDefaultLocale = ExtUtil.readBool(dis); fallbackDefaultForm = ExtUtil.readBool(dis); localeResources = (OrderedHashtable)ExtUtil.read(dis, new ExtWrapMap(typeof(String), new ExtWrapListPoly(), 1), pf);; locales = (ArrayList)ExtUtil.read(dis, new ExtWrapList(typeof(String))); setDefaultLocale((String)ExtUtil.read(dis, new ExtWrapNullable(typeof(String)), pf)); String currentLocale = (String)ExtUtil.read(dis, new ExtWrapNullable(typeof(String)), pf); if (currentLocale != null) { Locale = currentLocale; } }
public object item(int index) { if (index < 0 || index >= map.Count) { return(null); } OrderedHashtable <MapKey> .Enumerator enumerator = map.GetEnumerator(); for (int i = 0; i <= index; i++) { enumerator.MoveNext(); } return(enumerator.Current.Value); }
public virtual OrderedHashtable GetServerData() { OrderedHashtable serverData = new OrderedHashtable(); foreach (FieldInfo field in GetType().GetFields()) { if (field.GetCustomAttributes(typeof(ServerDataAttribute), true).Length > 0) { var value = field.GetValue(this); //if (field.FieldType == typeof(GenericFormulaValueModel)) //{ // value = (value as GenericFormulaValueModel).ToString(); //} serverData[field.Name] = value; } } return(serverData); }
private void parseAndAdd(OrderedHashtable locale, String line, int curline) { //trim whitespace. line = line.Trim(); //clear comments while (line.IndexOf("#") != -1) { line = line.Substring(0, line.IndexOf("#")); } if (line.IndexOf('=') == -1) { // TODO: Invalid line. Empty lines are fine, especially with comments, // but it might be hard to get all of those. if (line.Trim().Equals("")) { //Empty Line } else { Console.WriteLine("Invalid line (#" + curline + ") read: " + line); } } else { //Check to see if there's anything after the '=' first. Otherwise there //might be some big problems. if (line.IndexOf('=') != line.Length - 1) { String value = line.Substring(line.IndexOf('=') + 1, line.Length); locale.put(line.Substring(0, line.IndexOf('=')), value); } else { Console.WriteLine("Invalid line (#" + curline + ") read: '" + line + "'. No value follows the '='."); } } }
public DOMNamedNodeMap() : base(ScriptContext.CurrentContext, true) { map = new OrderedHashtable <MapKey>(); }
/** * Get the set of mappings for a locale. * * @param locale Locale * @returns Hashtable representing text mappings for this locale. Returns null if locale not defined or null. */ public OrderedHashtable getLocaleData(String locale) { if (locale == null || !this.locales.Contains(locale)) { return(null); } //It's very important that any default locale contain the appropriate strings to localize the interface //for any possible language. As such, we'll keep around a table with only the default locale keys to //ensure that there are no localizations which are only present in another locale, which causes ugly //and difficult to trace errors. OrderedHashtable defaultLocaleKeys = new OrderedHashtable(); //This table will be loaded with the default values first (when applicable), and then with any //language specific translations overwriting the existing values. OrderedHashtable data = new OrderedHashtable(); // If there's a default locale, we load all of its elements into memory first, then allow // the current locale to overwrite any differences between the two. if (fallbackDefaultLocale && defaultLocale != null) { ArrayList defaultResources = (ArrayList)localeResources[defaultLocale]; for (int i = 0; i < defaultResources.Count; ++i) { loadTable(data, ((LocaleDataSource)defaultResources[i]).getLocalizedText()); } for (IEnumerator en = data.GetEnumerator(); en.MoveNext();) { defaultLocaleKeys.put(en.Current, Boolean.TrueString); } } ArrayList resources = (ArrayList)localeResources[locale]; for (int i = 0; i < resources.Count; ++i) { loadTable(data, ((LocaleDataSource)resources[i]).getLocalizedText()); } //If we're using a default locale, now we want to make sure that it has all of the keys //that the locale we want to use does. Otherwise, the app will crash when we switch to //a locale that doesn't contain the key. if (fallbackDefaultLocale && defaultLocale != null) { String missingKeys = ""; int keysmissing = 0; for (IEnumerator en = data.GetEnumerator(); en.MoveNext();) { String key = (String)en.Current; if (!defaultLocaleKeys.ContainsKey(key)) { missingKeys += key + ","; keysmissing++; } } if (keysmissing > 0) { //Is there a good way to localize these exceptions? throw new NoLocalizedTextException("Error loading locale " + locale + ". There were " + keysmissing + " keys which were contained in this locale, but were not " + "properly registered in the default Locale. Any keys which are added to a locale should always " + "be added to the default locale to ensure appropriate functioning.\n" + "The missing translations were for the keys: " + missingKeys, missingKeys, defaultLocale); } } return(data); }
public override OrderedHashtable GetServerData() { OrderedHashtable serverData = base.GetServerData(); return(serverData); }
public void readExternal(System.IO.BinaryReader in_Renamed, PrototypeFactory pf) { localeData = (OrderedHashtable)ExtUtil.read(in_Renamed, new ExtWrapMap(typeof(String), typeof(String), 1), pf); }
public TableLocaleSource(OrderedHashtable localeData) { this.localeData = localeData; }
private OrderedHashtable localeData; /*{ String -> String } */ public TableLocaleSource() { localeData = new OrderedHashtable(); }
public object rewind(ScriptContext context) { this.enumerator = this.storage.GetEnumerator(); this.enumerator.MoveFirst(); this.index = 0; return null; }
/** * @param resourceName A path to a resource file provided in the current environment * * @return a dictionary of key/value locale pairs from a file in the resource directory */ private OrderedHashtable loadLocaleResource(String resourceName) { System.IO.Stream is_Renamed = typeof(Type).Assembly.GetManifestResourceStream(resourceName); // TODO: This might very well fail. Best way to handle? OrderedHashtable locale = new OrderedHashtable(); int chunk = 100; BinaryReader isr; try { isr = new BinaryReader(is_Renamed); } catch (Exception e) { throw new SystemException("Failed to load locale resource " + resourceName + ". Is it in the dll?"); } Boolean done = false; char[] cbuf = new char[chunk]; int offset = 0; int curline = 0; try { String line = ""; while (!done) { int read = isr.Read(cbuf, offset, chunk - offset); if (read == -1) { done = true; if (line != "") { parseAndAdd(locale, line, curline); } break; } String stringchunk = new String(cbuf, offset, read); int index = 0; while (index != -1) { int nindex = stringchunk.IndexOf('\n', index); //UTF-8 often doesn't encode with newline, but with CR, so if we //didn't find one, we'll try that if (nindex == -1) { nindex = stringchunk.IndexOf('\r', index); } if (nindex == -1) { line += stringchunk.Substring(index); break; } else { line += stringchunk.Substring(index, nindex); //Newline. process our string and start the next one. curline++; parseAndAdd(locale, line, curline); line = ""; } index = nindex + 1; } } } catch (IOException e) { // TODO Auto-generated catch block Console.WriteLine(e.StackTrace); } finally { try { is_Renamed.Close(); } catch (IOException e) { Console.Out.WriteLine("Binary Reader for resource file " + resourceURI + " failed to close. This will eat up your memory! Fix Problem! [" + e.Message + "]"); Console.WriteLine(e.StackTrace); } } return(locale); }
/** * Constructs a body of local resources to be the set of Current Locale Data. * * After loading, the current locale data will contain definitions for each * entry defined by the current locale resources, as well as definitions for any * entry present in the fallback resources but not in those of the current locale. * * The procedure to accomplish this set is as follows, with overwritting occuring * when a collision occurs: * * 1. Load all of the in memory definitions for the default locale if fallback is enabled * 2. For each resource file for the default locale, load each definition if fallback is enabled * 3. Load all of the in memory definitions for the current locale * 4. For each resource file for the current locale, load each definition */ private void loadCurrentLocaleResources() { this.currentLocaleData = getLocaleData(currentLocale); }
public DOMNamedNodeMap(ScriptContext context, bool newInstance) : base(context, newInstance) { map = new OrderedHashtable<MapKey>(); }