private void buttonAdd_Click(object sender, RoutedEventArgs e) { try { if (null != dataGridSource.SelectedItem && null != dataGridRecipient.SelectedItem) { var sItemInfo = (ItemInfo)dataGridSource.SelectedItem; var rItemInfo = (ItemInfo)dataGridRecipient.SelectedItem; if (rItemInfo.Enabled) { var mapItemInfo = new MapItemInfo(); mapItemInfo.MapItemType = currentType; mapItemInfo.SourceModelId = sModelInfo.ModelId; mapItemInfo.SourceItemId = sItemInfo.ItemId; mapItemInfo.SourceItemName = sItemInfo.ItemName; mapItemInfo.RecipientModelId = rModelInfo.ModelId; mapItemInfo.RecipientItemId = rItemInfo.ItemId; mapItemInfo.RecipientItemName = rItemInfo.ItemName; ViewConfig.MapItems.Add(mapItemInfo); if (sourceItems.ContainsKey(sItemInfo.ItemId) && recipientItems.ContainsKey(rItemInfo.ItemId)) { sItemInfo.Mapped = true; sourceItems.Remove(sItemInfo.ItemId); sourceItems.Add(sItemInfo.ItemId, sItemInfo); rItemInfo.Mapped = true; recipientItems.Remove(rItemInfo.ItemId); recipientItems.Add(rItemInfo.ItemId, rItemInfo); } DisplayItems(); } else { MessageBox.Show("The type of recipient item is different from the source item.\nPlease select a valid item.", "Type Mismatched", MessageBoxButton.OK, MessageBoxImage.Information); } } else { MessageBox.Show("Please select a source item and a recipient item to create a link.", "Missing Selection", MessageBoxButton.OK, MessageBoxImage.Information); } } catch (Exception ex) { MessageBox.Show("Failed to add a link.\n" + ex.Message, "Add Links", MessageBoxButton.OK, MessageBoxImage.Warning); } }
public static ViewConfiguration GetViewConfiguration(Document doc) { var viewConfig = new ViewConfiguration(); try { if (null == m_schema) { m_schema = CreateSchema(); } if (null != m_schema) { var savedStorage = GetViewConfigurationStorage(doc, m_schema); if (savedStorage.Count > 0) { var storage = savedStorage.First(); var entity = storage.GetEntity(m_schema); viewConfig.ApplyWorksetVisibility = entity.Get <bool>(m_schema.GetField(s_WorksetVisibility)); var mapItems = new List <MapItemInfo>(); var subEntities = entity.Get <IList <Entity> >(m_schema.GetField(s_MapItems)); foreach (var subE in subEntities) { var mapItem = new MapItemInfo(); mapItem.SourceModelId = subE.Get <string>(subSchema.GetField(s_SourceModelId)); mapItem.RecipientModelId = subE.Get <string>(subSchema.GetField(s_RecipientModelId)); mapItem.MapItemType = (MapType)Enum.Parse(typeof(MapType), subE.Get <string>(subSchema.GetField(s_MapItemType))); mapItem.SourceItemId = subE.Get <int>(subSchema.GetField(s_SourceItemId)); mapItem.RecipientItemId = subE.Get <int>(subSchema.GetField(s_RecipientItemId)); mapItem.SourceItemName = subE.Get <string>(subSchema.GetField(s_SourceItemName)); mapItem.RecipientItemName = subE.Get <string>(subSchema.GetField(s_RecipientItemName)); mapItems.Add(mapItem); } viewConfig.MapItems = mapItems; } } } catch (Exception ex) { MessageBox.Show("Failed to get view configuration.\n" + ex.Message, "Get View Configuration", MessageBoxButton.OK, MessageBoxImage.Warning); } return(viewConfig); }