Пример #1
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);
     }
 }
Пример #2
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);
            }
        }