Exemplo n.º 1
0
		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);
						}
					}
				}
			}
		}
Exemplo n.º 2
0
		/// <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);
						}
					}
				}
			}
		}