/// <summary> /// Using the current verbalization settings, verbalize the specified /// elements into the output text writer. /// </summary> /// <param name="store">The context <see cref="Store"/> returned by <see cref="ModelLoader.Load(Stream)"/>.</param> /// <param name="writer">An externally allocated writer to receive the output.</param> /// <param name="target">The name of the target to verbalize. The target must match /// a known target as registered with the <see cref="VerbalizationTargetProviderAttribute"/> on /// a loaded core or extension model.</param> /// <param name="elements">One or more elements to verbalize.</param> /// <param name="showNegative">Generate a negative verbalization if available.</param> public void Verbalize(Store store, TextWriter writer, string target, ICollection elements, bool showNegative) { IDictionary <Type, IVerbalizationSets> snippetsDictionary = null; IDictionary <string, object> options = null; IVerbalizationSets <CoreVerbalizationSnippetType> snippets = null; IExtensionVerbalizerService extensionVerbalizer = null; VerbalizationCallbackWriter callbackWriter = null; bool firstCallPending = true; Dictionary <IVerbalize, IVerbalize> alreadyVerbalized = new Dictionary <IVerbalize, IVerbalize>(); Dictionary <object, object> locallyVerbalized = new Dictionary <object, object>(); if (elements != null) { foreach (object elemIter in elements) { if (snippetsDictionary == null) { IORMToolServices toolServices = (IORMToolServices)store; extensionVerbalizer = toolServices.ExtensionVerbalizerService; options = toolServices.VerbalizationOptions; snippetsDictionary = toolServices.GetVerbalizationSnippetsDictionary(target); snippets = (IVerbalizationSets <CoreVerbalizationSnippetType>)snippetsDictionary[typeof(CoreVerbalizationSnippetType)]; callbackWriter = new VerbalizationCallbackWriter(snippets, writer, VerbalizationHelper.GetDocumentHeaderReplacementFields(store, snippets)); } object elem = elemIter; ModelElement mel = elem as ModelElement; PresentationElement pel; if ((mel != null) && null != (pel = mel as PresentationElement)) { IRedirectVerbalization shapeRedirect = pel as IRedirectVerbalization; if (null == (shapeRedirect = pel as IRedirectVerbalization) || null == (elem = shapeRedirect.SurrogateVerbalizer as ModelElement)) { elem = mel = pel.ModelElement; } } if (elem != null && (mel == null || !mel.IsDeleted)) { locallyVerbalized.Clear(); VerbalizationHelper.VerbalizeElement( elem, snippetsDictionary, extensionVerbalizer, options, target, alreadyVerbalized, locallyVerbalized, (showNegative ? VerbalizationSign.Negative : VerbalizationSign.Positive) | VerbalizationSign.AttemptOppositeSign, callbackWriter, true, ref firstCallPending); } } } if (!firstCallPending) { // Write footer callbackWriter.WriteDocumentFooter(); // Clear cache alreadyVerbalized.Clear(); } }
private void UpdateVerbalization() { if (CurrentORMSelectionContainer == null) { return; } if (myStringWriter != null) { myStringWriter.GetStringBuilder().Length = 0; ICollection selectedObjects = base.GetSelectedComponents(); IDictionary <Type, IVerbalizationSets> snippetsDictionary = null; IDictionary <string, object> options = null; IVerbalizationSets <CoreVerbalizationSnippetType> snippets = null; IExtensionVerbalizerService extensionVerbalizer = null; VerbalizationCallbackWriter callbackWriter = null; bool showNegative = ORMDesignerPackage.VerbalizationWindowSettings.ShowNegativeVerbalizations; bool firstCallPending = true; Dictionary <IVerbalize, IVerbalize> alreadyVerbalized = myAlreadyVerbalized; if (alreadyVerbalized == null) { alreadyVerbalized = new Dictionary <IVerbalize, IVerbalize>(); myAlreadyVerbalized = alreadyVerbalized; } else { alreadyVerbalized.Clear(); } Dictionary <object, object> locallyVerbalized = myLocallyVerbalized; if (locallyVerbalized == null) { locallyVerbalized = new Dictionary <object, object>(); myLocallyVerbalized = locallyVerbalized; } if (selectedObjects != null) { foreach (object melIter in selectedObjects) { ModelElement mel = melIter as ModelElement; PresentationElement pel = mel as PresentationElement; ModelElement secondMel = null; if (pel != null) { IRedirectVerbalization shapeRedirect = pel as IRedirectVerbalization; bool redirected = null != (shapeRedirect = pel as IRedirectVerbalization) && null != (mel = shapeRedirect.SurrogateVerbalizer as ModelElement); if (!redirected) { mel = pel.ModelElement; } if (pel is IVerbalizeCustomChildren || (!redirected && pel is IVerbalize || pel is IVerbalizeChildren)) { secondMel = mel; mel = pel; } } while (mel != null && !mel.IsDeleted) { if (snippetsDictionary == null) { Store store = Utility.ValidateStore(mel.Store); if (store == null) { break; } IORMToolServices toolServices = (IORMToolServices)store; extensionVerbalizer = toolServices.ExtensionVerbalizerService; options = toolServices.VerbalizationOptions; snippetsDictionary = toolServices.GetVerbalizationSnippetsDictionary(ORMCoreDomainModel.VerbalizationTargetName); snippets = (IVerbalizationSets <CoreVerbalizationSnippetType>)snippetsDictionary[typeof(CoreVerbalizationSnippetType)]; callbackWriter = new VerbalizationCallbackWriter(snippets, myStringWriter, GetDocumentHeaderReplacementFields(mel, snippets)); } locallyVerbalized.Clear(); VerbalizationHelper.VerbalizeElement( mel, snippetsDictionary, extensionVerbalizer, options, ORMCoreDomainModel.VerbalizationTargetName, alreadyVerbalized, locallyVerbalized, (showNegative ? VerbalizationSign.Negative : VerbalizationSign.Positive) | VerbalizationSign.AttemptOppositeSign, callbackWriter, true, ref firstCallPending); if (secondMel != null) { mel = secondMel; secondMel = null; } else { mel = null; } } } } if (!firstCallPending) { // Write footer callbackWriter.WriteDocumentFooter(); // Clear cache alreadyVerbalized.Clear(); } else { // Nothing happened, put in text for nothing happened } WebBrowser browser = myWebBrowser; if (browser != null) { browser.DocumentText = myStringWriter.ToString(); } } }