Esempio n. 1
0
        /// <summary>
        /// Writes the stream states to the current schema.
        /// </summary>
        /// <param name="streamStates"></param>
        public static void WriteStreamStateList(DgnFile File, List <StreamState> streamStates)
        {
            DgnECManager       Manager = DgnECManager.Manager;
            FindInstancesScope scope   = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));

            IECSchema schema  = RetrieveSchema(File, scope);
            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);

            var data = JsonConvert.SerializeObject(streamStates) as string;
            StandaloneECDInstance _instance = instanceEnabler.SharedWipInstance;

            _instance.SetAsString(propertyName, data);
            instanceEnabler.CreateInstanceOnFile(File, _instance);
        }
Esempio n. 2
0
        public void FindInstances()
        {
            DgnECManager       manager = DgnECManager.Manager;
            FindInstancesScope scope   = FindInstancesScope.CreateScope(Program.GetActiveDgnFile(), new FindInstancesScopeOption(DgnECHostType.Element, true));
            ECQuery            query   = new ECQuery(Extension.Utilities.GetActiveModelAllClasses());

            query.SelectClause.SelectAllProperties = true;
            manager.FindInstances(scope, query);
            //每次寻找实例不对啊,需要打开Property窗口后才能正确显示
            using (DgnECInstanceCollection ecInstances = manager.FindInstances(scope, query))
            {
                foreach (var ecin in ecInstances)
                {
                    foreach (IECProperty itemProp in ecin.ClassDefinition.Properties(false))
                    {
                        var instanceitem = new Instance();
                        instanceitem.ClassName    = ecin.ClassDefinition.DisplayLabel;
                        instanceitem.PropertyName = itemProp.Name;
                        string type = itemProp.Type.Name.ToLower();
                        instanceitem.TypeName = type;
                        IECPropertyValue propvalue = ecin.GetPropertyValue(itemProp.Name);

                        switch (type)
                        {
                        case "string":
                            instanceitem.PropertyValue = (propvalue != null) ? propvalue.StringValue : "";
                            break;

                        case "boolean":
                            instanceitem.PropertyValue = (propvalue != null) ? propvalue.StringValue : "";
                            break;

                        case "int":
                            instanceitem.PropertyValue = (propvalue != null) ? propvalue.IntValue.ToString() : "";
                            break;

                        case "double":
                            instanceitem.PropertyValue = (propvalue != null) ? propvalue.DoubleValue.ToString() : "";
                            break;
                        }
                        Instances.Add(instanceitem);
                    }
                }
            }
        }
Esempio n. 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);
            }
Esempio n. 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);
            }
Esempio n. 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);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Returns all the speckle stream states present in the custom schema (schema is attached to file).
        /// </summary>
        /// <param name="schema"></param>
        /// <returns></returns>
        public static List <StreamState> ReadState(ECSchema schema)
        {
            DgnFile      File    = Session.Instance.GetActiveDgnFile();
            DgnECManager Manager = DgnECManager.Manager;

            try
            {
                ECQuery readWidget = new ECQuery(schema.GetClass(className));
                readWidget.SelectClause.SelectAllProperties = true;

                FindInstancesScope scope = FindInstancesScope.CreateScope(File, new FindInstancesScopeOption(DgnECHostType.All));

                var states = new List <StreamState>();
                using (DgnECInstanceCollection ecInstances = Manager.FindInstances(scope, readWidget))
                {
                    foreach (IDgnECInstance instance in ecInstances)
                    {
                        var id = instance["Id"].StringValue;
                        var streamStateData = instance["StreamData"].StringValue;
                        var state           = JsonConvert.DeserializeObject <StreamState>(streamStateData);
                        states.Add(state);
                    }
                }

                if (states != null)
                {
                    states.ForEach(x => x.Initialise(true));
                }

                return(states);
            }
            catch (Exception e)
            {
                return(new List <StreamState>());
            }
        }