// RENAME -- symbol-name new-symbol-name private void ProcessRename(string[] commands) { DataDictionaryObject symbol = GetSymbolFromName(commands[1], SymbolTypes.AllSupported); DataDictionary dictionary = GetDataDictionaryFromSymbol(symbol); string oldName = symbol.Name; string newName = commands[2].ToUpper(); CheckIfValidNewName(dictionary, newName); // a couple things if changing the name of a dictionary if (symbol == dictionary) { _dictionaries.Remove(dictionary.Name); _dictionarySymbols.Remove(dictionary.Name); _dictionaries.Add(newName, dictionary); } // change the name symbol.Name = newName; LoadDictionarySymbols(dictionary); RefreshSymbolParents(); SetOutputSuccess(String.Format(Messages.RenameSuccess, oldName, newName)); }
// LABEL -- symbol-name label private void ProcessLabel(string[] commands) { DataDictionaryObject symbol = GetSymbolFromName(commands[1], SymbolTypes.AllSupported); symbol.Label = commands[2]; SetOutputSuccess(String.Format(Messages.LabelModified, symbol.Name, commands[2])); }
// REMOVE -- symbol-name private void ProcessRemove(string[] commands) { DataDictionaryObject symbol = GetSymbolFromName(commands[1], SymbolTypes.Record | SymbolTypes.Item | SymbolTypes.ValueSet); DataDictionary dictionary = null; if (symbol is Record) { Record record = (Record)symbol; Level level = record.ParentLevel; dictionary = record.ParentDictionary; if (level.IDs == record) { throw new Exception(Messages.RemoveIDsDisabled); } level.Records.Remove(record); SetOutputSuccess(String.Format(Messages.RemoveRecord, record.Name, record.Items.Count)); } else if (symbol is Item) { Item item = (Item)symbol; Record record = item.ParentRecord; dictionary = item.ParentDictionary; record.Items.Remove(item); // delete any subitems associated with the item foreach (Item subitem in item.Subitems) { record.Items.Remove(subitem); } DataDictionaryWorker.CalculateItemPositions(dictionary); DataDictionaryWorker.CalculateRecordLengths(dictionary); DataDictionaryWorker.RemoveBrokenValueSetLinks(dictionary); SetOutputSuccess(String.Format(Messages.RemoveItem, item.Name, record.Name)); } else // ValueSet { ValueSet vs = (ValueSet)symbol; Item item = vs.ParentItem; dictionary = vs.ParentDictionary; item.ValueSets.Remove(vs); DataDictionaryWorker.RemoveBrokenValueSetLinks(dictionary); SetOutputSuccess(String.Format(Messages.RemoveValueSet, vs.Name, item.Name)); } LoadDictionarySymbols(dictionary); RefreshSymbolParents(); }
private DataDictionary GetDataDictionaryFromSymbol(DataDictionaryObject symbol) { return(symbol is DataDictionary ? (DataDictionary)symbol : symbol is Level ? ((Level)symbol).ParentDictionary : symbol is Record ? ((Record)symbol).ParentDictionary : symbol is Item ? ((Item)symbol).ParentDictionary : symbol is ValueSet ? ((ValueSet)symbol).ParentDictionary : null); }