public static void UpdateElementIds(Document doc, ColorEditorSettings settings) { try { if (null == m_schema) { m_schema = CreateSchema(); } if (null != m_schema) { IList <DataStorage> savedStorage = GetSettingStorage(doc, m_schema); if (savedStorage.Count > 0) { using (Transaction trans = new Transaction(doc)) { trans.Start("Update ElementIds in the data storage."); try { DataStorage storage = savedStorage.First(); Entity entity = storage.GetEntity(m_schema); if (settings.ColoredElements.Count > 0) { IDictionary <string, Entity> mapOfEntities = new Dictionary <string, Entity>(); foreach (string schemeId in settings.ColoredElements.Keys) { IList <ElementId> elementIds = settings.ColoredElements[schemeId]; Entity subEntity = new Entity(subSchemaId); subEntity.Set <IList <ElementId> >(s_ElementIds, elementIds); mapOfEntities.Add(schemeId, subEntity); } entity.Set <IDictionary <string, Entity> >(s_ColoredElementIds, mapOfEntities); storage.SetEntity(entity); } trans.Commit(); } catch (Exception ex) { trans.RollBack(); MessageBox.Show("Failed to set element Ids in the data storage.\n" + ex.Message, "Update Element Ids", MessageBoxButton.OK, MessageBoxImage.Warning); } } } } } catch (Exception ex) { MessageBox.Show("Failed to update element Ids in the extensible storage.\n" + ex.Message, "Update Element Ids", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public static void UpdatePath(Document doc, ColorEditorSettings settings) { try { if (null == m_schema) { m_schema = CreateSchema(); } if (null != m_schema) { IList <DataStorage> savedStorage = GetSettingStorage(doc, m_schema); if (savedStorage.Count > 0) { using (Transaction trans = new Transaction(doc)) { trans.Start("Update BCF Path in the data storage."); try { DataStorage storage = savedStorage.First(); Entity entity = storage.GetEntity(m_schema); if (!string.IsNullOrEmpty(settings.BCFPath)) { entity.Set <string>(s_BCFPath, settings.BCFPath); storage.DeleteEntity(m_schema); storage.SetEntity(entity); } trans.Commit(); } catch (Exception ex) { trans.RollBack(); MessageBox.Show("Failed to set BCF path in the data storage.\n" + ex.Message, "Update Path", MessageBoxButton.OK, MessageBoxImage.Warning); } } } } } catch (Exception ex) { MessageBox.Show("Failed to update the bcf path in the extensible storage.\n" + ex.Message, "Update BCF Path", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public static ColorEditorSettings ReadDataStorage(Document doc) { ColorEditorSettings settings = new ColorEditorSettings(); try { if (null == m_schema) { m_schema = CreateSchema(); } if (null != m_schema) { IList <DataStorage> savedStorage = GetSettingStorage(doc, m_schema); if (savedStorage.Count > 0) { Entity savedSetting = savedStorage.First().GetEntity(m_schema); settings.BCFPath = savedSetting.Get <string>(m_schema.GetField(s_BCFPath)); var mapField = savedSetting.Get <IDictionary <string, Entity> >(m_schema.GetField(s_ColoredElementIds)); if (null != mapField) { IDictionary <string, IList <ElementId> > dictionary = new Dictionary <string, IList <ElementId> >(); foreach (string schemeId in mapField.Keys) { Entity entity = mapField[schemeId]; IList <ElementId> elementIds = entity.Get <IList <ElementId> >(s_ElementIds); if (null != elementIds && !dictionary.ContainsKey(schemeId)) { dictionary.Add(schemeId, elementIds); } } settings.ColoredElements = dictionary; } } } } catch (Exception ex) { MessageBox.Show("Failed to read data storage for the Color Editor.\n" + ex.Message, "Read Data Storage", MessageBoxButton.OK, MessageBoxImage.Warning); } return(settings); }