示例#1
0
        private static ECSchema RetrieveSchema(DgnFile File, FindInstancesScope scope)
        {
            DgnECManager Manager      = DgnECManager.Manager;
            DgnModel     model        = Session.Instance.GetActiveDgnModel();
            var          schemas      = (List <string>)Manager.DiscoverSchemasForModel(model, ReferencedModelScopeOption.All, false);
            var          schemaString = schemas.Where(x => x.Contains(schemaName)).FirstOrDefault();

            if (schemaString != null)
            {
                try
                {
                    IECSchema schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);
                    return((ECSchema)schema);
                }
                catch (Exception e)
                {
                    return(null);
                }
            }

            else
            {
                return(CreateSchema(File));
            }
        }
示例#2
0
            public static ECSchema RetrieveSchema()
            {
                DgnFile      File    = Session.Instance.GetActiveDgnFile();
                DgnECManager Manager = DgnECManager.Manager;

                FindInstancesScope scope  = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));
                IECSchema          schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);

                return((ECSchema)schema);
            }
示例#3
0
            public static DgnECInstanceCollection RetrieveInstances()
            {
                DgnFile      File    = Session.Instance.GetActiveDgnFile();
                DgnECManager Manager = DgnECManager.Manager;

                FindInstancesScope scope   = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));
                IECSchema          schema  = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);
                IECClass           ecClass = schema.GetClass(className);

                ECQuery readWidget = new ECQuery(ecClass);

                readWidget.SelectClause.SelectAllProperties = true;
                DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget);

                return(instances);
            }
示例#4
0
            public static IDgnECInstance RetrieveInstance(StreamState streamState)
            {
                DgnFile      File    = Session.Instance.GetActiveDgnFile();
                DgnECManager Manager = DgnECManager.Manager;

                FindInstancesScope scope   = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));
                IECSchema          schema  = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);
                IECClass           ecClass = schema.GetClass(className);

                ECQuery readWidget = new ECQuery(ecClass);

                readWidget.SelectClause.SelectAllProperties = true;
                DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget);

                var instance = instances.Where(x => x["Id"].StringValue == streamState.Stream.id).FirstOrDefault();

                return(instance);
            }
示例#5
0
        /// <summary>
        /// Writes the stream states to the current schema.
        /// </summary>
        /// <param name="streamStates"></param>
        public static void WriteStreamStateList(List <StreamState> streamStates)
        {
            DgnFile      File    = Session.Instance.GetActiveDgnFile();
            DgnECManager Manager = DgnECManager.Manager;

            FindInstancesScope scope  = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));
            IECSchema          schema = Manager.LocateSchemaInScope(scope, schemaName, 1, 0, SchemaMatchType.Latest);

            if (schema == null)
            {
                schema = StreamStateListSchema.GetSchema();
            }

            IECClass ecClass = schema.GetClass(className);

            ECQuery readWidget = new ECQuery(ecClass);

            readWidget.SelectClause.SelectAllProperties = true;

            using (DgnECInstanceCollection instances = Manager.FindInstances(scope, readWidget))
            {
                foreach (IDgnECInstance instance in instances)
                {
                    instance.Delete();
                }
            }

            DgnECInstanceEnabler instanceEnabler = Manager.ObtainInstanceEnabler(File, ecClass);

            foreach (var streamState in streamStates)
            {
                var data = JsonConvert.SerializeObject(streamState) as string;
                StandaloneECDInstance instance = instanceEnabler.SharedWipInstance;

                instance.SetAsString("Id", streamState.Stream.id);
                instance.SetAsString("StreamData", data);

                instanceEnabler.CreateInstanceOnFile(File, instance);
            }
        }