/// <summary> /// Contribute additively to initialization code for the TextTransformation generated class. /// </summary> /// <remarks> /// This code will be added before the call to the base class. /// </remarks> /// <param name="directiveName"></param> /// <param name="codeBuffer"></param> /// <param name="languageProvider"></param> /// <param name="requiresArguments"></param> /// <param name="providesArguments"></param> protected override void GeneratePreInitializationCode(string directiveName, global::System.Text.StringBuilder codeBuffer, global::System.CodeDom.Compiler.CodeDomProvider languageProvider, global::System.Collections.Generic.IDictionary <string, string> requiresArguments, global::System.Collections.Generic.IDictionary <string, string> providesArguments) { if ((global::System.StringComparer.OrdinalIgnoreCase.Compare(directiveName, supportedDirectiveName) == 0)) { if (languageProvider != null) { global::System.CodeDom.Compiler.CodeGeneratorOptions options = new global::System.CodeDom.Compiler.CodeGeneratorOptions(); options.BlankLinesBetweenMembers = true; options.IndentString = " "; options.VerbatimOrder = true; options.BracingStyle = "C"; using (global::System.IO.StringWriter writer = new global::System.IO.StringWriter(codeBuffer, global::System.Globalization.CultureInfo.InvariantCulture)) { global::System.CodeDom.CodeExpressionStatement addModel = new global::System.CodeDom.CodeExpressionStatement( new global::System.CodeDom.CodeMethodInvokeExpression( new global::System.CodeDom.CodeMethodReferenceExpression( new global::System.CodeDom.CodeThisReferenceExpression(), "AddDomainModel"), new global::System.CodeDom.CodePropertyReferenceExpression( new global::System.CodeDom.CodeTypeReferenceExpression(typeof(PatternModelReader)), "DomainModelType"))); languageProvider.GenerateCodeFromStatement(addModel, writer, options); } } } }
/// <summary> /// Contribute additively to initialization code for the TextTransformation generated class. /// </summary> /// <remarks> /// This code will be added before the call to the base class. /// </remarks> /// <param name="directiveName"></param> /// <param name="codeBuffer"></param> /// <param name="languageProvider"></param> /// <param name="requiresArguments"></param> /// <param name="providesArguments"></param> protected override void GeneratePreInitializationCode(string directiveName, global::System.Text.StringBuilder codeBuffer, global::System.CodeDom.Compiler.CodeDomProvider languageProvider, global::System.Collections.Generic.IDictionary <string, string> requiresArguments, global::System.Collections.Generic.IDictionary <string, string> providesArguments) { if ((global::System.StringComparer.OrdinalIgnoreCase.Compare(directiveName, supportedDirectiveName) == 0)) { if (languageProvider != null) { string[] domainModels = { "Microsoft.VisualStudio.Modeling.Diagrams.CoreDesignSurfaceDomainModel", "BizTalkMessaging.BizTalkMessagingDomainModel", }; global::System.CodeDom.Compiler.CodeGeneratorOptions options = new global::System.CodeDom.Compiler.CodeGeneratorOptions(); options.BlankLinesBetweenMembers = true; options.IndentString = " "; options.VerbatimOrder = true; options.BracingStyle = "C"; using (global::System.IO.StringWriter writer = new global::System.IO.StringWriter(codeBuffer, global::System.Globalization.CultureInfo.InvariantCulture)) { foreach (string domainModel in domainModels) { global::System.CodeDom.CodeExpressionStatement addModel = new global::System.CodeDom.CodeExpressionStatement(new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "AddDomainModel"), new global::System.CodeDom.CodeTypeOfExpression(domainModel))); languageProvider.GenerateCodeFromStatement(addModel, writer, options); } } } } }
InferDeduceSchema ( string data ) { global::System.Xml.Schema.XmlSchema schema = null; //Begin parsing source XML document global::System.Xml.XmlDocument doc = new global::System.Xml.XmlDocument(); try { //Assume string XML doc.LoadXml(data); } catch { //String XML load failed. Try loading as a file path try { doc.Load(data); } catch { throw new global::System.Xml.Schema.XmlSchemaException("XML document is not well-formed."); } } global::System.Xml.XmlElement root = doc.DocumentElement; global::System.Xml.XmlReader reader = null; reader = global::System.Xml.XmlReader.Create(new System.IO.StringReader(data)); global::System.Xml.Schema.XmlSchemaSet schema_set = null; schema_set = new global::System.Xml.Schema.XmlSchemaSet(); global::System.Xml.Schema.XmlSchemaInference schema_inferred = null; schema_inferred = new global::System.Xml.Schema.XmlSchemaInference(); schema_set = schema_inferred.InferSchema(reader); foreach (global::System.Xml.Schema.XmlSchema s in schema_set.Schemas()) { using (global::System.IO.StringWriter sw = new global::System.IO.StringWriter()) { using (global::System.Xml.XmlWriter writer = global::System.Xml.XmlWriter.Create(sw)) { s.Write(writer); } } } return //( (schema // types: types //) ); }
public string SerializeMarshall <T>(T t) { string json = null; using (global::System.IO.StringWriter output = new global::System.IO.StringWriter()) { global::Jil.JSON.Serialize(t, output); json = output.ToString(); } return(json); }
public async Task <string> SerializeMarshallAsync <T>(T t) { global::YamlDotNet.Serialization.Serializer serializer = null; serializer = new global::YamlDotNet.Serialization.Serializer(); var yaml = new System.Text.StringBuilder(); //await using global::System.IO.StringWriter textWriter = new global::System.IO.StringWriter(yaml); serializer.Serialize(textWriter, t, typeof(T)); return(yaml.ToString()); }
protected override void GeneratePostInitializationCode(string directiveName, global::System.Text.StringBuilder codeBuffer, global::System.CodeDom.Compiler.CodeDomProvider languageProvider, global::System.Collections.Generic.IDictionary <string, string> requiresArguments, global::System.Collections.Generic.IDictionary <string, string> providesArguments) { if ((global::System.StringComparer.OrdinalIgnoreCase.Compare(directiveName, supportedDirectiveName) == 0)) { // We check the encoding of the model file, and ask the host to use that // encoding to write the output. This is to make sure we use the correct encoding // if the model file contains international characters that could be used in // the template output. string fileName = requiresArguments[requiresFileParameter]; if (!string.IsNullOrEmpty(fileName) && global::System.IO.File.Exists(fileName)) { Host.SetOutputEncoding(VSTextTemplating::EncodingHelper.GetEncoding(fileName), false); } if (languageProvider != null) { global::System.CodeDom.CodeMethodInvokeExpression invokeLoad; global::System.String transactionName = providesArguments[providesModelParameter].ToLower(global::System.Globalization.CultureInfo.InvariantCulture) + "Transaction"; global::System.CodeDom.CodeVariableDeclarationStatement transactionDeclaration = new global::System.CodeDom.CodeVariableDeclarationStatement(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::Transaction)), transactionName, new global::System.CodeDom.CodePrimitiveExpression(null)); global::System.CodeDom.CodeStatement finallyStatement = new global::System.CodeDom.CodeConditionStatement(new global::System.CodeDom.CodeBinaryOperatorExpression(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), global::System.CodeDom.CodeBinaryOperatorType.IdentityInequality, new global::System.CodeDom.CodePrimitiveExpression(null)), new global::System.CodeDom.CodeExpressionStatement(new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), "Dispose"))); global::System.Collections.Generic.List <global::System.CodeDom.CodeStatement> txTryStatements = new global::System.Collections.Generic.List <global::System.CodeDom.CodeStatement>(); global::System.CodeDom.CodeVariableDeclarationStatement serializationResultDeclaration = new global::System.CodeDom.CodeVariableDeclarationStatement(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::SerializationResult)), "serializationResult", new global::System.CodeDom.CodeObjectCreateExpression(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::SerializationResult)))); global::System.CodeDom.CodeMethodInvokeExpression invokeEnableDiagramRules = null; global::System.CodeDom.CodeVariableDeclarationStatement diagramFileDeclaration = null; global::System.CodeDom.CodeAssignStatement diagramFileAssign = null; if (LoadDiagramData) { // generate code to enable diagram fixup rules and load the diagram if required. invokeEnableDiagramRules = new global::System.CodeDom.CodeMethodInvokeExpression( new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression("BizTalkMessagingDomainModel"), "EnableDiagramRules"), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store")); diagramFileDeclaration = new global::System.CodeDom.CodeVariableDeclarationStatement(new global::System.CodeDom.CodeTypeReference("System.String"), "diagramFileName"); diagramFileAssign = new global::System.CodeDom.CodeAssignStatement(new global::System.CodeDom.CodeVariableReferenceExpression("diagramFileName"), new global::System.CodeDom.CodeBinaryOperatorExpression(new global::System.CodeDom.CodePrimitiveExpression(requiresArguments[requiresFileParameter]), global::System.CodeDom.CodeBinaryOperatorType.Add, new global::System.CodeDom.CodePrimitiveExpression(".diagram"))); invokeLoad = new global::System.CodeDom.CodeMethodInvokeExpression( new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression(typeof(BizTalkMessagingSerializationHelper)), "Instance"), "LoadModelAndDiagram"), new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store"), new global::System.CodeDom.CodePrimitiveExpression(requiresArguments[requiresFileParameter]), new global::System.CodeDom.CodeVariableReferenceExpression("diagramFileName"), new global::System.CodeDom.CodePrimitiveExpression(null), new global::System.CodeDom.CodePrimitiveExpression(null)); } else { invokeLoad = new global::System.CodeDom.CodeMethodInvokeExpression( new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression(typeof(BizTalkMessagingSerializationHelper)), "Instance"), "LoadModel"), new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store"), new global::System.CodeDom.CodePrimitiveExpression(requiresArguments[requiresFileParameter]), new global::System.CodeDom.CodePrimitiveExpression(null), new global::System.CodeDom.CodePrimitiveExpression(null)); } global::System.CodeDom.CodeAssignStatement loadAssign = new global::System.CodeDom.CodeAssignStatement(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), providesArguments[providesModelParameter].ToLower(global::System.Globalization.CultureInfo.InvariantCulture) + "Value"), invokeLoad); txTryStatements.Add(serializationResultDeclaration); txTryStatements.Add(new global::System.CodeDom.CodeAssignStatement(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store"), "TransactionManager"), "BeginTransaction", new global::System.CodeDom.CodePrimitiveExpression("Load"), new global::System.CodeDom.CodePrimitiveExpression(true)))); txTryStatements.Add(loadAssign); global::System.CodeDom.CodeConditionStatement serializationResultCheck = new global::System.CodeDom.CodeConditionStatement( new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"), "Failed"), new global::System.CodeDom.CodeThrowExceptionStatement(new global::System.CodeDom.CodeObjectCreateExpression(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::SerializationException)), new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"))) ); txTryStatements.Add(serializationResultCheck); txTryStatements.Add(new global::System.CodeDom.CodeExpressionStatement(new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), "Commit"))); global::System.CodeDom.CodeTryCatchFinallyStatement txTryStatement = new global::System.CodeDom.CodeTryCatchFinallyStatement(txTryStatements.ToArray(), new global::System.CodeDom.CodeCatchClause[] { }, new global::System.CodeDom.CodeStatement[] { finallyStatement }); // We check if the user has requested validation to be performed. If so, we call // ValidateStore() on the base ModelingTextTransformation class. string validationCategories = requiresArguments[requiresValidationParameter]; global::System.CodeDom.CodeMethodInvokeExpression validationInvoke = null; if (!string.IsNullOrEmpty(validationCategories)) { validationInvoke = new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "ValidateStore", new global::System.CodeDom.CodePrimitiveExpression(validationCategories), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Errors")); } global::System.CodeDom.Compiler.CodeGeneratorOptions options = new global::System.CodeDom.Compiler.CodeGeneratorOptions(); options.BlankLinesBetweenMembers = true; options.IndentString = " "; options.VerbatimOrder = true; options.BracingStyle = "C"; using (global::System.IO.StringWriter writer = new global::System.IO.StringWriter(codeBuffer, global::System.Globalization.CultureInfo.InvariantCulture)) { if (invokeEnableDiagramRules != null) { languageProvider.GenerateCodeFromStatement(new global::System.CodeDom.CodeExpressionStatement(invokeEnableDiagramRules), writer, options); } if (diagramFileDeclaration != null) { languageProvider.GenerateCodeFromStatement(diagramFileDeclaration, writer, options); languageProvider.GenerateCodeFromStatement(diagramFileAssign, writer, options); } languageProvider.GenerateCodeFromStatement(transactionDeclaration, writer, options); languageProvider.GenerateCodeFromStatement(txTryStatement, writer, options); if (validationInvoke != null) { languageProvider.GenerateCodeFromStatement(new global::System.CodeDom.CodeExpressionStatement(validationInvoke), writer, options); } } } } }
protected override void GenerateTransformCode(string directiveName, global::System.Text.StringBuilder codeBuffer, global::System.CodeDom.Compiler.CodeDomProvider languageProvider, global::System.Collections.Generic.IDictionary <string, string> requiresArguments, global::System.Collections.Generic.IDictionary <string, string> providesArguments) { if ((global::System.StringComparer.OrdinalIgnoreCase.Compare(directiveName, supportedDirectiveName) == 0)) { if (languageProvider != null) { // Create a field to store the model once it is loaded global::System.CodeDom.CodeMemberField rootElement = new global::System.CodeDom.CodeMemberField(); rootElement.Name = providesArguments[providesModelParameter].ToLower(global::System.Globalization.CultureInfo.InvariantCulture) + "Value"; rootElement.Type = new global::System.CodeDom.CodeTypeReference(typeof(global::BizTalkMessaging.BizTalkMessagingModel)); rootElement.Attributes = global::System.CodeDom.MemberAttributes.Private; // Create a property for the Model that delay-loads the model global::System.CodeDom.CodeMemberProperty rootElementProperty = new global::System.CodeDom.CodeMemberProperty(); rootElementProperty.Name = providesArguments[providesModelParameter]; rootElementProperty.Type = new global::System.CodeDom.CodeTypeReference(typeof(global::BizTalkMessaging.BizTalkMessagingModel)); rootElementProperty.Attributes = global::System.CodeDom.MemberAttributes.Private; rootElementProperty.HasSet = false; rootElementProperty.HasGet = true; rootElementProperty.GetStatements.Add(new global::System.CodeDom.CodeMethodReturnStatement(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), rootElement.Name))); // Create a helper method for resolving relative paths global::System.CodeDom.CodeMemberMethod resolver = null; if (!this.oneTimeCodeGenerated && global::System.IO.File.Exists(this.Host.TemplateFile)) { resolver = new global::System.CodeDom.CodeMemberMethod(); resolver.Name = "Convert" + "BizTalkMessagingModel" + "RelativePathToTemplateRelativePath"; resolver.ReturnType = new global::System.CodeDom.CodeTypeReference(typeof(string)); resolver.Parameters.Add(new global::System.CodeDom.CodeParameterDeclarationExpression(typeof(string), "path")); resolver.Attributes = global::System.CodeDom.MemberAttributes.Public; global::System.CodeDom.CodeVariableDeclarationStatement declaration = new global::System.CodeDom.CodeVariableDeclarationStatement(typeof(string), "modelPath", new global::System.CodeDom.CodePrimitiveExpression((string)(requiresArguments[requiresFileParameter]))); resolver.Statements.Add(declaration); declaration = new global::System.CodeDom.CodeVariableDeclarationStatement(typeof(string), "templatePath", new global::System.CodeDom.CodePrimitiveExpression((string)(this.Host.TemplateFile))); resolver.Statements.Add(declaration); global::System.CodeDom.CodeMethodReturnStatement returnStatement = new global::System.CodeDom.CodeMethodReturnStatement( new global::System.CodeDom.CodeMethodInvokeExpression( new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression("Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation"), "ConvertModelRelativePathToTemplateRelativePath"), new global::System.CodeDom.CodeVariableReferenceExpression("modelPath"), new global::System.CodeDom.CodeVariableReferenceExpression("templatePath"), new global::System.CodeDom.CodeVariableReferenceExpression("path"))); resolver.Statements.Add(returnStatement); } // Generate the actual code using the CodeDomProvider global::System.CodeDom.Compiler.CodeGeneratorOptions options = new global::System.CodeDom.Compiler.CodeGeneratorOptions(); options.BlankLinesBetweenMembers = true; options.IndentString = " "; options.VerbatimOrder = true; options.BracingStyle = "C"; using (global::System.IO.StringWriter writer = new global::System.IO.StringWriter(codeBuffer, global::System.Globalization.CultureInfo.InvariantCulture)) { languageProvider.GenerateCodeFromMember(rootElement, writer, options); languageProvider.GenerateCodeFromMember(rootElementProperty, writer, options); if (resolver != null) { languageProvider.GenerateCodeFromMember(resolver, writer, options); } } this.oneTimeCodeGenerated = true; } } }
protected override void GeneratePostInitializationCode(string directiveName, global::System.Text.StringBuilder codeBuffer, global::System.CodeDom.Compiler.CodeDomProvider languageProvider, global::System.Collections.Generic.IDictionary<string, string> requiresArguments, global::System.Collections.Generic.IDictionary<string, string> providesArguments) { if ((global::System.StringComparer.OrdinalIgnoreCase.Compare(directiveName, supportedDirectiveName) == 0)) { // We check the encoding of the model file, and ask the host to use that // encoding to write the output. This is to make sure we use the correct encoding // if the model file contains international characters that could be used in // the template output. string fileName = requiresArguments[requiresFileParameter]; if (!string.IsNullOrEmpty(fileName) && global::System.IO.File.Exists(fileName)) { Host.SetOutputEncoding(VSTextTemplating::EncodingHelper.GetEncoding(fileName), false); } if (languageProvider != null) { global::System.CodeDom.CodeMethodInvokeExpression invokeLoad; global::System.String transactionName = providesArguments[providesModelParameter].ToLower(global::System.Globalization.CultureInfo.InvariantCulture) + "Transaction"; global::System.CodeDom.CodeVariableDeclarationStatement transactionDeclaration = new global::System.CodeDom.CodeVariableDeclarationStatement(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::Transaction)), transactionName, new global::System.CodeDom.CodePrimitiveExpression(null)); global::System.CodeDom.CodeStatement finallyStatement = new global::System.CodeDom.CodeConditionStatement(new global::System.CodeDom.CodeBinaryOperatorExpression(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), global::System.CodeDom.CodeBinaryOperatorType.IdentityInequality, new global::System.CodeDom.CodePrimitiveExpression(null)), new global::System.CodeDom.CodeExpressionStatement(new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), "Dispose"))); global::System.Collections.Generic.List<global::System.CodeDom.CodeStatement> txTryStatements = new global::System.Collections.Generic.List<global::System.CodeDom.CodeStatement>(); global::System.CodeDom.CodeVariableDeclarationStatement serializationResultDeclaration = new global::System.CodeDom.CodeVariableDeclarationStatement(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::SerializationResult)), "serializationResult", new global::System.CodeDom.CodeObjectCreateExpression(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::SerializationResult)))); global::System.CodeDom.CodeMethodInvokeExpression invokeEnableDiagramRules = null; global::System.CodeDom.CodeVariableDeclarationStatement diagramFileDeclaration = null; global::System.CodeDom.CodeAssignStatement diagramFileAssign = null; if(LoadDiagramData) { // generate code to enable diagram fixup rules and load the diagram if required. invokeEnableDiagramRules = new global::System.CodeDom.CodeMethodInvokeExpression( new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression("ScheduledTasksDomainModel"), "EnableDiagramRules"), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store")); diagramFileDeclaration = new global::System.CodeDom.CodeVariableDeclarationStatement(new global::System.CodeDom.CodeTypeReference("System.String"), "diagramFileName"); diagramFileAssign = new global::System.CodeDom.CodeAssignStatement(new global::System.CodeDom.CodeVariableReferenceExpression("diagramFileName"), new global::System.CodeDom.CodeBinaryOperatorExpression(new global::System.CodeDom.CodePrimitiveExpression(requiresArguments[requiresFileParameter]), global::System.CodeDom.CodeBinaryOperatorType.Add, new global::System.CodeDom.CodePrimitiveExpression(".diagram"))); invokeLoad = new global::System.CodeDom.CodeMethodInvokeExpression( new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression(typeof(ScheduledTasksSerializationHelper)), "Instance"), "LoadModelAndDiagram"), new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store"), new global::System.CodeDom.CodePrimitiveExpression(requiresArguments[requiresFileParameter]), new global::System.CodeDom.CodeVariableReferenceExpression("diagramFileName"), new global::System.CodeDom.CodePrimitiveExpression(null), new global::System.CodeDom.CodePrimitiveExpression(null), new global::System.CodeDom.CodePrimitiveExpression(null)); } else { invokeLoad = new global::System.CodeDom.CodeMethodInvokeExpression( new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression(typeof(ScheduledTasksSerializationHelper)), "Instance"), "LoadModel"), new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store"), new global::System.CodeDom.CodePrimitiveExpression(requiresArguments[requiresFileParameter]), new global::System.CodeDom.CodePrimitiveExpression(null), new global::System.CodeDom.CodePrimitiveExpression(null), new global::System.CodeDom.CodePrimitiveExpression(null)); } global::System.CodeDom.CodeAssignStatement loadAssign = new global::System.CodeDom.CodeAssignStatement(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), providesArguments[providesModelParameter].ToLower(global::System.Globalization.CultureInfo.InvariantCulture) + "Value"), invokeLoad); txTryStatements.Add(serializationResultDeclaration); txTryStatements.Add(new global::System.CodeDom.CodeAssignStatement(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Store"), "TransactionManager"), "BeginTransaction", new global::System.CodeDom.CodePrimitiveExpression("Load"), new global::System.CodeDom.CodePrimitiveExpression(true)))); txTryStatements.Add(loadAssign); global::System.CodeDom.CodeConditionStatement serializationResultCheck = new global::System.CodeDom.CodeConditionStatement( new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"), "Failed"), new global::System.CodeDom.CodeThrowExceptionStatement(new global::System.CodeDom.CodeObjectCreateExpression(new global::System.CodeDom.CodeTypeReference(typeof(DslModeling::SerializationException)), new global::System.CodeDom.CodeVariableReferenceExpression("serializationResult"))) ); txTryStatements.Add(serializationResultCheck); txTryStatements.Add(new global::System.CodeDom.CodeExpressionStatement(new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeVariableReferenceExpression(transactionName), "Commit"))); global::System.CodeDom.CodeTryCatchFinallyStatement txTryStatement = new global::System.CodeDom.CodeTryCatchFinallyStatement(txTryStatements.ToArray(), new global::System.CodeDom.CodeCatchClause[] { }, new global::System.CodeDom.CodeStatement[] { finallyStatement }); // We check if the user has requested validation to be performed. If so, we call // ValidateStore() on the base ModelingTextTransformation class. string validationCategories = requiresArguments[requiresValidationParameter]; global::System.CodeDom.CodeMethodInvokeExpression validationInvoke = null; if (!string.IsNullOrEmpty(validationCategories)) { validationInvoke = new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "ValidateStore", new global::System.CodeDom.CodePrimitiveExpression(validationCategories), new global::System.CodeDom.CodePropertyReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "Errors")); } global::System.CodeDom.Compiler.CodeGeneratorOptions options = new global::System.CodeDom.Compiler.CodeGeneratorOptions(); options.BlankLinesBetweenMembers = true; options.IndentString = " "; options.VerbatimOrder = true; options.BracingStyle = "C"; using (global::System.IO.StringWriter writer = new global::System.IO.StringWriter(codeBuffer, global::System.Globalization.CultureInfo.InvariantCulture)) { if(invokeEnableDiagramRules != null) { languageProvider.GenerateCodeFromStatement(new global::System.CodeDom.CodeExpressionStatement(invokeEnableDiagramRules), writer, options); } if(diagramFileDeclaration != null) { languageProvider.GenerateCodeFromStatement(diagramFileDeclaration, writer, options); languageProvider.GenerateCodeFromStatement(diagramFileAssign, writer, options); } languageProvider.GenerateCodeFromStatement(transactionDeclaration, writer, options); languageProvider.GenerateCodeFromStatement(txTryStatement, writer, options); if (validationInvoke != null) { languageProvider.GenerateCodeFromStatement(new global::System.CodeDom.CodeExpressionStatement(validationInvoke), writer, options); } } } } }
/// <summary> /// Contribute additively to initialization code for the TextTransformation generated class. /// </summary> /// <remarks> /// This code will be added before the call to the base class. /// </remarks> /// <param name="directiveName"></param> /// <param name="codeBuffer"></param> /// <param name="languageProvider"></param> /// <param name="requiresArguments"></param> /// <param name="providesArguments"></param> protected override void GeneratePreInitializationCode(string directiveName, global::System.Text.StringBuilder codeBuffer, global::System.CodeDom.Compiler.CodeDomProvider languageProvider, global::System.Collections.Generic.IDictionary<string, string> requiresArguments, global::System.Collections.Generic.IDictionary<string, string> providesArguments) { if ((global::System.StringComparer.OrdinalIgnoreCase.Compare(directiveName, supportedDirectiveName) == 0)) { if (languageProvider != null) { string[] domainModels = { "Architect.ScheduledTasks.ScheduledTasksDomainModel", }; global::System.CodeDom.Compiler.CodeGeneratorOptions options = new global::System.CodeDom.Compiler.CodeGeneratorOptions(); options.BlankLinesBetweenMembers = true; options.IndentString = " "; options.VerbatimOrder = true; options.BracingStyle = "C"; using (global::System.IO.StringWriter writer = new global::System.IO.StringWriter(codeBuffer, global::System.Globalization.CultureInfo.InvariantCulture)) { foreach (string domainModel in domainModels) { global::System.CodeDom.CodeExpressionStatement addModel = new global::System.CodeDom.CodeExpressionStatement(new global::System.CodeDom.CodeMethodInvokeExpression(new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), "AddDomainModel"), new global::System.CodeDom.CodeTypeOfExpression(domainModel))); languageProvider.GenerateCodeFromStatement(addModel, writer, options); } } } } }
protected override void GenerateTransformCode(string directiveName, global::System.Text.StringBuilder codeBuffer, global::System.CodeDom.Compiler.CodeDomProvider languageProvider, global::System.Collections.Generic.IDictionary<string, string> requiresArguments, global::System.Collections.Generic.IDictionary<string, string> providesArguments) { if ((global::System.StringComparer.OrdinalIgnoreCase.Compare(directiveName, supportedDirectiveName) == 0)) { if (languageProvider != null) { // Create a field to store the model once it is loaded global::System.CodeDom.CodeMemberField rootElement = new global::System.CodeDom.CodeMemberField(); rootElement.Name = providesArguments[providesModelParameter].ToLower(global::System.Globalization.CultureInfo.InvariantCulture) + "Value"; rootElement.Type = new global::System.CodeDom.CodeTypeReference(typeof(global::Architect.ScheduledTasks.Group)); rootElement.Attributes = global::System.CodeDom.MemberAttributes.Private; // Create a property for the Model that delay-loads the model global::System.CodeDom.CodeMemberProperty rootElementProperty = new global::System.CodeDom.CodeMemberProperty(); rootElementProperty.Name = providesArguments[providesModelParameter]; rootElementProperty.Type = new global::System.CodeDom.CodeTypeReference(typeof(global::Architect.ScheduledTasks.Group)); rootElementProperty.Attributes = global::System.CodeDom.MemberAttributes.Private; rootElementProperty.HasSet = false; rootElementProperty.HasGet = true; rootElementProperty.GetStatements.Add(new global::System.CodeDom.CodeMethodReturnStatement(new global::System.CodeDom.CodeFieldReferenceExpression(new global::System.CodeDom.CodeThisReferenceExpression(), rootElement.Name))); // Create a helper method for resolving relative paths global::System.CodeDom.CodeMemberMethod resolver = null; if (!this.oneTimeCodeGenerated && global::System.IO.File.Exists(this.Host.TemplateFile)) { resolver = new global::System.CodeDom.CodeMemberMethod(); resolver.Name = "Convert" + "Group" + "RelativePathToTemplateRelativePath"; resolver.ReturnType = new global::System.CodeDom.CodeTypeReference(typeof(string)); resolver.Parameters.Add(new global::System.CodeDom.CodeParameterDeclarationExpression(typeof(string), "path")); resolver.Attributes = global::System.CodeDom.MemberAttributes.Public; global::System.CodeDom.CodeVariableDeclarationStatement declaration = new global::System.CodeDom.CodeVariableDeclarationStatement(typeof(string), "modelPath", new global::System.CodeDom.CodePrimitiveExpression((string)(requiresArguments[requiresFileParameter]))); resolver.Statements.Add(declaration); declaration = new global::System.CodeDom.CodeVariableDeclarationStatement(typeof(string), "templatePath", new global::System.CodeDom.CodePrimitiveExpression((string)(this.Host.TemplateFile))); resolver.Statements.Add(declaration); global::System.CodeDom.CodeMethodReturnStatement returnStatement = new global::System.CodeDom.CodeMethodReturnStatement( new global::System.CodeDom.CodeMethodInvokeExpression( new global::System.CodeDom.CodeMethodReferenceExpression(new global::System.CodeDom.CodeTypeReferenceExpression("Microsoft.VisualStudio.TextTemplating.VSHost.ModelingTextTransformation"), "ConvertModelRelativePathToTemplateRelativePath"), new global::System.CodeDom.CodeVariableReferenceExpression("modelPath"), new global::System.CodeDom.CodeVariableReferenceExpression("templatePath"), new global::System.CodeDom.CodeVariableReferenceExpression("path"))); resolver.Statements.Add(returnStatement); } // Generate the actual code using the CodeDomProvider global::System.CodeDom.Compiler.CodeGeneratorOptions options = new global::System.CodeDom.Compiler.CodeGeneratorOptions(); options.BlankLinesBetweenMembers = true; options.IndentString = " "; options.VerbatimOrder = true; options.BracingStyle = "C"; using (global::System.IO.StringWriter writer = new global::System.IO.StringWriter(codeBuffer, global::System.Globalization.CultureInfo.InvariantCulture)) { languageProvider.GenerateCodeFromMember(rootElement, writer, options); languageProvider.GenerateCodeFromMember(rootElementProperty, writer, options); if (resolver != null) { languageProvider.GenerateCodeFromMember(resolver, writer, options); } } this.oneTimeCodeGenerated = true; } } }