Beispiel #1
0
        public override void Persist(IModel model, string fileName, ReportProgressDelegate progDelegate = null)
        {
            if (model is EsentModel esentModel)
            {
                var fullSourcePath = Path.GetFullPath(esentModel.DatabaseName);
                var fullTargetPath = Path.GetFullPath(fileName);
                if (string.Compare(fullSourcePath, fullTargetPath, StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return; // do nothing - don't save on top of self
                }
            }
            else
            {
                throw new ArgumentOutOfRangeException("EsentModelProvider only supports EsentModel");
            }

            // Create a new Esent model for this Model => Model copy
            var factory = GetFactory(model.SchemaVersion);

            using (var esentDb = new EsentModel(factory))
            {
                esentDb.CreateFrom(model, fileName, progDelegate);
                esentDb.Close();
            }
        }
Beispiel #2
0
 /// <summary>
 ///  Creates and opens a new Xbim Database
 /// </summary>
 /// <param name="factory">Entity factory to be used for deserialization</param>
 /// <param name="dbFileName">Name of the Xbim file</param>
 /// <param name="access"></param>
 /// <returns></returns>
 static public EsentModel CreateModel(IEntityFactory factory, string dbFileName, XbimDBAccess access = XbimDBAccess.ReadWrite)
 {
     try
     {
         if (string.IsNullOrWhiteSpace(Path.GetExtension(dbFileName)))
         {
             dbFileName += ".xBIM";
         }
         var model = new EsentModel(factory);
         model.CreateDatabase(dbFileName);
         model.Open(dbFileName, access);
         model.Header = new StepFileHeader(StepFileHeader.HeaderCreationMode.InitWithXbimDefaults, model)
         {
             FileName = { Name = dbFileName }
         };
         foreach (var schemasId in factory.SchemasIds)
         {
             model.Header.FileSchema.Schemas.Add(schemasId);
         }
         return(model);
     }
     catch (Exception e)
     {
         throw new XbimException("Failed to create and open xBIM file \'" + dbFileName + "\'\n" + e.Message, e);
     }
 }
        public EsentGeometryStoreReader(EsentModel esentModel)
        {
            _esentModel               = esentModel;
            _shapeGeometryCursor      = _esentModel.GetShapeGeometryTable();
            _shapeInstanceCursor      = _esentModel.GetShapeInstanceTable();
            _shapeGeometryTransaction = _shapeGeometryCursor.BeginReadOnlyTransaction();
            _shapeInstanceTransaction = _shapeInstanceCursor.BeginReadOnlyTransaction();
            _regionsList              = new XbimContextRegionCollection();
            IXbimShapeGeometryData regions = new XbimRegionCollection();

            if (_shapeGeometryCursor.TryMoveFirstRegion(ref regions))
            {
                do
                {
                    _regionsList.Add((XbimRegionCollection)regions);
                    regions = new XbimRegionCollection();
                } while (_shapeGeometryCursor.TryMoveNextRegion(ref regions));
            }
            if (!_regionsList.Any()) //we might have an old xbim database regions were stored in the geometry table
            {
                var legacyCursor = _esentModel.GetGeometryTable();
                using (var txn = legacyCursor.BeginReadOnlyTransaction())
                {
                    foreach (var regionData in legacyCursor.GetGeometryData(Xbim.Common.Geometry.XbimGeometryType.Region))
                    {
                        _regionsList.Add(XbimRegionCollection.FromArray(regionData.ShapeData));
                    }
                }
                _esentModel.FreeTable(legacyCursor);
            }
            _contextIds = new HashSet <int>(ContextIds);
        }
Beispiel #4
0
        //public static IStepFileHeader GetFileHeader(string fileName)
        //{
        //}

        public static IStepFileHeader GetStepFileHeader(string fileName)
        {
            //create a temporary model
            var esentModel = new EsentModel();

            esentModel.InstanceCache = new PersistedEntityInstanceCache(esentModel, null);

            esentModel.InstanceCache.DatabaseName = fileName;
            IStepFileHeader header;
            var             entTable = esentModel.InstanceCache.GetEntityTable();

            try
            {
                using (entTable.BeginReadOnlyTransaction())
                {
                    header = entTable.ReadHeader();
                }
            }
            catch (Exception e)
            {
                throw new XbimException("Failed to open " + fileName, e);
            }
            finally
            {
                esentModel.InstanceCache.FreeTable(entTable);
                esentModel.Dispose();
            }
            return(header);
        }
 public XbimGeometryCursor(EsentModel model, string database, OpenDatabaseGrbit mode)
     : base(model, database, mode)
 {
     Api.JetOpenTable(Sesid, DbId, GeometryTableName, null, 0, mode == OpenDatabaseGrbit.ReadOnly ? OpenTableGrbit.ReadOnly :
                      mode == OpenDatabaseGrbit.Exclusive ? OpenTableGrbit.DenyWrite : OpenTableGrbit.None,
                      out Table);
     InitColumns();
 }
 public EsentShapeInstanceCursor(EsentModel model, string database, OpenDatabaseGrbit mode)
     : base(model, database, mode)
 {
     Api.JetOpenTable(this.Sesid, this.DbId, InstanceTableName, null, 0, mode == OpenDatabaseGrbit.ReadOnly ? OpenTableGrbit.ReadOnly :
                      mode == OpenDatabaseGrbit.Exclusive ? OpenTableGrbit.DenyWrite : OpenTableGrbit.None,
                      out this.Table);
     InitColumns();
 }
Beispiel #7
0
 public T SurfaceStyle <T>(EsentModel model) where T : class, IPersistEntity
 {
     if (IsIfcSurfaceStyle)
     {
         return((T)model.Instances[_styleId]);
     }
     return(null);
 }
Beispiel #8
0
 internal XbimReadWriteTransaction(EsentModel model, EsentLazyDBTransaction txn, string name = null)
 {
     Name = name;
     Model = model;
     _readWriteTransaction = txn;
     InTransaction = true;
     _pulseCount = 0;
     _transactionBatchSize = 100;
 }
Beispiel #9
0
        public override IModel Create(XbimSchemaVersion ifcVersion, XbimStoreType storageType)
        {
            var factory = GetFactory(ifcVersion);

            if (storageType == XbimStoreType.EsentDatabase)
            {
                return(EsentModel.CreateTemporaryModel(factory));
            }
            throw new NotSupportedException($"{storageType} is not a supported Storage Type");
        }
Beispiel #10
0
        private EsentModel CreateEsentModel(XbimSchemaVersion schema, int codePageOverride)
        {
            var factory = GetFactory(schema);
            var model   = new EsentModel(factory)
            {
                CodePageOverride = codePageOverride
            };

            return(model);
        }
Beispiel #11
0
 /// <summary>
 /// Constructs a table and opens it
 /// </summary>
 /// <param name="instance"></param>
 /// <param name="database"></param>
 public EsentEntityCursor(EsentModel model, string database, OpenDatabaseGrbit mode)
     : base(model, database, mode)
 {
     Api.JetOpenTable(Sesid, DbId, ifcEntityTableName, null, 0,
                      mode == OpenDatabaseGrbit.ReadOnly ? OpenTableGrbit.ReadOnly :
                      mode == OpenDatabaseGrbit.Exclusive ? OpenTableGrbit.DenyWrite : OpenTableGrbit.None, out Table);
     Api.JetOpenTable(Sesid, DbId, ifcEntityIndexTableName, null, 0,
                      mode == OpenDatabaseGrbit.ReadOnly ? OpenTableGrbit.ReadOnly :
                      mode == OpenDatabaseGrbit.Exclusive ? OpenTableGrbit.DenyWrite : OpenTableGrbit.None, out _indexTable);
     InitColumns();
 }
Beispiel #12
0
 protected EsentCursor(EsentModel model, string database, OpenDatabaseGrbit mode)
 {
     LockObject = new Object();
     Model      = model;
     Instance   = model.Cache.JetInstance;
     Sesid      = new Session(Instance);
     Api.JetOpenDatabase(Sesid, database, String.Empty, out DbId, mode);
     Api.JetOpenTable(Sesid, DbId, GlobalsTableName, null, 0, mode == OpenDatabaseGrbit.ReadOnly ? OpenTableGrbit.ReadOnly :
                      mode == OpenDatabaseGrbit.Exclusive ? OpenTableGrbit.DenyWrite : OpenTableGrbit.None,
                      out GlobalsTable);
     EntityCountColumn   = Api.GetTableColumnid(Sesid, GlobalsTable, EntityCountColumnName);
     GeometryCountColumn = Api.GetTableColumnid(Sesid, GlobalsTable, GeometryCountColumnName);
     FlushColumn         = Api.GetTableColumnid(Sesid, GlobalsTable, FlushColumnName);
     IfcHeaderColumn     = Api.GetTableColumnid(Sesid, GlobalsTable, ifcHeaderColumnName);
     ReadOnly            = (mode == OpenDatabaseGrbit.ReadOnly);
 }
Beispiel #13
0
        /// <summary>
        /// Creates an empty model using a temporary filename, the model will be deleted on close, unless SaveAs is called
        /// It will be returned open for read write operations
        /// </summary>
        /// <returns></returns>
        static public EsentModel CreateTemporaryModel(IEntityFactory factory)
        {
            var tmpFileName = Path.GetTempFileName();

            try
            {
                var model = new EsentModel(factory);
                model.CreateDatabase(tmpFileName);
                model.Open(tmpFileName, XbimDBAccess.ReadWrite, true);
                model.Header = new StepFileHeader(StepFileHeader.HeaderCreationMode.InitWithXbimDefaults, model);
                foreach (var schemasId in factory.SchemasIds)
                {
                    model.Header.FileSchema.Schemas.Add(schemasId);
                }
                return(model);
            }
            catch (Exception e)
            {
                throw new XbimException("Failed to create and open temporary xBIM file \'" + tmpFileName + "\'\n" + e.Message, e);
            }
        }
Beispiel #14
0
        public override XbimSchemaVersion GetXbimSchemaVersion(string modelPath)
        {
            var storageType = modelPath.StorageType();

            if (storageType == StorageType.Invalid)
            {
                return(XbimSchemaVersion.Unsupported);
            }
            if (storageType != StorageType.Xbim)
            {
                return(Memory.MemoryModel.GetSchemaVersion(modelPath));
            }

            var            stepHeader       = EsentModel.GetStepFileHeader(modelPath);
            IList <string> schemas          = stepHeader.FileSchema.Schemas;
            var            schemaIdentifier = string.Join(", ", schemas);

            foreach (var schema in schemas)
            {
                if (string.Compare(schema, "Ifc4", StringComparison.OrdinalIgnoreCase) == 0 ||
                    schema.StartsWith("Ifc4RC", StringComparison.OrdinalIgnoreCase))
                {
                    return(XbimSchemaVersion.Ifc4);
                }
                if (string.Compare(schema, "Ifc4x1", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(XbimSchemaVersion.Ifc4x1);
                }
                if (string.Compare(schema, "Ifc2x3", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return(XbimSchemaVersion.Ifc2X3);
                }
                if (schema.StartsWith("Ifc2x", StringComparison.OrdinalIgnoreCase)) //return this as 2x3
                {
                    return(XbimSchemaVersion.Ifc2X3);
                }
            }
            return(XbimSchemaVersion.Unsupported);
        }
Beispiel #15
0
 public EsentEntityCursor(EsentModel model, string database)
     : this(model, database, OpenDatabaseGrbit.None)
 {
 }
Beispiel #16
0
        public override IModel Create(XbimSchemaVersion ifcVersion, string dbPath)
        {
            var factory = GetFactory(ifcVersion);

            return(EsentModel.CreateModel(factory, dbPath));
        }
 internal XbimReadTransaction(EsentModel theModel, EsentReadOnlyTransaction txn)
 {
     Model            = theModel;
     _readTransaction = txn;
     InTransaction    = true;
 }
 public EsentShapeInstanceCursor(EsentModel model, string database)
     : this(model, database, OpenDatabaseGrbit.None)
 {
 }
Beispiel #19
0
 public EsentGeometryStore(EsentModel esentModel)
 {
     _esentModel = esentModel;
 }
 internal XbimInstanceCollection(EsentModel esentModel)
 {
     Cache  = esentModel.Cache;
     _model = esentModel;
 }
 public XbimGeometryCursor(EsentModel model, string database)
     : this(model, database, OpenDatabaseGrbit.None)
 {
 }