private static void processFile(string f, string lang, string title) { IGraphConsole.WriteLine("Processing file: " + f); List <StatisticalGraph> sgList = json_reader.BuildGraphList(f, ops.writeGIF); // was there at least one graph in that file? if (sgList == null || sgList.Count == 0) { log.Info("No valid graph to process here."); } else { foreach (StatisticalGraph sg in sgList) { // Graph cleaning goes first. CleaningManager.CleanGraph(sg); // NLG goes last. if (nlg.Generate(sg)) { log.Error("This file has wounded me deeply. Please fix it."); } } } }
private static void WriteBanner() { Assembly executingAssembly = Assembly.GetExecutingAssembly(); System.Version version = executingAssembly.GetName().Version; IGraphConsole.WriteLine( String.Format("This is iGraph-Lite, Version {0} ({1})", version.ToString(4), System.IO.File.GetLastWriteTime(executingAssembly.Location))); }
public void Help() { IGraphConsole.WriteLine("\nUsage: igl [OPTIONS] Directory"); IGraphConsole.WriteLine("\nOptions:"); opset.WriteOptionDescriptions(Console.Out); IGraphConsole.WriteLine("\nOptions that take values may use an equal" + " sign, a colon"); IGraphConsole.WriteLine("or a space to separate the option from its" + " value."); IGraphConsole.WriteLine("\nIf no directory is specified, the current" + " directory is used."); }
private static void processFile(string file, string lang, string title) { string f = Path.GetFullPath(file); // the full path of "file" IGraphConsole.WriteLine("Processing file: " + f); List <StatisticalGraph> sgList = xl_reader.BuildGraphList(f, ops.writeGIF); // was there at least one graph in that Excel file? if (sgList == null || sgList.Count == 0) { log.Info("No valid graph to process here."); } else { foreach (StatisticalGraph sg in sgList) { if (ops.isCsv) { if (title != null && title.Length > 0) { sg.MainTitle = title; } if (lang != null && lang.Length > 0) { sg.GraphLanguage = lang; } } // Graph cleaning goes first. CleaningManager.CleanGraph(sg); // Writers go second if (ops.writeXML) { log.Debug("Writing graph as XML file."); XMLGraphWriter.write(sg); } // NLG goes last. if (nlg.Generate(sg)) { log.Error("This file has wounded me deeply. Please fix it."); } } } }
private void SaveDescription(string desc) { string graph_name = g.Prologue.GetGraphName(); string filename = output_path + graph_name + ".html"; TextWriter tw = new StreamWriter(filename); if (File.Exists(filename)) { IGraphConsole.WriteLine("Overwritting an HTML description: \"" + filename + "\"."); log.Warn("Overwritting an HTML description: \"" + filename + "\"."); } else { IGraphConsole.WriteLine("Writing HTML description to " + filename); } tw.Write(desc); tw.Close(); }
public static void Execute(IGraphOptions _ops) { json_reader = new JSONGraphReader(); nlg = new LanguageGenerator(); ops = _ops; string dir = ops.DirectoryName; string csvFilename = ops.CsvFilename; string inputFilename = ops.InputFilename; string[] json_files = Directory.GetFiles(dir, "*.json"); nlg.output_path = ops.OutputDir; processFile(inputFilename, null, null); log.Info("Successfully released the Excel handle. This is awesome."); IGraphConsole.WriteLine("Done."); Environment.Exit(IGraphConstants.EXIT_SUCCESS); }
public static void Main(string[] args) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", false); WriteBanner(); IGraphOptions opts = new IGraphOptions(args); #region Logger /// Logging setup. We do not use a configuration file. ColoredConsoleAppender appender = new ColoredConsoleAppender(); appender.Layout = new PatternLayout("[%5level]\t%m\n"); AddColorMapping(appender, Level.Error, ColoredConsoleAppender.Colors.Red | ColoredConsoleAppender.Colors.HighIntensity); AddColorMapping(appender, Level.Warn, ColoredConsoleAppender.Colors.Yellow | ColoredConsoleAppender.Colors.HighIntensity); switch (opts.LogLevel) { case 0: appender.Threshold = Level.Off; break; case 1: appender.Threshold = Level.Fatal; break; case 2: appender.Threshold = Level.Error; break; case 3: appender.Threshold = Level.Warn; break; case 4: appender.Threshold = Level.Info; break; case 5: appender.Threshold = Level.Debug; break; case 6: appender.Threshold = Level.All; break; default: appender.Threshold = Level.Warn; break; } appender.ActivateOptions(); BasicConfigurator.Configure(appender); IGraphConsole.WriteLine("Log level set to: " + appender.Threshold + " (" + opts.LogLevel + ")"); #endregion if (opts.isHelp) { opts.Help(); } else if (!opts.Validate()) { IGraphConsole.WriteError("There are unrecognized options." + "\n\tTry igl -h or igl --help for more information."); opts.Help(); Environment.Exit(IGraphConstants.INVALID_OPTIONS); } else if (opts.isFile && !File.Exists(opts.InputFilename)) { IGraphConsole.WriteError("The specified file was not found." + "\n\tYou said: " + opts.InputFilename); Environment.Exit(IGraphConstants.EXCEL_NOT_FOUND); } else if (opts.isCsv && !File.Exists(opts.CsvFilename)) { IGraphConsole.WriteError("CSV file not found."); Environment.Exit(IGraphConstants.CSV_NOT_FOUND); } else if (!Directory.Exists(opts.DirectoryName)) { IGraphConsole.WriteError("Directory does not exist." + "\n\tYou said: " + opts.DirectoryName + "\n\tRemember to add quotes if directory contains spaces."); Environment.Exit(IGraphConstants.DIR_NOT_FOUND); } else { IGraphLite.Execute(opts); } }
public LanguageGenerator() { IGraphConsole.WriteLine("This is Alpha-Lexis, Version 1.0."); }
public bool Generate(StatisticalGraph graph) { g = graph; error = false; FrenchGenerator fr_t = new FrenchGenerator(); EnglishGenerator en_t = new EnglishGenerator(); #region NVelocity setup VelocityEngine velocity = new VelocityEngine(); ExtendedProperties props = new ExtendedProperties(); velocity.Init(props); //Template template; string strTemplate; // This nested if can be better... if (g.GraphLanguage == null || g.GraphLanguage.Length == 0) { if (g.Prologue.GetLanguageByFilename() != "French") { g.GraphLanguage = IGraphConstants.LANG_ENG; } else { g.GraphLanguage = IGraphConstants.LANG_FRA; } } if (g.GraphLanguage == IGraphConstants.LANG_ENG) { //template = velocity.GetTemplate(@"./English.nv"); byte[] NVtemplate = igl.Properties.Resources.NVenglish; System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); strTemplate = enc.GetString(NVtemplate); } else { //template = velocity.GetTemplate(@"./French.nv"); byte[] NVtemplate = igl.Properties.Resources.NVfrench; System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding(); strTemplate = enc.GetString(NVtemplate); } VelocityContext context = new VelocityContext(); #endregion context.Put("graph", g); context.Put("french", fr_t); context.Put("english", en_t); context.Put("date", DateTime.Now); // run template matching StringWriter writer = new StringWriter(); try { //setting Culture if (g.GraphLanguage == IGraphConstants.LANG_ENG) { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-CA", false); } else { System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("fr-CA", false); } //template.Merge(context, writer); velocity.Evaluate(context, writer, "NVlocity", strTemplate); SaveDescription(writer.GetStringBuilder().ToString()); } catch (Exception e) { log.Error("NVelocity error." + e.Message); IGraphConsole.WriteLine("NVelocity error: " + e); error = true; } //Restoring culture System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US", false); return(error); }
public static void Execute(IGraphOptions _ops) { // Atributes :) xl_reader = new ExcelGraphReader(); nlg = new LanguageGenerator(); ops = _ops; string dir = ops.DirectoryName; string csvFilename = ops.CsvFilename; string inputFilename = ops.InputFilename; if (ops.isFile) { processFile(inputFilename, null, null); } else if (ops.isCsv) { CsvFile[] xl_csvfiles = CsvParse.parse(csvFilename); string path_csvfile = Path.GetDirectoryName(Path.GetFullPath(csvFilename)); if (xl_csvfiles.Length == 0) { IGraphConsole.WriteError("CSV file found, but no Excel files in it." + "\n\tYou said: " + csvFilename); Environment.Exit(IGraphConstants.NO_GRAPH_FILES_IN_CSV); } // All's well so far, process each graph in each file in the dir log.Info(xl_csvfiles.Length + " Excel file(s) in the csv file."); foreach (CsvFile csvfile in xl_csvfiles) { string file = csvfile.Filename; string f = Path.Combine(path_csvfile, file); // full path of "file" if (File.Exists(f)) { processFile(f, csvfile.Language, csvfile.Title); } else { log.Warn("Excel file not found." + "\n\tThe Excel file must be in: " + f); } } } else { // Do Excel files exist in the directory? string[] xl_files = Directory.GetFiles(dir, "*.xls"); if (xl_files.Length == 0) { IGraphConsole.WriteError("Directory found, but no Excel files in it." + "\n\tYou said: " + (dir == "." ? ". (current directory)" : dir)); Environment.Exit(IGraphConstants.NO_GRAPH_FILES_IN_DIR); } log.Info(xl_files.Length + " Excel file(s) in the directory."); // All's well so far, process each graph in each file in the dir foreach (string file in xl_files) { processFile(file, null, null); } } log.Info("Successfully released the Excel handle. This is awesome."); IGraphConsole.WriteLine("Done."); Environment.Exit(IGraphConstants.EXIT_SUCCESS); }