Exemplo n.º 1
0
        // https://stackoverflow.com/a/19538654/6345585
        public static MemoryLog Setup(string file = null)
        {
            var config = new LoggerConfiguration()
                         .Enrich.FromLogContext()
                         .WriteTo.ColoredConsole();


            if (file != null)
            {
                config.WriteTo.File(file);
            }

            var memLog         = new MemoryLog();
            var memLogProvider = new MemoryLogProvider(memLog);

            Log.Logger = config.CreateLogger();

            var lf = new LoggerFactory().AddSerilog();

            lf.AddProvider(memLogProvider);
            var log = lf.CreateLogger("WexbimCreation");

            log.LogInformation("Creating wexBIM file from IFC model.");

            // set up xBIM logging. It will use your providers.
            XbimLogging.LoggerFactory = lf;

            return(memLog);
        }
Exemplo n.º 2
0
        public bool Check(IModel model, string logFile = null)
        {
            // set up error logger handler to get errors from parser
            appender = Logger.Setup(logFile);
            log      = XbimLogging.CreateLogger("Validator");

            return(CheckInternal(model, new Dictionary <int, string>()));
        }
Exemplo n.º 3
0
 public MemoryLogProvider(MemoryLog log)
 {
     this.log = log;
 }
Exemplo n.º 4
0
        public bool Check(string file)
        {
            // set up error logger handler to get errors from parser
            var logFile = file + ".log";

            appender = Logger.Setup(logFile);
            log      = XbimLogging.CreateLogger("Validator");


            var ext    = Path.GetExtension(file).ToUpperInvariant().Trim('.');
            var format = "UNKNOWN";

            switch (ext)
            {
            case "IFC":
                format = "STEP21 (*.ifc)";
                break;

            case "IFCXML":
                format = "XML (*.ifcXML)";
                break;

            default:
                break;
            }
            log.LogInformation($"Validating file: {file}");
            log.LogInformation($"File format: {format}");


            try
            {
                // open as an in-memory model (all syntactic errors fill be picked up)
                using (var model = IfcStore.Open(file, null, -1))
                {
                    // header information
                    log.LogInformation($"Schema version: {string.Join(", ", model.Header.SchemaVersion)}");
                    log.LogInformation($"Model View Definitions: {string.Join(", ", model.Header.FileDescription.Description)}");

                    // STEP21 syntactic errors will be reported in the log already
                    if (appender.Errors.Any())
                    {
                        // do not proceed because the data is incomplete
                        return(false);
                    }

                    log.LogInformation($"Number of entities: {model.Instances.Count}");
                    LogEntityHistogram(model);

                    var idMap = new Dictionary <int, string>();
                    if (file.ToLower().EndsWith(".ifcxml"))
                    {
                        using (var stream = File.OpenRead(file))
                        {
                            idMap = GetXmlEntityMap(stream, model);
                        }
                    }

                    CheckInternal(model, idMap);
                }
            }
            // XML syntactic errors will be fired as an exception
            catch (XbimParserException pe)
            {
                log.LogError($"Parser failure: {pe.Message}.");
                return(false);
            }
            catch (Exception ge)
            {
                log.LogError($"General failure: {ge.Message}.", ge);
                return(false);
            }

            return(!Errors.Any() && !Warnings.Any());
        }