private static string Explode(this string source, Regex pattern, PatternStyle patternStyle, Func <string, string> expansionFactory, TreeNode <string> parent) { var output = source; while (output.HasChildren(pattern)) { foreach (Match match in pattern.Matches(source)) { var child = match.Value; var token = patternStyle.TokenReplaceFilter(match.Value); var thisNode = parent.Children.Add(token); // if we have already encountered this token in this call tree, we have a circular reference if (thisNode.CallTree.Contains(token)) { throw new CircularReferenceException(string.Format("Circular Reference Detected for token '{0}'. Call Tree: {1}->{2}", token, String.Join("->", thisNode.CallTree.ToArray().Reverse()), token)); } // expand this match var expandedValue = expansionFactory(token); // Replace the match with the expanded value child = Regex.Replace(child, patternStyle.OutputFilter(match.Value), expandedValue); // Recursively expand the child until we no longer encounter nested tokens (or hit a circular reference) child = child.Explode(pattern, patternStyle, expansionFactory, thisNode); // finally, replace the match in the output with the fully-expanded value output = Regex.Replace(output, patternStyle.OutputFilter(match.Value), child); } } return(output); }
public static string GetPatternImage(PatternStyle pattern, Color foreColor, Color backgroundColor) { string result = ""; using (MemoryStream ms = new MemoryStream()) using (Bitmap bitmap = new Bitmap(8, 8)) using (Graphics gr = Graphics.FromImage(bitmap)) { gr.Clear(backgroundColor); var patternCoords = m_coords[(int)pattern]; for (int i = 0; i < patternCoords.Length; i += 2) { bitmap.SetPixel(patternCoords[i], patternCoords[i + 1], foreColor); } bitmap.Save(ms, ImageFormat.Png); ms.Position = 0; result = "data:image/png;base64," + Convert.ToBase64String(ms.ToArray()); } return(result); }
public void Reset() { Style = PatternStyle.NoPattern; ForegroundColor = ExcelColor.WindowTextForPattern; BackgroundColor = ExcelColor.WindowBackgroundForPattern; }