private static int Handle(Arguments a) { int exitCode = 0; string cwd = System.IO.Directory.GetCurrentDirectory(); IEnumerable <string> paths = Input.MatchFiles( cwd, new List <string>(a.Inputs), new List <string>(a.Excludes ?? new string[0])); var ignoreLinesMatching = new List <Regex>(a.IgnoreLinesMatching?.Length ?? 0); foreach (var pattern in a.IgnoreLinesMatching ?? new string[] { }) { try { var regex = new Regex(pattern); ignoreLinesMatching.Add(regex); } catch (System.Exception ex) { Console.Error.WriteLine($"Failed to parse the regular expression {pattern}: {ex}"); } } bool success = true; foreach (string path in paths) { using StreamReader sr = File.OpenText(path); var record = Inspection.InspectLines(sr, a.MaxLineLength, ignoreLinesMatching); bool isOk = Output.Report(path, record, a.MaxLineLength, a.MaxLinesInFile, a.Verbose, Console.Out); success = success & isOk; } if (!success) { if (ignoreLinesMatching.Count > 0) { Console.Out.WriteLine( $"The --ignore-lines-matching was set to: " + string.Join(" ", ignoreLinesMatching.Select(i => i.ToString()))); } Console.Error.WriteLine("One or more input files failed the checks."); exitCode = 1; } return(exitCode); }
/// <summary> /// Returns the HTML email template with values replaced /// </summary> /// <param name="to"></param> /// <param name="content"></param> /// <returns></returns> public string EmailTemplate(string to, string content) { using (var sr = File.OpenText(HttpContext.Current.Server.MapPath(@"~/App_Plugins/Dialogue/EmailTemplates/EmailNotification.htm"))) { var sb = sr.ReadToEnd(); sr.Close(); sb = sb.Replace("#CONTENT#", content); sb = sb.Replace("#SITENAME#", Dialogue.Settings().ForumName); sb = sb.Replace("#SITEURL#", AppHelpers.ReturnCurrentDomain()); if (!string.IsNullOrEmpty(to)) { to = $"<p>{to},</p>"; sb = sb.Replace("#TO#", to); } return(sb); } }
static FoodTrucksController() { var path = HostingEnvironment.MapPath("~/mock_data.json"); using (var stream = IOFile.OpenText(path)) using (var reader = new JsonTextReader(stream)) { var data = JsonSerializer.Create().Deserialize <MockData>(reader); FoodTrucks = data.Trucks; FoodTruckMenuItems = data.MenuItems .GroupBy(m => m.FoodTruckId) .ToDictionary(g => g.Key, g => g.ToList()); FoodTruckSchedules = data.Schedules .GroupBy(s => s.FoodTruckId) .ToDictionary(g => g.Key, g => g.ToList()); } }