static int Main(string[] args) { int totErrors = 0; // We need to use the logger early to initialise before we use EventTrace Logger.Debug("XbimConvert starting..."); arguments = Params.ParseParams(args); if (!arguments.IsValid) { return -1; } var SubMode = SearchOption.TopDirectoryOnly; if (arguments.ProcessSubDir) SubMode = SearchOption.AllDirectories; var files = Directory.GetFiles(arguments.specdir, arguments.specpart, SubMode); if (files.Length == 0) { Console.WriteLine("Invalid IFC filename or filter: {0}, current directory is: {1}", args[0], Directory.GetCurrentDirectory()); return -1; } long parseTime = 0; long geomTime = 0; foreach (var origFileName in files) { using (EventTrace eventTrace = LoggerFactory.CreateEventTrace()) { try { Console.WriteLine("Starting conversion of {0}", origFileName); Logger.InfoFormat("Starting conversion of {0}", origFileName); string xbimFileName = BuildFileName(origFileName, ".xbim"); //string xbimGeometryFileName = BuildFileName(arguments.IfcFileName, ".xbimGC"); System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); ReportProgressDelegate progDelegate = delegate(int percentProgress, object userState) { if (!arguments.IsQuiet) { Console.Write(string.Format("{0:D5} Converted", percentProgress)); ResetCursor(Console.CursorTop); } }; watch.Start(); using (XbimModel model = ParseModelFile(origFileName, xbimFileName, arguments.Caching)) { //model.Open(xbimFileName, XbimDBAccess.ReadWrite); parseTime = watch.ElapsedMilliseconds; if (!arguments.NoGeometry) { XbimMesher.GenerateGeometry(model, Logger, progDelegate); geomTime = watch.ElapsedMilliseconds - parseTime; if (arguments.GenerateScene) { Stopwatch sceneTimer = new Stopwatch(); if (!arguments.IsQuiet) Console.Write("Scene generation started..."); sceneTimer.Start(); XbimSceneBuilder sb = new XbimSceneBuilder(); sb.Options = arguments.GenerateSceneOptions; string xbimSceneName = BuildFileName(xbimFileName, ".xbimScene"); sb.BuildGlobalScene(model, xbimSceneName, !arguments.IsQuiet ? Logger : null ); sceneTimer.Stop(); if (!arguments.IsQuiet) Console.WriteLine(string.Format(" Completed in {0} ms", sceneTimer.ElapsedMilliseconds)); } } model.Close(); watch.Stop(); } // XbimModel.Terminate(); GC.Collect(); ResetCursor(Console.CursorTop + 1); Console.WriteLine("Success. Parsed in " + parseTime + " ms, geometry meshed in " + geomTime + " ms, total time " + (parseTime+geomTime) + " ms."); } catch (Exception e) { if (e is XbimException || e is NotImplementedException) { // Errors we have already handled or know about. Keep details brief in the log Logger.ErrorFormat("One or more errors converting {0}. Exiting...", origFileName); CreateLogFile(origFileName, eventTrace.Events); DisplayError(string.Format("One or more errors converting {0}, {1}", origFileName, e.Message)); } else { // Unexpected failures. Log exception details Logger.Fatal(String.Format("Fatal Error converting {0}. Exiting...", origFileName), e); CreateLogFile(origFileName, eventTrace.Events); DisplayError(string.Format("Fatal Error converting {0}, {1}", origFileName, e.Message)); } } int errors = (from e in eventTrace.Events where (e.EventLevel > EventLevel.INFO) select e).Count(); if (errors > 0) { CreateLogFile(origFileName, eventTrace.Events); } totErrors += errors; } } GetInput(); Logger.Info("XbimConvert finished successfully..."); return totErrors; }
public static Params ParseParams(string[] args) { Params result = new Params(args); return result; }