Ejemplo n.º 1
0
        public FieldBuilder CreateField(SchemaBuilder schemaBuilder,
                                        PropertyInfo propertyInfo)
        {
            FieldBuilder fieldBuilder;

            // Check whether generic type is subentity or not
            var genericType = propertyInfo.PropertyType.GetGenericArguments()[0];

            var iRevitEntity = genericType.GetInterface("IRevitEntity");

            if (iRevitEntity != null)
            {
                fieldBuilder =
                    schemaBuilder.AddArrayField(propertyInfo.Name, typeof(Entity));

                AttributeExtractor <SchemaAttribute> schemaAttributeExtractor =
                    new AttributeExtractor <SchemaAttribute>();
                var subSchemaAttribute =
                    schemaAttributeExtractor
                    .GetAttribute(genericType);
                fieldBuilder
                .SetSubSchemaGUID(subSchemaAttribute.GUID);
            }
            else
            {
                fieldBuilder =
                    schemaBuilder.AddArrayField(propertyInfo.Name, genericType);
            }
            return(fieldBuilder);
        }
        private bool StoreElemDateTime(Element elem, string excelFileName, string excelWorksheetName, List <string> paramNames, List <string> massGroupingParams, FamilySymbol selectedSymbol, Level selectedLevel, string creationDateTime, string groupId)
        {
            string message = "start";

            try
            {
                // Add schema data
                SchemaBuilder sBuilder = new SchemaBuilder(Properties.Settings.Default.SchemaIdElement);
                sBuilder.SetReadAccessLevel(AccessLevel.Public);
                sBuilder.SetWriteAccessLevel(AccessLevel.Public);
                sBuilder.SetVendorId("LMNA");
                sBuilder.SetSchemaName("ProgramElem");

                FieldBuilder fileFB = sBuilder.AddSimpleField("FileName", typeof(string));
                fileFB.SetDocumentation("File path to the excel file.");
                message = "file name set";
                FieldBuilder worksheetFB = sBuilder.AddSimpleField("Worksheet", typeof(string));
                worksheetFB.SetDocumentation("Worksheet names for the imports");
                message = "worksheet set";
                FieldBuilder paramsFB = sBuilder.AddArrayField("ParameterNames", typeof(string));
                paramsFB.SetDocumentation("Parameter names selected for this set of masses.");
                message = "parameternames set";
                FieldBuilder groupingsFB = sBuilder.AddArrayField("GroupingParameters", typeof(string));
                groupingsFB.SetDocumentation("Mass grouping parameters.");
                message = "grouping set";
                FieldBuilder symbolFB = sBuilder.AddSimpleField("SymbolId", typeof(ElementId));
                symbolFB.SetDocumentation("Symbol for mass family creation.");
                message = "symbols et";
                FieldBuilder levelFB = sBuilder.AddSimpleField("LevelId", typeof(ElementId));
                levelFB.SetDocumentation("Level for mass family creation.");
                message = "level set";
                FieldBuilder dtFB = sBuilder.AddSimpleField("CreationTime", typeof(string));
                dtFB.SetDocumentation("Creation time of this mass element per import.");
                message = "datetime set";
                FieldBuilder gidFB = sBuilder.AddSimpleField("GroupId", typeof(string));
                gidFB.SetDocumentation("GroupID based on GroupingParameters");
                Schema schema = sBuilder.Finish();

                Entity entity = new Entity(schema);
                entity.Set <string>("FileName", excelFileName);
                entity.Set <string>("Worksheet", excelWorksheetName);
                entity.Set <IList <string> >(schema.GetField("ParameterNames"), paramNames);
                entity.Set <IList <string> >(schema.GetField("GroupingParameters"), massGroupingParams);
                entity.Set <ElementId>("SymbolId", selectedSymbol.Id);
                entity.Set <ElementId>("LevelId", selectedLevel.Id);
                entity.Set <string>("CreationTime", creationDateTime);
                entity.Set <string>("GroupId", groupId);
                elem.SetEntity(entity);

                return(true);
            }
            catch (Exception ex)
            {
                TaskDialog.Show(message, ex.Message);
                return(false);
            }
        }
        private static Schema CreateSchema()
        {
            Schema schema = null;

            try
            {
                var subBuilder = new SchemaBuilder(subSchemaId);
                subBuilder.SetSchemaName("MapItemInfoList");
                subBuilder.AddSimpleField(s_SourceModelId, typeof(string));
                subBuilder.AddSimpleField(s_RecipientModelId, typeof(string));
                subBuilder.AddSimpleField(s_MapItemType, typeof(string));
                subBuilder.AddSimpleField(s_SourceItemId, typeof(int));
                subBuilder.AddSimpleField(s_RecipientItemId, typeof(int));
                subBuilder.AddSimpleField(s_SourceItemName, typeof(string));
                subBuilder.AddSimpleField(s_RecipientItemName, typeof(string));
                subSchema = subBuilder.Finish();

                var sBuilder = new SchemaBuilder(schemaId);
                sBuilder.SetSchemaName("ViewConfiguration");
                sBuilder.AddSimpleField(s_WorksetVisibility, typeof(bool));
                var fBuilder = sBuilder.AddArrayField(s_MapItems, typeof(Entity));
                fBuilder.SetSubSchemaGUID(subSchemaId);

                schema = sBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema.\n" + ex.Message, "Create Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
Ejemplo n.º 4
0
        internal static Schema GetSchema(Guid guid, string schemaName, IDictionary <string, ISet <string> > values)
        {
            // Ensure that the schema being generated is unique -
            // - otherwise, return the existing one.
            Schema schema = Schema.Lookup(guid);

            if (schema == null)
            {
                // 1. Create and name a new schema
                SchemaBuilder schemaBuilder =
                    new SchemaBuilder(guid);
                schemaBuilder.SetSchemaName(schemaName);

                // 2. Set the read/write access
                schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
                schemaBuilder.SetWriteAccessLevel(AccessLevel.Vendor);
                schemaBuilder.SetVendorId(VENDOR_ID);

                // 3. Define one or more fields of data
                foreach (string key in values.Keys)
                {
                    if (schemaBuilder.AcceptableName(key))
                    {
                        schemaBuilder.AddArrayField(key, typeof(string));
                    }
                    else
                    {
                        System.Diagnostics.Trace.Write($"{key}");
                    }
                }
                schema = schemaBuilder.Finish();
            }
            return(schema);
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     Creates an array type field builder by field name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="schemaBuilder"></param>
        /// <param name="fieldName"></param>
        /// <param name="unitType"></param>
        /// <param name="desc"></param>
        /// <returns></returns>
        public static FieldBuilder CreateArrayField <T>(this SchemaBuilder schemaBuilder, string fieldName,
                                                        UnitType unitType, string desc = null)
        {
            if (schemaBuilder is null)
            {
                throw new ArgumentNullException(nameof(schemaBuilder));
            }

            if (fieldName is null)
            {
                throw new ArgumentNullException(nameof(fieldName));
            }

            if (desc is null)
            {
                throw new ArgumentNullException(nameof(desc));
            }

            var result = schemaBuilder.AddArrayField(fieldName, typeof(T));

            result.SetUnitType(unitType);
            result.SetDocumentation(desc);

            return(result);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///     Creates an IEnumerable type field builder by field name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="schemaBuilder"></param>
        /// <param name="fieldName"></param>
        /// <param name="unitType"></param>
        /// <param name="dcrp"></param>
        /// <returns></returns>
        public static void AddListField <T>(this SchemaBuilder schemaBuilder, string fieldName, UnitType unitType, string dcrp = null)
        {
            if (schemaBuilder is null)
            {
                throw new ArgumentNullException(nameof(schemaBuilder));
            }

            if (fieldName is null)
            {
                throw new ArgumentNullException(nameof(fieldName));
            }

            if (dcrp is null)
            {
                throw new ArgumentNullException(nameof(dcrp));
            }

            if (!typeof(T).IsPrimitive)
            {
                throw new NotSupportedException(nameof(T));
            }

            var result = schemaBuilder.AddArrayField(fieldName, typeof(IEnumerable <T>));

            result.SetUnitType(unitType);

            result.SetDocumentation(dcrp);
        }
Ejemplo n.º 7
0
 public override Schema GetOrCreateSchema()
 {
     SchemaBuilder sb = new SchemaBuilder(SchemaGuid);
      sb.SetSchemaName(SchemaName);
      sb.AddArrayField("someStringArray", typeof(string));
      return sb.Finish();
 }
Ejemplo n.º 8
0
        public static Schema CreateSchema()
        {
            Schema schema    = null;
            Schema subSchema = null;

            try
            {
                SchemaBuilder subSchemaBuilder = new SchemaBuilder(subSchemaId);
                subSchemaBuilder.SetSchemaName("ElementIds");
                subSchemaBuilder.AddArrayField(s_ElementIds, typeof(ElementId));
                subSchema = subSchemaBuilder.Finish();

                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaId);
                schemaBuilder.SetSchemaName("ColorEditorSetting");
                schemaBuilder.AddSimpleField(s_BCFPath, typeof(string));
                var mapField = schemaBuilder.AddMapField(s_ColoredElementIds, typeof(string), typeof(Entity));
                mapField.SetSubSchemaGUID(subSchemaId);
                schema = schemaBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema for Color Scheme Editor.\n" + ex.Message, "Create Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
        private static Schema CreateSchema()
        {
            Schema schema = null;

            try
            {
                SchemaBuilder subBuilder = new SchemaBuilder(subSchemaId);
                subBuilder.SetSchemaName("MassParameterMaps");
                subBuilder.AddSimpleField(s_HostParameterName, typeof(string));
                subBuilder.AddSimpleField(s_MassParameterName, typeof(string));
                subSchema = subBuilder.Finish();

                SchemaBuilder sBuilder = new SchemaBuilder(schemaId);
                sBuilder.SetSchemaName("MassConfiguration");
                sBuilder.AddSimpleField(s_HostCategory, typeof(string));
                sBuilder.AddSimpleField(s_MassCategory, typeof(string));
                sBuilder.AddSimpleField(s_ParameterUpdateType, typeof(string));
                sBuilder.AddSimpleField(s_SetDefaultHeight, typeof(bool));
                FieldBuilder fBuilder = sBuilder.AddSimpleField(s_UserHeight, typeof(double));
                fBuilder.SetUnitType(UnitType.UT_Length);

                fBuilder = sBuilder.AddArrayField(s_ParameterMaps, typeof(Entity));
                fBuilder.SetSubSchemaGUID(subSchemaId);

                schema = sBuilder.Finish();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to create schema.\n" + ex.Message, "Create Schema", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            return(schema);
        }
Ejemplo n.º 10
0
        public override Schema GetOrCreateSchema()
        {
            SchemaBuilder sb = new SchemaBuilder(SchemaGuid);

            sb.SetSchemaName(SchemaName);
            sb.AddArrayField("someStringArray", typeof(string));
            return(sb.Finish());
        }
Ejemplo n.º 11
0
        public Schema CreateSchema(Guid schemaGuid)
        {
            Schema schema = Schema.Lookup(schemaGuid);

            if (schema == null)
            {
                SchemaBuilder schemaBuilder = new SchemaBuilder(schemaGuid);
                schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
                schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);
                //schemaBuilder.SetWriteAccessLevel(AccessLevel.Vendor);
                //schemaBuilder.SetVendorId("CBIM");

                FieldBuilder fieldBuilder = schemaBuilder.AddSimpleField("XYZ", typeof(XYZ));
                fieldBuilder.SetUnitType(UnitType.UT_Length);
                fieldBuilder.SetDocumentation("I'm XYZ");

                FieldBuilder fieldBuilder1 = schemaBuilder.AddSimpleField("Double", typeof(double));
                fieldBuilder1.SetUnitType(UnitType.UT_Length);
                fieldBuilder1.SetDocumentation("I'm Double");

                //Ilist<string>
                FieldBuilder fieldBuilder2 = schemaBuilder.AddArrayField("List", typeof(string));
                //fieldBuilder2.SetUnitType(UnitType.UT_Length);
                fieldBuilder2.SetDocumentation("I'm Ilist<string>");

                //IDictinary<string,int>
                FieldBuilder fieldBuilder3 = schemaBuilder.AddMapField("Dictionary", typeof(string), typeof(int));
                //fieldBuilder3.SetUnitType(UnitType.UT_Length);
                fieldBuilder3.SetDocumentation("I'm IDictinary<string,int>");

                //SubSchema
                //Guid guid = new Guid("f9b00633-6aa9-47a6-acea-7f74407b9ea5");
                //Schema subSchema = Schema.Lookup(guid);
                //if (subSchema == null)
                //{
                //    SchemaBuilder subSchemaBuilder = new SchemaBuilder(guid);
                //    subSchemaBuilder.SetReadAccessLevel(AccessLevel.Public);
                //    subSchemaBuilder.SetWriteAccessLevel(AccessLevel.Public);

                //    FieldBuilder sub = subSchemaBuilder.AddSimpleField("subInt", typeof(int));
                //    sub.SetDocumentation("I'm Int");

                //    subSchemaBuilder.SetSchemaName("SubSchema");
                //    subSchema = subSchemaBuilder.Finish();
                //}
                //Entity subEntity = new Entity(subSchema);
                //subEntity.Set<int>(subSchema.GetField("subInt"), 11);

                //FieldBuilder fieldBuilder4 = schemaBuilder.AddSimpleField("SubEntity", typeof(Entity));
                //fieldBuilder4.SetDocumentation("I'm SubSchema");


                schemaBuilder.SetSchemaName("SchemaName");
                schema = schemaBuilder.Finish();
            }

            return(schema);
        }
Ejemplo n.º 12
0
        private static Schema create_ElementListOfId()
        {
            SchemaBuilder sb = new SchemaBuilder(Guid_ElementListOfId);

            sb.SetSchemaName("ElementListOfId");
            sb.SetReadAccessLevel(AccessLevel.Public);
            FieldBuilder fb1 = sb.AddArrayField("ElementList", typeof(string)); //element unique ids

            Schema sm = sb.Finish();

            return(sm);
        }
Ejemplo n.º 13
0
        /// <summary>
        ///     Sets an entity.
        /// </summary>
        /// <param name="elm"></param>
        /// <param name="schemaName"></param>
        /// <param name="fields"></param>
        /// <returns></returns>
        public static void SetEntity(this Element elm, string schemaName, params FieldInfo[] fields)
        {
            if (elm is null)
            {
                throw new ArgumentNullException(nameof(elm));
            }

            if (schemaName is null)
            {
                throw new ArgumentNullException(nameof(schemaName));
            }

            if (fields is null)
            {
                throw new ArgumentNullException(nameof(fields));
            }

            var guid = Guid.NewGuid();

            var schemaBuilder = new SchemaBuilder(guid);

            schemaBuilder.SetReadAccessLevel(AccessLevel.Public);

            schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);

            schemaBuilder.SetSchemaName(schemaName);

            foreach (var field in fields)
            {
                switch (field.FieldType)
                {
                case SchemaFieldType.Simple:
                    schemaBuilder.AddSimpleField(field.FieldName, field.DataType);

                    break;

                case SchemaFieldType.List:
                    schemaBuilder.AddArrayField(field.FieldName, field.DataType);

                    break;

                case SchemaFieldType.Dictionary:
                    schemaBuilder.AddMapField(field.FieldName, field.KeyType, field.ValueType);

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            elm.SetEntity(new Entity(schemaBuilder.Finish()));
        }
Ejemplo n.º 14
0
        private static Guid FindOrCreateSchema(Document doc)
        {
            // find schema
            RvtSchema = Schema.Lookup(RvtGuid);

            try
            {
                // Find or read subschemas needed
                Guid provGuid = Provider.FindOrCreateSchema(doc);
                Guid servGuid = Service.FindOrCreateSchema(doc);

                // create schema if not found
                if (RvtSchema == null)
                {
                    // Start transaction
                    Transaction createSchema = new Transaction(doc, "Create Bimbot Schema");
                    createSchema.Start();

                    // Build schema
                    SchemaBuilder schemaBldr = new SchemaBuilder(RvtGuid);

                    // Set read and write access attributes and a name
                    schemaBldr.SetReadAccessLevel(AccessLevel.Application);
                    schemaBldr.SetWriteAccessLevel(AccessLevel.Application);
                    schemaBldr.SetApplicationGUID(RevitBimbot.ApplicationGuid);
                    schemaBldr.SetVendorId(RevitBimbot.VendorId);
                    schemaBldr.SetSchemaName("BimBotDocument");

                    // create a field to store services
                    FieldBuilder fieldBldr = schemaBldr.AddMapField(ProvidersField, typeof(string), typeof(Entity));
                    fieldBldr.SetDocumentation("Dictionary of providers by url of service(s) in this project.");
                    fieldBldr.SetSubSchemaGUID(provGuid);

                    fieldBldr = schemaBldr.AddArrayField(ServicesField, typeof(Entity));
                    fieldBldr.SetDocumentation("List of services assigned to this project.");
                    fieldBldr.SetSubSchemaGUID(servGuid);

                    RvtSchema = schemaBldr.Finish(); // register the Schema object
                    createSchema.Commit();
                }
                else
                {
                    RvtSchema = Schema.Lookup(RvtGuid);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(RvtGuid);
        }
Ejemplo n.º 15
0
        /// 添加字段
        /// <summary>
        ///  构造函数,创建schema 表
        /// </summary>
        private SchemaOpr()
        {
            //创建dictionary方式的schema
            System.Guid   guid    = GetCurGuid();
            SchemaBuilder builder = new SchemaBuilder(guid);

            // Set name to this schema builder

            builder.SetSchemaName("PmSchemaComn");
            builder.SetDocumentation("品茗通用的数据扩展结构");

            // Set read and write access levels

            builder.SetReadAccessLevel(AccessLevel.Public);
            builder.SetWriteAccessLevel(AccessLevel.Public);

            // 版本号,升级用
            builder.AddSimpleField("versionNum", typeof(short));

            // string元素
            builder.AddMapField("parms_str", typeof(string), typeof(string));

            // double元素
            FieldBuilder fb = builder.AddMapField("parms_double", typeof(string), typeof(double));

            fb.SetUnitType(UnitType.UT_Length);

            // element元素
            builder.AddMapField("parms_element", typeof(string), typeof(ElementId));

            // 表格元素
            builder.AddArrayField("tables_name", typeof(string));      //段名称
            builder.AddArrayField("tables_postion", typeof(int));      //段的二进制位置
            builder.AddArrayField("tables_content", typeof(byte));     //段的内容

            //
            m_schema = builder.Finish();
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates an array type field builder by field name.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="schemaBuilder"></param>
        /// <param name="fieldName"></param>
        /// <param name="unitType"></param>
        /// <param name="decription"></param>
        /// <returns></returns>
        public static FieldBuilder CreateArrayField <T>(this SchemaBuilder schemaBuilder, string fieldName, UnitType unitType, string decription = null)
        {
            var result = schemaBuilder.AddArrayField(fieldName, typeof(T));

            result.SetUnitType(unitType);

            if (decription == null)
            {
                decription = fieldName;
            }

            result.SetDocumentation(decription);

            return(result);
        }
Ejemplo n.º 17
0
 public ExtensibleStorage(string guid, string SchemaName, string FieldName, Type ValueType, string Fielddocumentation)
 {
     this.Schema_Name   = SchemaName;
     this.Field_Name    = FieldName;
     this.Value_Type    = ValueType;
     this.schemaBuilder = new SchemaBuilder(new Guid(guid));
     schemaBuilder.SetReadAccessLevel(AccessLevel.Public);
     schemaBuilder.SetWriteAccessLevel(AccessLevel.Public);
     // create a field to store a string map
     this.FieldDocumentation = Fielddocumentation;
     this.fieldBuilder       = schemaBuilder.AddArrayField(Field_Name, ValueType);
     fieldBuilder.SetDocumentation(FieldDocumentation);
     schemaBuilder.SetSchemaName(Schema_Name);
     schema = schemaBuilder.Finish();
 }
Ejemplo n.º 18
0
        public static Schema GetSchema( )
        {
            var schema = Schema.Lookup(schemaGuid);

            if (schema != null)
            {
                return(schema);
            }

            var builder = new SchemaBuilder(schemaGuid);

            builder.SetSchemaName("SpeckleLocalStateStorage");
            builder.AddArrayField("streams", typeof(string));

            return(builder.Finish());
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Retrieve an existing EstoreFile schema or
        /// create a new one if it does not exist yet.
        /// </summary>
        /// <returns>EstoreFile schema</returns>
        static Schema GetSchema()
        {
            Schema schema = Schema.Lookup(CmdStore._schema_guid);

            if (null == schema)
            {
                SchemaBuilder schemaBuilder
                    = new SchemaBuilder(_schema_guid);

                schemaBuilder.SetSchemaName("EstoreFile");

                // Allow anyone to read and write the object

                schemaBuilder.SetReadAccessLevel(
                    AccessLevel.Public);

                schemaBuilder.SetWriteAccessLevel(
                    AccessLevel.Public);

                // Create fields

                FieldBuilder fieldBuilder = schemaBuilder
                                            .AddSimpleField("Filename", typeof(string));

                fieldBuilder.SetDocumentation("File name");

                fieldBuilder = schemaBuilder.AddSimpleField(
                    "Folder", typeof(string));

                fieldBuilder.SetDocumentation("Original file folder path");

                fieldBuilder = schemaBuilder.AddArrayField(
                    "Data", typeof(byte));

                fieldBuilder.SetDocumentation("Stored file data");

                // Register the schema

                schema = schemaBuilder.Finish();
            }
            return(schema);
        }
Ejemplo n.º 20
0
        private static readonly Guid RvtGuid = new Guid("a54b4c89-0ee7-4fae-8fbd-b13b04f01a01"); //b13b04 = bimbot, f01 = service data, a01 = version 0.1

        public static Guid FindOrCreateSchema(Document doc)
        {
            // find schema
            RvtSchema = Schema.Lookup(RvtGuid);

            try
            {
                // Find or read subschemas needed
                Guid provGuid = Provider.FindOrCreateSchema(doc);

                // create schema if not found
                if (RvtSchema == null)
                {
                    // Start transaction
                    Transaction createSchema = new Transaction(doc, "Create Service Schema");
                    createSchema.Start();

                    // Build schema
                    SchemaBuilder serviceBldr = new SchemaBuilder(RvtGuid);

                    // Set read and write access attributes and a name
                    serviceBldr.SetReadAccessLevel(AccessLevel.Application);
                    serviceBldr.SetWriteAccessLevel(AccessLevel.Application);
                    serviceBldr.SetApplicationGUID(RevitBimbot.ApplicationGuid);
                    serviceBldr.SetVendorId(RevitBimbot.VendorId);
                    serviceBldr.SetSchemaName("BimBotService");

                    // create fields for relevant attributes of services
                    FieldBuilder fieldBldr = serviceBldr.AddSimpleField(NameField, typeof(string));
                    fieldBldr.SetDocumentation("Name of the service.");
                    fieldBldr = serviceBldr.AddSimpleField(DescriptionField, typeof(string));
                    fieldBldr.SetDocumentation("Decription of the service.");
                    fieldBldr = serviceBldr.AddArrayField(InputsField, typeof(string));
                    fieldBldr.SetDocumentation("List of input types of the service.");
                    fieldBldr = serviceBldr.AddArrayField(OutputsField, typeof(string));
                    fieldBldr.SetDocumentation("List of output types the service.");
                    fieldBldr = serviceBldr.AddSimpleField(UrlField, typeof(string));
                    fieldBldr.SetDocumentation("Url of the service.");
                    fieldBldr = serviceBldr.AddArrayField(TriggersField, typeof(string));
                    fieldBldr.SetDocumentation("List of triggers that activate the service.");
                    fieldBldr = serviceBldr.AddSimpleField(ProviderField, typeof(string));
                    fieldBldr.SetDocumentation("Name of the Provider of the service.");
                    fieldBldr = serviceBldr.AddSimpleField(AuthorizationField, typeof(string));
                    fieldBldr.SetDocumentation("Code used for authorizing the service.");
                    fieldBldr = serviceBldr.AddSimpleField(IfcConfigurationField, typeof(string));
                    fieldBldr.SetDocumentation("IFC export configuration used when running the service.");

                    fieldBldr = serviceBldr.AddSimpleField(LastRunField, typeof(string));
                    fieldBldr.SetDocumentation("Last date the service was executed.");
                    fieldBldr = serviceBldr.AddSimpleField(ResultTypeField, typeof(string));
                    fieldBldr.SetDocumentation("Last result type delivered by the service.");
                    fieldBldr = serviceBldr.AddSimpleField(ResultDataField, typeof(string));
                    fieldBldr.SetDocumentation("Last results delivered by the service.");
                    RvtSchema = serviceBldr.Finish(); // register the subSchema object

                    createSchema.Commit();
                }
                else
                {
                    RvtSchema = Schema.Lookup(RvtGuid);
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(RvtGuid);
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Create a new Autodesk.Revit.DB.ExtensibleStorage.SchemaBuilder and Schema from
        /// the data in the SchemaWrapper.
        /// </summary>
        public void FinishSchema()
        {
            //Create the Autodesk.Revit.DB.ExtensibleStorage.SchemaBuilder that actually builds the schema
            m_SchemaBuilder = new SchemaBuilder(new Guid(m_SchemaDataWrapper.SchemaId));


            //We will add a new field to our schema from each FieldData object in our SchemaWrapper
            foreach (FieldData currentFieldData in m_SchemaDataWrapper.DataList)
            {
                //If the current field's type is a supported system type (int, string, etc...),
                //we can instantiate it with Type.GetType().  If the current field's type is a supported Revit API type
                //(XYZ, elementID, etc...), we need to call GetType from the RevitAPI.dll assembly object.
                Type fieldType = null;
                try
                {
                    fieldType = Type.GetType(currentFieldData.Type, true, true);
                }

                catch (Exception ex) //Get the type from the Revit API assembly if it is not a system type.
                {
                    Debug.WriteLine(ex.ToString());
                    try
                    {
                        //Get the field from the Revit API assembly.
                        fieldType = m_Assembly.GetType(currentFieldData.Type);
                    }

                    catch (Exception exx)
                    {
                        Debug.WriteLine("Error getting type: " + exx.ToString());
                        throw;
                    }
                }


                //Now that we have the data type of field we need to add, we need to call either
                //SchemaBuilder.AddSimpleField, AddArrayField, or AddMapField.

                FieldBuilder currentFieldBuilder = null;
                Guid         subSchemaId         = Guid.Empty;
                Type[]       genericParams       = null;


                if (currentFieldData.SubSchema != null)
                {
                    subSchemaId = new Guid(currentFieldData.SubSchema.Data.SchemaId);
                }

                //If our data type is a generic, it is an IList<> or an IDictionary<>, so it's an array or map type
                if (fieldType.IsGenericType)
                {
                    Type tGeneric = fieldType.GetGenericTypeDefinition(); //tGeneric will be either an IList<> or an IDictionary<>.

                    //Create an IList<> or an IDictionary<> to compare against tGeneric.
                    Type iDictionaryType = typeof(IDictionary <int, int>).GetGenericTypeDefinition();
                    Type iListType       = typeof(IList <int>).GetGenericTypeDefinition();

                    genericParams = fieldType.GetGenericArguments(); //Get the actual data type(s) stored in the field's IList<> or IDictionary<>
                    if (tGeneric == iDictionaryType)
                    {
                        //Pass the key and value type of our dictionary type to AddMapField.
                        currentFieldBuilder = m_SchemaBuilder.AddMapField(currentFieldData.Name, genericParams[0], genericParams[1]);
                    }
                    else if (tGeneric == iListType)
                    {
                        //Pass the value type of our list type to AddArrayField.
                        currentFieldBuilder = m_SchemaBuilder.AddArrayField(currentFieldData.Name, genericParams[0]);
                    }
                    else
                    {
                        throw new Exception("Generic type is neither IList<> nor IDictionary<>, cannot process.");
                    }
                }
                else
                {
                    //The simpler case -- just add field using a name and a System.Type.
                    currentFieldBuilder = m_SchemaBuilder.AddSimpleField(currentFieldData.Name, fieldType);
                }

                if ( //if we're dealing with an Entity as a simple field, map field, or list field and need to do recursion...
                    (fieldType == (typeof(Entity)))
                    ||
                    (fieldType.IsGenericType && ((genericParams[0] == (typeof(Entity))) || ((genericParams.Length > 1) && (genericParams[1] == typeof(Entity)))))
                    )
                {
                    currentFieldBuilder.SetSubSchemaGUID(subSchemaId); //Set the SubSchemaID if our field
                    currentFieldData.SubSchema.FinishSchema();         //Recursively create the schema for the subSchema.
                }

                if (!currentFieldData.Spec.Empty())
                {
                    currentFieldBuilder.SetSpec(currentFieldData.Spec);
                }
            }

            //Set all the top level data in the schema we are generating.
            m_SchemaBuilder.SetReadAccessLevel(this.Data.ReadAccess);
            m_SchemaBuilder.SetWriteAccessLevel(this.Data.WriteAccess);
            m_SchemaBuilder.SetVendorId(this.Data.VendorId);
            m_SchemaBuilder.SetApplicationGUID(new Guid(this.Data.ApplicationId));
            m_SchemaBuilder.SetDocumentation(this.Data.Documentation);
            m_SchemaBuilder.SetSchemaName(this.Data.Name);


            //Actually finish creating the Autodesk.Revit.DB.ExtensibleStorage.Schema.
            m_Schema = m_SchemaBuilder.Finish();
        }