/// <summary> /// Append log information to log writer. /// </summary> /// <param name="logger">Log writer object.</param> /// <param name="newLine">Flag of whether add a new line.</param> /// <param name="format">Format of the output.</param> /// <param name="list">Argument list of the output.</param> private static void TraceLog(TextLogger logger, bool newLine, string format, params object[] list) { if (logger != null) { if (newLine) { logger.LogLine(format, list); } else { logger.Log(format, list); } } }
/// <summary> /// Traverse script file. /// </summary> /// <param name="visitor">Script item processor interface.</param> /// <param name="importDataPathList">File list for importing data model.</param> /// <param name="inScriptFile">Input script file.</param> /// <param name="outScriptFile">Output script file.</param> /// <param name="logger">Text logger.</param> /// <param name="parameters">Parameters.</param> public static void TraverseScriptFile(IScriptItemProcessor visitor, Dictionary<string, string> importDataPathList, string inScriptFile, string outScriptFile, TextLogger logger, object parameters) { if (string.IsNullOrEmpty(inScriptFile)) { throw new ArgumentNullException("inScriptFile"); } if (!File.Exists(inScriptFile)) { throw new FileNotFoundException(inScriptFile); } XmlScriptFile script = new XmlScriptFile(); string message = Helper.NeutralFormat("Processing file : {0}", inScriptFile); Console.WriteLine(message); string fileName = Path.GetFileName(inScriptFile); try { script.Load(inScriptFile); List<string> listDiscard = new List<string>(); foreach (ScriptItem scriptItem in script.Items) { try { // When the mode is "Import F0/Power/Segment", the importDataPathList will not be null. if (importDataPathList == null || importDataPathList.ContainsKey(scriptItem.Id)) { visitor.ProcessItem(scriptItem, parameters); } else { listDiscard.Add(scriptItem.Id); } } catch (InvalidDataException exception) { if (logger != null) { logger.LogLine("ERROR : [File {0}][Item {1}]{2}", fileName, scriptItem.Id, exception.Message); } } } foreach (string id in listDiscard) { script.Remove(id); } if (!string.IsNullOrEmpty(outScriptFile)) { Helper.TestWritable(outScriptFile); script.Save(outScriptFile, Encoding.Unicode); } } catch (InvalidDataException exception) { if (logger != null) { logger.LogLine("ERROR : [File {0}]{1}", fileName, exception.Message); } } }
/// <summary> /// Add line in log writer. /// </summary> /// <param name="logger">Log writer object.</param> private static void TraceLogLine(TextLogger logger) { if (logger != null) { logger.LogLine(); } }