private void TryEncodeFixAndLoad(string fb2FileName, int itteration) { string fb2EncodedFile = fb2FileName; if (fb2Encoding != Encoding.UTF8) { fb2EncodedFile = EncodeFB2File(fb2FileName); fb2Encoding = Encoding.UTF8; } try { BatchFilesProcessor fb2Fix = new BatchFilesProcessor(); fb2Fix.Process(fb2EncodedFile); itteration++; LoadFB2ToXDocument("Temp\\" + Path.GetFileName(fb2EncodedFile), itteration); } catch { CopyFB2ToBadFolder("Temp\\" + Path.GetFileName(fb2EncodedFile)); } finally { //File.Delete(fb2EncodedFile); File.Delete("Temp\\" + Path.GetFileName(fb2EncodedFile)); } }
private static void Main(string[] args) { CustomTraceListener listener = null; Fb2FixArguments arguments = new Fb2FixArguments(); ZipConstants.DefaultCodePage = 866; if (CommandLineParser.ParseArguments(args, arguments)) { string workingDirectory = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location); //if(File.Exists(Path.Combine(workingDirectory, "fb2fix.rsp")) && !arguments.noconfig) //{ // arguments = new Fb2FixArguments(); // string[] argList = new string[args.Length + 1]; // argList[0] = "@" + Path.Combine(workingDirectory, "fb2fix.rsp"); // args.CopyTo(argList, 1); // if(!CommandLineParser.ParseArguments(argList, arguments)) // { // Console.WriteLine(); // PrintUsageInfo(); // Environment.Exit(1); // } //} if (arguments.files.Length == 0) { PrintUsageInfo(); Environment.Exit(1); } if(String.IsNullOrEmpty(arguments.dtdFile) || String.Compare(arguments.dtdFile, "fb2.dtd") == 0) { arguments.dtdFile = Path.Combine(workingDirectory, "fb2.dtd"); } if(String.IsNullOrEmpty(arguments.genres) || String.Compare(arguments.genres, "genrestransfer.xml") == 0) { arguments.genres = Path.Combine(workingDirectory, "genrestransfer.xml"); } if (String.IsNullOrEmpty(arguments.xsdSchema) || String.Compare(arguments.xsdSchema, "FictionBook.xsd") == 0) { arguments.xsdSchema = Path.Combine(workingDirectory, "FictionBook.xsd"); } CustomConsoleTraceListener infoConsoleListener = new CustomConsoleTraceListener(); infoConsoleListener.Filter = new TraceEventTypeFilter(TraceEventTypes.Information, arguments.loglevel); Logger.Listeners.Add(infoConsoleListener); CustomConsoleTraceListener errorConsoleListener = new CustomConsoleTraceListener(); errorConsoleListener.Filter = new TraceEventTypeFilter(TraceEventTypes.Critical | TraceEventTypes.Error | TraceEventTypes.Warning, arguments.loglevel); Logger.Listeners.Add(errorConsoleListener); if (!String.IsNullOrEmpty(arguments.logfile)) { listener = new CustomTraceListener(arguments.logfile); listener.Filter = new EventTypeFilter((SourceLevels) arguments.loglevel); Logger.Listeners.Add(listener); } try { using (FileStream fileStream = File.Open(arguments.genres, FileMode.Open, FileAccess.Read, FileShare.Read)) { using (XmlReader reader = XmlReader.Create(fileStream)) { GenreTable.ReadGenreList(reader); } } BatchFilesProcessor batch = new BatchFilesProcessor(arguments); batch.Process(arguments.files); } catch (Exception exp) { Logger.WriteLine(TraceEventType.Critical, exp.Message); Logger.WriteLine(TraceEventType.Verbose, exp.ToString()); } finally { Logger.Flush(); if (listener != null) { listener.Flush(); listener.Close(); } } } else { Console.WriteLine(); PrintUsageInfo(); Environment.Exit(1); } }