/// <summary> /// Changes the name of an expression element from one value to another. /// </summary> /// <param name="from">The name of the expression element that the caller wants to remap.</param> /// <param name="to">The name to which the caller wants to remap the expression element.</param> public void ChangeName(string from, string to) { if (!m_nameMap.ContainsKey(from)) { throw new ApplicationException(Msg_NameMapDoesntContainKey(from)); } ExpressionElement expressionElement = m_nameMap[from]; if (expressionElement != null) { DualModeString dms = expressionElement as DualModeString; if (dms != null) { dms.Name = to; m_nameMap.Remove(from); m_nameMap.Add(to, expressionElement); } } }
/// <summary> /// Registers a mapping of this string as a DualMode string, mapped under the provided Guid. /// This will be a string that represents a step or transition, and which is backed by a Guid so that the /// string can be changed (such as when a step is flattened up into its parent, and its name goes from, e.g. /// "Prepare-Step" to "B : Xfr_Liquid2.Prepare-Step". /// </summary> /// <param name="name">The name that is to become a DualMode string.</param> /// <param name="guid">The guid by which this element is to be known.</param> /// <returns> /// The newly-created (or preexisting, if it was there already) dual mode string element. /// </returns> public ExpressionElement RegisterMapping(string name, Guid guid) { bool guidIsAlreadyKnown = m_guidMap.ContainsKey(guid); bool nameIsAlreadyKnown = m_nameMap.ContainsKey(name); if (!nameIsAlreadyKnown && !guidIsAlreadyKnown) { #region Create a Dual Mode String and add it into the two maps. DualModeString dms = new DualModeString(guid, name); m_nameMap.Add(name, dms); m_guidMap.Add(guid, dms); #endregion } else if (nameIsAlreadyKnown && !guidIsAlreadyKnown) { #region There's already one with this name, but it's got a different guid. int i = 1; while (m_nameMap.ContainsKey(name + "_" + i)) { i++; } name = name + "_" + i; DualModeString dms = new DualModeString(guid, name); m_nameMap.Add(name, dms); m_guidMap.Add(guid, dms); #endregion } else if (!nameIsAlreadyKnown && guidIsAlreadyKnown) { #region There's already one with this Guid, but it has a different name. string msg = "Attempting to register a mapping between " + name + " and " + guid + " in a ParticipantDirectory, but the guid is already correlated to a different string, " + m_guidMap[guid].Name + "."; throw new ApplicationException(msg); #endregion } else { // Both name and guid are known - object is already added in. } return(m_guidMap[guid]); }