public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { if (e.Name.Equals("ipconfig", StringComparison.OrdinalIgnoreCase)) { e.Value = IpConfig(); } else if (e.Name.Equals("ips", StringComparison.OrdinalIgnoreCase)) { e.Value = string.Join("\r\n", Regex.Matches(IpConfig(), @"(?<name>Carte.*?)$(\s*(?!Carte)(^(\s*(?<ipv4>A.*IPv4.*\s(?<ip>(\d+\.){3}\d+).*)|.*)$))+", RegexOptions.Multiline | RegexOptions.IgnoreCase) .Cast <Match>() .Where(match => match.Groups["ip"].Success) .Select(match => match.Groups["name"].Value.Trim() + "\r\n" + match.Groups["ip"].Value)); } else if (e.Name.Equals("jips", StringComparison.OrdinalIgnoreCase)) { e.Value = string.Join("\r\n", Regex.Matches(IpConfig(), @"(?<name>Carte.*?)$(\s*(?!Carte)(^(\s*(?<ipv4>A.*IPv4.*\s(?<ip>(\d+\.){3}\d+).*)|.*)$))+", RegexOptions.Multiline | RegexOptions.IgnoreCase) .Cast <Match>() .Where(match => match.Groups["ip"].Success) .Select(match => match.Groups["ip"].Value)); } else if (e.Name.StartsWith("ip_", StringComparison.OrdinalIgnoreCase)) { string find = Regex.Replace(e.Name.Substring(3), ".", "(.*?)$&"); e.Value = string.Join("\r\n", Regex.Matches(IpConfig(), @"(?<name>Carte\s+find.*?)$(\s*(?!Carte)(^(\s*(?<ipv4>A.*IPv4.*\s(?<ip>(\d+\.){3}\d+).*)|.*)$))+".Replace("find", find), RegexOptions.Multiline | RegexOptions.IgnoreCase) .Cast <Match>() .Where(match => match.Groups["ip"].Success) .Select(match => match.Groups["name"].Value.Trim() + "\r\n" + match.Groups["ip"].Value)); } else if (e.Name.StartsWith("jip_", StringComparison.OrdinalIgnoreCase)) { string find = Regex.Replace(e.Name.Substring(4), ".", "(.*?)$&"); e.Value = string.Join("\r\n", Regex.Matches(IpConfig(), @"(?<name>Carte\s+find.*?)$(\s*(?!Carte)(^(\s*(?<ipv4>A.*IPv4.*\s(?<ip>(\d+\.){3}\d+).*)|.*)$))+".Replace("find", find), RegexOptions.Multiline | RegexOptions.IgnoreCase) .Cast <Match>() .Where(match => match.Groups["ip"].Success) .Select(match => match.Groups["ip"].Value)); } else if (e.Name.StartsWith("aip_", StringComparison.OrdinalIgnoreCase)) { string find = Regex.Replace(e.Name.Substring(4), ".", "(.*?)$&"); e.Value = string.Join("\r\n", Regex.Matches(IpConfig(), @"(?<name>Carte\s+find.*?)$(\s*(?!Carte)(^(\s*(?<ipv4>A.*IPv4.*\s(?<ip>(\d+\.){3}\d+).*)|.*)$))+".Replace("find", find), RegexOptions.Multiline | RegexOptions.IgnoreCase) .Cast <Match>() .Where(match => match.Groups["ip"].Success) .Select(match => match.Value)); } return(e.HasValue); }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { if (e.Name.Equals("clipboard", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("cb", StringComparison.OrdinalIgnoreCase)) { if (e.This != null) { if (e.This is Bitmap bitmap) { Clipboard.SetDataObject(bitmap); } else { Clipboard.SetText(e.This?.ToString() ?? string.Empty); } e.Value = e.This; } else { e.Value = Clipboard.ContainsImage() ? Clipboard.GetImage().GetBitmap() : (object)Clipboard.GetText(); } } return(e.HasValue); }
private void Evaluator_EvaluateVariable(object sender, VariableEvaluationEventArg e) { if (e.This != null && e.Name.Equals("Json")) { e.Value = JsonConvert.SerializeObject(e.This); } }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { Match loremIspumVariableEvalMatch = loremIspumVariableEvalRegex.Match(e.Name); if (loremIspumVariableEvalMatch.Success) { LoremIpsum li = new LoremIpsum(); if (loremIspumVariableEvalMatch.Groups["language"].Success) { li.CurrentLanguage = loremIspumVariableEvalMatch.Groups["language"].Value.ToLower(); } int wordPerLine = loremIspumVariableEvalMatch.Groups["wordsPerLine"].Success ? int.Parse(loremIspumVariableEvalMatch.Groups["wordsPerLine"].Value, CultureInfo.InvariantCulture) : 10; if (loremIspumVariableEvalMatch.Groups["words"].Success) { e.Value = li.GetWords(int.Parse(loremIspumVariableEvalMatch.Groups["words"].Value, CultureInfo.InvariantCulture), wordPerLine); } else { e.Value = loremIspumVariableEvalMatch.Groups["lines"].Success ? li.GetLines(int.Parse(loremIspumVariableEvalMatch.Groups["lines"].Value, CultureInfo.InvariantCulture), wordPerLine) : li.GetWords(100, wordPerLine); } return(true); } else { return(false); } }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { if (e.Name.Equals("test")) { e.Value = DateTime.Now.ToString("dd.MM.yyyy"); return(true); } if (e.This is DBResultViewModel dBResultViewModel) { Match csvMatch; Match excelMatch; if (valuePropRegex.IsMatch(e.Name)) { if (dBResultViewModel.Results.Count == 1 && dBResultViewModel.Results[0] is IDictionary <string, object> dict) { if (dict.Count == 1) { e.Value = dict[dict.Keys.First()]; } else { e.Value = dBResultViewModel.Results[0]; } } else { e.Value = dBResultViewModel.Results; } } else if ((csvMatch = csvRegex.Match(e.Name)).Success) { StringBuilder stringBuilder = new StringBuilder(); if (!csvMatch.Groups["noheader"].Success) { stringBuilder.AppendLine(string.Join(";", dBResultViewModel.ColumnsNames.Select(n => "\"" + n + "\""))); } foreach (IDictionary <string, object> result in dBResultViewModel.Results) { stringBuilder.AppendLine(string.Join(";", dBResultViewModel.ColumnsNames.Select(n => result[n].ToString().Replace("\"", "\"\"")))); } e.Value = stringBuilder.ToString(); } else if ((excelMatch = excelRegex.Match(e.Name)).Success) { e.Value = CreateExcel(dBResultViewModel, excelMatch); } } return(e.HasValue); }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { Match excelSheetVariableMatch; Match toExcelMatch; Match excelMatch; if (e.This is ExcelPackage pack4Book) { if (e.Name.Equals("book", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("b", StringComparison.OrdinalIgnoreCase)) { e.Value = pack4Book.Workbook; } else if (e.Name.Equals("saveandopen", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("saveopen", StringComparison.OrdinalIgnoreCase)) { if (pack4Book.File == null) { pack4Book.File = new FileInfo(Config.Instance.ExcelDefaultFileName); } if (pack4Book.Workbook.Worksheets.Count == 0) { pack4Book.Workbook.Worksheets.Add(string.Format(Config.Instance.ExcelDefaultSheetName, 1)); } pack4Book.Save(); Process.Start(pack4Book.File.FullName); e.Value = pack4Book; } } else if ((excelMatch = baseExcelRegex.Match(e.Name)).Success && e.This == null) { var fileName = Config.Instance.ExcelDefaultFileName; if (excelMatch.Groups["new"].Success) { File.Delete(fileName); } e.Value = new ExcelPackage(new FileInfo(fileName)); } else if ((excelSheetVariableMatch = excelSheetVariableRegex.Match(e.Name)).Success && (e.This is ExcelPackage || e.This is ExcelWorkbook)) { ExcelWorkbook excelWorkbook = (e.This as ExcelWorkbook) ?? (e.This as ExcelPackage)?.Workbook; e.Value = excelSheetVariableMatch.Groups["index"].Success ? excelWorkbook.Worksheets[int.Parse(excelSheetVariableMatch.Groups["index"].Value)] : (object)excelWorkbook.Worksheets; } else if (e.This is IEnumerable rowEnumerable && (toExcelMatch = toExcelRegex.Match(e.Name)).Success) { e.Value = IEnumerableToExcel(rowEnumerable, toExcelMatch); } return(e.HasValue); }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { if ((e.Name.Equals("sections", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("sec", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("s", StringComparison.OrdinalIgnoreCase)) && e.This is IniFile inifile1) { e.Value = inifile1.SectionsNames; } return(e.HasValue); }
private static void EvaluateVariable(object sender, VariableEvaluationEventArg e) { if (e.This is JObject jObj) { e.Value = jObj[e.Name]; } else if (e.This is CoreBase.Globals.NTVDict p) { e.Value = p.TryGetMember(e.Name); } }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { Match tabVarMatch = tabVarRegex.Match(e.Name); if (tabVarMatch.Success && (tabVarMatch.Groups["pos"].Success || tabVarMatch.Groups["fileName"].Success)) { string currentTab = BNpp.NotepadPP.CurrentFileName; if (tabVarMatch.Groups["all"].Success) { List <string> texts = new List <string>(); BNpp.NotepadPP.GetAllOpenedDocuments.ForEach(tabName => { if (tabVarMatch.Groups["fileName"].Success) { texts.Add(tabName); } else { BNpp.NotepadPP.ShowTab(tabName); texts.Add(BNpp.Text); } }); BNpp.NotepadPP.ShowTab(currentTab); e.Value = texts; } else if (tabVarMatch.Groups["count"].Success) { e.Value = BNpp.NotepadPP.TabCount; } else if (tabVarMatch.Groups["fileName"].Success) { e.Value = tabVarMatch.Groups["tabIndex"].Success ? BNpp.NotepadPP.GetAllOpenedDocuments[int.Parse(tabVarMatch.Groups["tabIndex"].Value)] : currentTab; } else if (tabVarMatch.Groups["tabIndex"].Success) { BNpp.NotepadPP.ShowTab(int.Parse(tabVarMatch.Groups["tabIndex"].Value)); string text = BNpp.Text; BNpp.NotepadPP.ShowTab(currentTab); string doNothingWithItText = BNpp.Text; e.Value = text; } return(true); } return(false); }
private static void ExpressionEvaluator_EvaluateVariable(object sender, VariableEvaluationEventArg e) { Creature player = GetPlayer(e.Evaluator.Variables); CastedSpell castedSpell = GetCastedSpell(e.Evaluator.Variables); DndVariable variable = variables.FirstOrDefault(x => x.Handles(e.Name, player, castedSpell)); if (variable != null) { e.Value = variable.GetValue(e.Name, e.Evaluator, player); Log($" {e.Name} == {e.Value}"); } }
public static void Evaluator_EvaluateVariable(object sender, VariableEvaluationEventArg e) { if (e.Name.Equals("hw", StringComparison.OrdinalIgnoreCase) && e.This == null) { e.Value = "!!! Hello World !!!"; } else if (e.Name.Equals("random") || e.Name.Equals("rand", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("rnd", StringComparison.OrdinalIgnoreCase)) { e.Value = random; } else if ((e.Name.Equals("hex", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("hex_d", StringComparison.OrdinalIgnoreCase)) && e.This is int intHexValue) { e.Value = (e.Name.EndsWith("d", StringComparison.OrdinalIgnoreCase) ? string.Empty : "0x") + intHexValue.ToString("X"); } else if ((e.Name.Equals("hex", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("hex_d", StringComparison.OrdinalIgnoreCase)) && e.This is double doubleHexValue) { e.Value = (e.Name.EndsWith("d", StringComparison.OrdinalIgnoreCase) ? string.Empty : "0x") + ((int)doubleHexValue).ToString("X"); } else if ((e.Name.Equals("bin", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("bin_d", StringComparison.OrdinalIgnoreCase)) && e.This is int intBinValue) { e.Value = (e.Name.EndsWith("d", StringComparison.OrdinalIgnoreCase) ? string.Empty : "0b") + Convert.ToString(intBinValue, 2); } else if ((e.Name.Equals("bin", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("bin_d", StringComparison.OrdinalIgnoreCase)) && e.This is double doubleBinValue) { e.Value = (e.Name.EndsWith("d", StringComparison.OrdinalIgnoreCase) ? string.Empty : "0b") + Convert.ToString((int)doubleBinValue, 2); } else if (e.Name.Equals("guid")) { e.Value = Guid.NewGuid().ToString(); } else if (e.Name.Equals("text", StringComparison.OrdinalIgnoreCase) && e.This == null) { e.Value = BNpp.Text; } else if (e.Name.Equals("selectedtext", StringComparison.OrdinalIgnoreCase) && e.This == null) { e.Value = BNpp.SelectedText; } else if (e.Name.Equals("props", StringComparison.OrdinalIgnoreCase) && e.This != null) { ShowPropertiesViewModel.Instance.ShowPropertiesWindow(e.This); e.Value = e.This; } else if (new string[] { "getcurrentlanguage", "currentlanguage", "currentlang", "curlang", "clang", "cl" }.Contains(e.Name.ToLower())) { e.Value = BNpp.NotepadPP.GetCurrentLanguage(); } else if (e.This is LangType langType && e.Name.Equals("name", StringComparison.OrdinalIgnoreCase)) { e.Value = NPTCommands.Languages.Find(c => c.ResultOrInfoSup is LangType tmplangType && tmplangType == langType)?.Name ?? "No Name"; }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { if (e.Name.Equals("html", StringComparison.OrdinalIgnoreCase)) { HtmlDocument htmlDocument = new HtmlDocument(); if (e.This is string sHTML) { htmlDocument.LoadHtml(sHTML); } e.Value = htmlDocument.DocumentNode; } return(e.HasValue); }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { if (convertToImageFactoryRegex.IsMatch(e.Name) && e.This is Image image) { e.Value = new ImageFactory().Load(image); } else if (convertToBitmapRegex.IsMatch(e.Name) && e.This is ImageFactory factory) { using MemoryStream ms = new MemoryStream(); factory.Save(ms); e.Value = new Bitmap(ms); } return(e.HasValue); }
private void Evaluator_EvaluateVariable(object sender, VariableEvaluationEventArg e) { if (e.This != null) { if (e.Name.Equals("Json")) { e.Value = JsonConvert.SerializeObject(e.This); } else if (e.Name.Equals("MethodsNames")) { e.Value = JsonConvert.SerializeObject(e.This.GetType().GetMethods().Select(m => m.Name)); } else if (e.Name.Equals("PropertiesNames")) { e.Value = JsonConvert.SerializeObject(e.This.GetType().GetProperties().Select(m => m.Name)); } } }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { if ((e.Name.Equals("stringjoin", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("sjoin", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("sj", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("j", StringComparison.OrdinalIgnoreCase)) && e.This is IEnumerable enumerableForJoin) { e.Value = string.Join("", enumerableForJoin.Cast <object>()); return(true); } if ((e.Name.Equals("linejoin", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("ljoin", StringComparison.OrdinalIgnoreCase) || e.Name.Equals("lj", StringComparison.OrdinalIgnoreCase)) && e.This is IEnumerable enumerableForLJoin) { e.Value = string.Join(BNpp.CurrentEOL, enumerableForLJoin.Cast <object>()); return(true); } else { return(false); } }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { if (e.Name.Equals("json", System.StringComparison.OrdinalIgnoreCase) && e.This != null) { e.Value = JsonConvert.SerializeObject(e.This); } if (e.Name.Equals("jsoni", System.StringComparison.OrdinalIgnoreCase) && e.This != null) { e.Value = JsonConvert.SerializeObject(e.This, Formatting.Indented); } else if ((e.Name.Equals("ujson", System.StringComparison.OrdinalIgnoreCase) || e.Name.Equals("unjson", System.StringComparison.OrdinalIgnoreCase) || e.Name.Equals("dejson", System.StringComparison.OrdinalIgnoreCase) || e.Name.Equals("djson", System.StringComparison.OrdinalIgnoreCase)) && e.This is string) { e.Value = JsonConvert.DeserializeObject(e.This.ToString()); } return(e.HasValue); }
public bool TryEvaluate(object sender, VariableEvaluationEventArg e) { Match plotMatch = plotRegex.Match(e.Name); if (plotMatch.Success) { e.Value = GetChart(plotMatch, e.This); } else if (plotListKeywords.Any(name => e.Name.Equals(name, StringComparison.OrdinalIgnoreCase))) { e.Value = string.Join("\r\n", Enum.GetNames(typeof(SeriesChartType))); } else if (toPicKeywords.Any(name => e.Name.Equals(name, StringComparison.OrdinalIgnoreCase)) && e.This is Chart chart) { using MemoryStream ms = new MemoryStream(); chart.SaveImage(ms, ChartImageFormat.Png); e.Value = new Bitmap(ms); } return(e.HasValue); }