public static KeynoteConfiguration GetConfiguration(Document doc) { KeynoteConfiguration config = new KeynoteConfiguration(); try { if (null == configSchema) { configSchema = CreateConfigSchema(); } if (null != configSchema) { IList <DataStorage> savedStorage = GetStorage(doc, configSchema); if (savedStorage.Count > 0) { DataStorage storage = savedStorage.First(); Entity entity = storage.GetEntity(configSchema); config.ProjectId = entity.Get <string>(configSchema.GetField(s_ProjectId)); config.KeynoteSetId = entity.Get <string>(configSchema.GetField(s_KeynoteSetId)); } } } catch (Exception ex) { MessageBox.Show("Failed to get configuration of Keynote Editor.\n" + ex.Message, "Get Configuration", MessageBoxButton.OK, MessageBoxImage.Warning); } return(config); }
public static bool StoreConfiguration(Document doc, KeynoteConfiguration config) { bool stored = false; try { if (null == configSchema) { configSchema = CreateConfigSchema(); } if (null != configSchema) { IList <DataStorage> savedStorage = GetStorage(doc, configSchema); if (savedStorage.Count > 0) { using (Transaction trans = new Transaction(doc)) { trans.Start("Delete Storage"); try { var storageIds = from storage in savedStorage select storage.Id; if (storageIds.Count() > 0) { foreach (ElementId storageId in storageIds) { doc.Delete(storageId); } } trans.Commit(); } catch (Exception ex) { trans.RollBack(); string message = ex.Message; } } } using (Transaction trans = new Transaction(doc)) { trans.Start("Store Storage"); try { DataStorage dStorage = DataStorage.Create(doc); Entity entity = new Entity(configSchemaId); entity.Set <string>(s_ProjectId, config.ProjectId); entity.Set <string>(s_KeynoteSetId, config.KeynoteSetId); dStorage.SetEntity(entity); trans.Commit(); } catch (Exception ex) { trans.RollBack(); string message = ex.Message; } } } } catch (Exception ex) { MessageBox.Show("Failed to store configuration.\n" + ex.Message, "Store Configuration", MessageBoxButton.OK, MessageBoxImage.Warning); } return(stored); }