Example #1
0
        private static DataStorage GetSettingsDataStorage(Document doc)
        {
            // Retrieve all data storages from project
            var collector = new FilteredElementCollector(doc);

            var dataStorages = collector.OfClass(typeof(DataStorage));

            // Find setting data storage
            foreach (DataStorage dataStorage in dataStorages)
            {
                var settingIdEntity = dataStorage.GetEntity(DSUniqueSchemaStreamStateStorage.GetSchema());

                if (!settingIdEntity.IsValid())
                {
                    continue;
                }

                var id = settingIdEntity.Get <Guid>("Id");

                if (!id.Equals(ID))
                {
                    continue;
                }

                return(dataStorage);
            }
            return(null);
        }
Example #2
0
        /// <summary>
        /// Writes the stream states to the current document.
        /// </summary>
        /// <param name="doc"></param>
        /// <param name="wrap"></param>
        public static void WriteStreamStateList(Document doc, List <StreamState> streamStates)
        {
            var ds = GetSettingsDataStorage(doc);

            if (ds == null)
            {
                ds = DataStorage.Create(doc);
            }

            var streamStatesEntity = new Entity(StreamStateListSchema.GetSchema());

            streamStatesEntity.Set("StreamStates", JsonConvert.SerializeObject(streamStates) as string);

            var idEntity = new Entity(DSUniqueSchemaStreamStateStorage.GetSchema());

            idEntity.Set("Id", ID);

            ds.SetEntity(idEntity);
            ds.SetEntity(streamStatesEntity);
        }