Beispiel #1
0
        /// <summary>
        /// Configure a Json Storage of a specific data class
        /// </summary>
        public RevitStorageBuilder ConfigureJsonStorage <T>(Action <RevitSchemaSettings> config) where T : class, new()
        {
            var storageType = typeof(T);

            if (config == null)
            {
                throw new ArgumentException($"Adding Revit Json Storage of type {storageType.FullName} requires Schema settings.");
            }

            var settings = new RevitSchemaSettings();

            config.Invoke(settings);

            if (Guid.Empty == settings.SchemaGuid)
            {
                throw new ArgumentException($"Revit Json Storage of type {storageType.FullName} requires Schema Guid.");
            }

            if (string.IsNullOrWhiteSpace(settings.SchemaName))
            {
                throw new ArgumentException($"Revit Json Storage of type {storageType.FullName} requires Schema name.");
            }

            this.storageSettings.SchemaSettings.Add(storageType, settings);
            this.storageConfigurations.Add(() =>
            {
                this.container.AddSingleton <IRevitJsonStorage <T>, RevitJsonStorage <T> >();
            });
            return(this);
        }
        private Schema CreateSchema(RevitSchemaSettings schemaSettings)
        {
            Schema        schema;
            SchemaBuilder builder = new SchemaBuilder(schemaSettings.SchemaGuid);

            if (Enum.IsDefined(typeof(AccessLevel), schemaSettings.ReadAccessLevel))
            {
                builder.SetReadAccessLevel((Autodesk.Revit.DB.ExtensibleStorage.AccessLevel)schemaSettings.ReadAccessLevel.GetHashCode());
            }

            if (Enum.IsDefined(typeof(AccessLevel), schemaSettings.WriteAccessLevel))
            {
                builder.SetWriteAccessLevel((Autodesk.Revit.DB.ExtensibleStorage.AccessLevel)schemaSettings.WriteAccessLevel.GetHashCode());
            }

            if (!string.IsNullOrWhiteSpace(schemaSettings.VendorId))
            {
                builder.SetVendorId(schemaSettings.VendorId);
            }

            if (!string.IsNullOrWhiteSpace(schemaSettings.SchemaDocumentation))
            {
                builder.SetDocumentation(schemaSettings.SchemaDocumentation);
            }

            builder.SetSchemaName(schemaSettings.SchemaName);

            builder.AddSimpleField(this.fieldName, typeof(string));
            schema = builder.Finish();

            if (schema == null)
            {
                throw new Exception($"Onbox was unable to create schema {schemaSettings.SchemaName}: {schemaSettings.SchemaGuid}");
            }

            return(schema);
        }