public static string GetStr(string key, Region region) { IGFSerializable cValue = region.Get(key); Console.WriteLine(" Get string -- key: " + key + " value: " + cValue.ToString()); return(cValue.ToString()); }
// Gets the value, if the key exists public static string GetStr(string key) { string testStr = string.Empty; IGFSerializable cValue = m_region.Get(key); // Is the key found? if (cValue != null) { testStr = cValue.ToString(); // Type of value? if (cValue is CacheableBytes) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); CacheableBytes cBytes = cValue as CacheableBytes; foreach (byte b in cBytes.Value) { sb.Append((char)b); } testStr = sb.ToString(); } else if (cValue is CacheableObjectXml) { object val = ((CacheableObjectXml)cValue).Value; System.Xml.XmlDocument xd = val as System.Xml.XmlDocument; if (xd != null) { testStr = xd.OuterXml; } } Console.WriteLine("Get [{0}] -- key: {1}, value: {2}", cValue.GetType().Name, key, testStr); } else { testStr = "NULL"; Console.WriteLine("No such key in region: " + key); } return(testStr); }
private string Process(string expr) { Match match = regex.Match(expr); if (match.Success) { string[] args = StringUtils.DelimitedListToStringArray(expr, " "); string command = args[0]; string arg1 = (args.Length >= 2 ? args[1] : null); string arg2 = (args.Length == 3 ? args[2] : null); if (IsMatch("query", command)) { StringBuilder sb = new StringBuilder(); sb.Append("["); string query = expr.Trim().Substring(command.Length); ISelectResults resultSet = region.Query(query); for (uint i = 0; i < resultSet.Size; i++) { sb.Append(resultSet[i].ToString()); if (i != resultSet.Size - 1) { sb.Append(","); } } sb.Append("]"); return(sb.ToString()); } // parse commands w/o arguments if (IsMatch("exit", command)) { threadActive = false; return("Node exiting..."); } if (IsMatch("help", command)) { return(help); } if (IsMatch("size", command)) { return("" + region.Size); } if (IsMatch("clear", command)) { region.Clear(); return("Clearing grid..."); } if (IsMatch("keys", command)) { StringBuilder sb = new StringBuilder(); sb.Append("["); ICacheableKey[] keys = region.GetKeys(); for (int i = 0; i < keys.Length; i++) { sb.Append(keys[i]); if (i != keys.Length - 1) { sb.Append(","); } } sb.Append("]"); return(sb.ToString()); } if (IsMatch("values", command)) { StringBuilder sb = new StringBuilder(); sb.Append("["); IGFSerializable[] values = region.GetValues(); for (int i = 0; i < values.Length; i++) { sb.Append(values[i]); if (i != values.Length - 1) { sb.Append(","); } } sb.Append("]"); return(sb.ToString()); } if (IsMatch("map", command)) { RegionEntry[] regionEntries = region.GetEntries(false); if (regionEntries.Length == 0) { return("[]"); } StringBuilder sb = new StringBuilder(); foreach (RegionEntry regionEntry in regionEntries) { sb.Append("[").Append(regionEntry.Key.ToString()).Append("=").Append( regionEntry.Value.ToString()).Append("]"); } return(sb.ToString()); } //commands w/ 1 arg if (IsMatch("containsKey", command)) { return("" + region.ContainsKey(arg1)); } if (IsMatch("containsValue", command)) { return("not yet implemented"); //return "" + region.ExistsValue(arg1); } if (IsMatch("get", command)) { IGFSerializable cValue = region.Get(arg1); if (cValue == null) { return("null"); } return(cValue.ToString()); } if (IsMatch("remove", command)) { return("not yet implemented"); } // commands w/ 2 args if (IsMatch("put", command)) { IGFSerializable oldValue = region.Get(arg1); region.Put(arg1, arg2); if (oldValue == null) { return("null"); } return("old value = [" + oldValue.ToString() + "]"); } return("unknown command [" + command + "] - type 'help' for available commands"); } return("unknown command [" + expr + "] - type 'help' for available commands"); }