// ---------------------------------------------------------------------------------------- /// <!-- FormatEndemeLeaf --> /// <summary> /// /// </summary> /// <param name="e"></param> /// <param name="num"></param> /// <param name="width"></param> /// <returns></returns> private static string FormatEndemeLeaf(Endeme e, int num, int width) { char[] alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".ToCharArray(); char[] c = e.ToCharArray(); string str = ""; if (num < c.Length) { str = " " + c[num] + " |" + " " + e.Index(alphabet[num]).ToString().PadLeft(2, ' ') + " " + e.EnSet.Characteristic[alphabet[num]].Display; } return(SetLength(width, str)); }
// ---------------------------------------------------------------------------------------- /// <!-- SelectionBag --> /// <summary> /// Places a bunch of marbles (chars) in a bag for random selection /// </summary> /// <param name="size">number of marbles in bag (try a multiple of 8 <= 120)</param> /// <returns></returns> private List <char> SelectionBag(Endeme e, int size) { Random r = RandomSource.New().Random; if (this.Count > this.OriginalCount) { throw new Exception("SelectionBag"); } // ---------------------------------------------------------------- // Define number of each kind of marble (character) // ---------------------------------------------------------------- char[] endeme = e.ToCharArray(); string str = ""; switch (size) { case 128: str = "@>=;:98765544332221111"; break; case 120: str = "@><;987665443322221111"; break; case 112: str = "?=;:987654433322211111"; break; case 104: str = "><:9876654433222211111"; break; case 96: str = "=;:9776544333222111110"; break; case 88: str = "<:98765544332221111110"; break; case 80: str = ";987665443322221111110"; break; case 72: str = ":877654433322211111100"; break; case 64: str = "9876544333222111111000"; break; case 60: str = "8766544332222111111000"; break; case 56: str = "8765543332221111110000"; break; case 52: str = "7665443322221111110000"; break; case 48: str = "7655433322211111100000"; break; case 44: str = "6554433222211111100000"; break; case 40: str = "6544333222111111000000"; break; case 36: str = "5544332221111110000000"; break; case 32: str = "5433322221111110000000"; break; case 28: str = "4433222211111100000000"; break; case 24: str = "4332222111111000000000"; break; case 20: str = "3322221111110000000000"; break; case 16: str = "3222111111100000000000"; break; case 14: str = "2222111111000000000000"; break; case 12: str = "2221111110000000000000"; break; case 10: str = "2211111100000000000000"; break; case 8: str = "2111111000000000000000"; break; case 7: str = "2111110000000000000000"; break; case 6: str = "1111110000000000000000"; break; case 5: str = "1111100000000000000000"; break; case 4: str = "1111000000000000000000"; break; case 3: str = "1110000000000000000000"; break; case 2: str = "1100000000000000000000"; break; case 1: str = "1000000000000000000000"; break; default: str = ""; Dictionary <char, int> cha = new Dictionary <char, int>(22); foreach (char c in endeme) { cha.Add(c, 0); } for (int i = 0; i < size; ++i) { cha[e.RandomLetter(0.89)]++; } var query = from ch in cha orderby cha.Values descending select cha; str = ""; foreach (var item in query) { str = str + item.ToString(); } break; // TODO: build the function that approximates these series (.89 * one before) } // ---------------------------------------------------------------- // Put marbles (characters) in bag // ---------------------------------------------------------------- List <int> quantity = StringToNums(str); List <char> bag = new List <char>(size); for (int i = 0; i < quantity.Count; ++i) { for (int j = 0; j < quantity[i]; ++j) { if (i < endeme.Length) { bag.Add(endeme[i]); } else if (endeme.Length > 0) { bag.Add(endeme[0]); } } } return(bag); }
// ---------------------------------------------------------------------------------------- /// <!-- A --> /// <summary> /// Provides a breakpoint in development and throws an exception in production /// </summary> /// <param name="e">exception</param> /// <param name="actions">bug action</param> /// <returns>The id in the database if sent to the database</returns> public static Guid A(Exception ex, Endeme actions, EventSourceCreationData eventSource , GuiActionTrace gat) { if (_exceptionAct == null) { FillExceptionAct(); } // -------------------------------------------------------------------------- // Handle missing exception actions with a default Squawk-Log-Pause // -------------------------------------------------------------------------- if (_actions == null) { _actions = "" + Squawk + EventLog + Pauses; } if (actions == null) { actions = _actions; } // -------------------------------------------------------------------------- // Handle missing event log operational data by complaining // -------------------------------------------------------------------------- if (eventSource == null) { throw new NoNullAllowedException("EventSourceCreationData is null!" + "\r\n" + " You may have to add code something like this before running Throw:" + "\r\n" + " Throw.EventSourceBuild(\"MyProj\", \"MyProLog\");" ); } Guid guid = Guid.Empty; string strGat = ""; // -------------------------------------------------------------------------- // Prepare message text // -------------------------------------------------------------------------- string msg = ""; if (ex.InnerException != null) { msg = ex.InnerException.GetType().ToString() + "\r\n" + ex.InnerException.Message + "\r\n" + "\r\n" + ex.Message; } else { msg = ex.GetType().ToString() + " - " + ex.Message; } // -------------------------------------------------------------------------- // Determine action level // -------------------------------------------------------------------------- //int idx = actions.ToString().IndexOf('L'); //if (idx < 0) idx = 11; //int actionLevel; //if (idx >= 0) actionLevel = 22 - idx; //else actionLevel = 20; // default action level, action level is a callable/programmable cutoff point //// N is a mandatory cutoff point // -------------------------------------------------------------------------- // This is how to do it with an endeme // -------------------------------------------------------------------------- if (msg != _lastMessage && // don't keep spewing out the same messages msg != _prevMessage && !Regex.IsMatch(msg, "Deadlock victim", RegexOptions.IgnoreCase)) // I don't want to hear about deadlock victims { char[] act = actions.ToCharArray(); bool run = true; for (int i = 0; run && i < act.Length; ++i) { switch (act[i]) { //case DataLog: guid = SendToDatabase("CodeWhite", msg, strGat); break; case EventLog: SendToActionLog(msg, eventSource, strGat); break; case Ignore: break; case Email: break; case None: run = false; break; case Pauses: Pause(); break; // set a breakpoint here case Squawk: MessageBox.Show(msg); break; case Throws: throw ex; // turn this on in production and make sure it's handled } } } _prevMessage = _lastMessage; _lastMessage = msg; return(guid); }