/// <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(); } }
/// <summary> /// Get the 8 document header replacement fields from the current font and color settings /// </summary> private static string[] GetDocumentHeaderReplacementFields(ModelElement element, IVerbalizationSets <CoreVerbalizationSnippetType> snippets) { string[] retVal = myDocumentHeaderReplacementFields; if (retVal == null) { myDocumentHeaderReplacementFields = retVal = VerbalizationHelper.GetDocumentHeaderReplacementFields(element.Store, snippets); } return(retVal); }
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(); } } }
/// <summary> /// Initializes a new instance of ObjectTypeListReport /// </summary> /// <param name="model">The model for the report</param> /// <param name="objectTypeList">The object type list.</param> /// <param name="snippets">The snippets.</param> /// <param name="headerSnippet">The header snippet.</param> /// <param name="footerSnippet">The footer snippet.</param> /// <param name="reportContent">Content of the report.</param> public ObjectTypeListReport( ORMModel model, IList<ObjectType> objectTypeList, IVerbalizationSets<ReportVerbalizationSnippetType> snippets, ReportVerbalizationSnippetType headerSnippet, ReportVerbalizationSnippetType footerSnippet, VerbalizationReportContent reportContent) { myModel = model; myObjectTypeList = objectTypeList; mySnippets = snippets; myHeaderSnippet = headerSnippet; myFooterSnippet = footerSnippet; myReportContent = reportContent; }
/// <summary> /// Get the 8 document header replacement fields from the current font and color settings /// </summary> private static string[] GetDocumentHeaderReplacementFields(ModelElement element, IVerbalizationSets<CoreVerbalizationSnippetType> snippets) { string[] retVal = myDocumentHeaderReplacementFields; if (retVal == null) { // The replacement fields, pulled from VerbalizationGenerator.xsd //{0} font-family //{1} font-size //{2} predicate text color //{3} predicate text bold //{4} object name color //{5} object name bold //{6} formal item color //{7} formal item bold //{8} notes item color //{9} notes item bold //{10} refmode item color //{11} refmode item bold //{12} instance value item color //{13} instance value item bold IORMFontAndColorService colorService = ((IORMToolServices)element.Store).FontAndColorService; string boldWeight = snippets.GetSnippet(CoreVerbalizationSnippetType.VerbalizerFontWeightBold); string normalWeight = snippets.GetSnippet(CoreVerbalizationSnippetType.VerbalizerFontWeightNormal); retVal = new string[] { "Tahoma", "8", "darkgreen", normalWeight, "purple", normalWeight, "mediumblue", boldWeight, "brown", normalWeight, "darkgray", normalWeight, "brown", normalWeight }; using (Font font = colorService.GetFont(ORMDesignerColorCategory.Verbalizer)) { retVal[0] = font.FontFamily.Name; retVal[1] = (font.Size * 72f).ToString(CultureInfo.InvariantCulture); retVal[2] = ColorTranslator.ToHtml(colorService.GetForeColor(ORMDesignerColor.VerbalizerPredicateText)); retVal[3] = (0 != (colorService.GetFontStyle(ORMDesignerColor.VerbalizerPredicateText) & FontStyle.Bold)) ? boldWeight : normalWeight; retVal[4] = ColorTranslator.ToHtml(colorService.GetForeColor(ORMDesignerColor.VerbalizerObjectName)); retVal[5] = (0 != (colorService.GetFontStyle(ORMDesignerColor.VerbalizerObjectName) & FontStyle.Bold)) ? boldWeight : normalWeight; retVal[6] = ColorTranslator.ToHtml(colorService.GetForeColor(ORMDesignerColor.VerbalizerFormalItem)); retVal[7] = (0 != (colorService.GetFontStyle(ORMDesignerColor.VerbalizerFormalItem) & FontStyle.Bold)) ? boldWeight : normalWeight; retVal[8] = ColorTranslator.ToHtml(colorService.GetForeColor(ORMDesignerColor.VerbalizerNotesItem)); retVal[9] = (0 != (colorService.GetFontStyle(ORMDesignerColor.VerbalizerNotesItem) & FontStyle.Bold)) ? boldWeight : normalWeight; retVal[10] = ColorTranslator.ToHtml(colorService.GetForeColor(ORMDesignerColor.VerbalizerRefMode)); retVal[11] = (0 != (colorService.GetFontStyle(ORMDesignerColor.VerbalizerRefMode) & FontStyle.Bold)) ? boldWeight : normalWeight; retVal[12] = ColorTranslator.ToHtml(colorService.GetForeColor(ORMDesignerColor.VerbalizerInstanceValue)); retVal[13] = (0 != (colorService.GetFontStyle(ORMDesignerColor.VerbalizerInstanceValue) & FontStyle.Bold)) ? boldWeight : normalWeight; } myDocumentHeaderReplacementFields = retVal; } return myDocumentHeaderReplacementFields; }
/// <summary> /// Initializes a new instance of ObjectTypePageReport /// </summary> public ObjectTypePageReport(ObjectType objectType, VerbalizationReportContent reportContent, IVerbalizationSets<ReportVerbalizationSnippetType> snippets) { myObjectType = objectType; myReportContent = reportContent; mySnippets = snippets; }
/// <summary> /// Initializes a new instance of ORMSolutions.ORMArchitect.Core.ObjectModel.VerbalizationReportCallbackWriter /// </summary> public VerbalizationReportCallbackWriter(IDictionary<Type, IVerbalizationSets> snippetDictionary, TextWriter writer) : base((IVerbalizationSets<CoreVerbalizationSnippetType>)snippetDictionary[typeof(CoreVerbalizationSnippetType)], writer) { myReportSnippets = (IVerbalizationSets<ReportVerbalizationSnippetType>)snippetDictionary[typeof(ReportVerbalizationSnippetType)]; }
/// <summary> /// Initializes a new instance of FactTypeConstraintValidationListReport /// </summary> /// <param name="model">Context model</param> /// <param name="factTypeList">The fact type list.</param> /// <param name="reportContent">Content of the report.</param> /// <param name="snippets">The snippets.</param> public FactTypeConstraintValidationListReport(ORMModel model, IList<FactType> factTypeList, VerbalizationReportContent reportContent, IVerbalizationSets<ReportVerbalizationSnippetType> snippets) { myModel = model; myFactTypeList = factTypeList; mySnippets = snippets; myReportContent = reportContent; }
/// <summary> /// Initializes a new instance of VerbalizationReportTableOfContentsWrapper /// </summary> public VerbalizationReportTableOfContentsWrapper(VerbalizationReportContent reportContent, IVerbalizationSets<ReportVerbalizationSnippetType> snippets) { myReportContent = reportContent; mySnippets = snippets; }
/// <summary> /// Initializes a new instance of FactTypePageReport /// </summary> public FactTypePageReport(FactType factType, VerbalizationReportContent reportContent, IVerbalizationSets<ReportVerbalizationSnippetType> snippets) { myFactType = factType; myReportContent = reportContent; mySnippets = snippets; }