Beispiel #1
0
        public static void OnTransformationEnded(TextTransformation transformation)
        {
            try
            {
                if (transformation == null)
                {
                    throw new ArgumentNullException("transformation");
                }

                if (TransformationContext.transformation != null && !TransformationContext.Errors.HasErrors)
                {
                    // Update the files in the default AppDomain to avoid remoting errors on Database projects
                    BindingFlags invokeInternalStaticMethod = BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic;
                    AppDomain    defaultDomain = (AppDomain)typeof(AppDomain).InvokeMember("GetDefaultDomain", invokeInternalStaticMethod, null, null, null, CultureInfo.InvariantCulture);
                    defaultDomain.DoCallBack(TransformationContext.outputManager.UpdateFiles);
                }

                TransformationContext.transformation = null;
                TransformationContext.outputManager  = null;
                TransformationContext.project        = null;
                TransformationContext.projectItem    = null;
                TransformationContext.dte            = null;

                if (TransformationContext.TransformationEnded != null)
                {
                    TransformationContext.TransformationEnded(null, EventArgs.Empty);
                }
            }
            catch (TransformationException e)
            {
                // Display expected errors in the Error List window without the call stack
                CompilerErrorCollection errors = new CompilerErrorCollection();
                CompilerError           error  = new CompilerError();
                error.ErrorText = e.Message;
                error.FileName  = Host.TemplateFile;
                errors.Add(error);
                TransformationContext.Host.LogErrors(errors);
            }
            finally
            {
                DestroyTraceListener();
            }
        }
        /// <summary>
        /// This method is a part of T4 Toolbox infrastructure. Don't call it in your code.
        /// </summary>
        /// <param name="transformation">
        /// Instance of the <see cref="TextTransformation"/> class generated by T4 engine.
        /// </param>
        /// <exception cref="ArgumentNullException">
        /// Method throws <see cref="ArgumentNullException"/> when the specified 
        /// <paramref name="transformation"/> is null.
        /// </exception>
        /// <remarks>
        /// During template transformation, this method is called by code in T4Toolbox.tt.
        /// </remarks>
        public static void OnTransformationStarted(TextTransformation transformation)
        {
            if (transformation == null)
            {
                throw new ArgumentNullException("transformation");
            }

            TransformationContext.transformation = transformation;
            TransformationContext.outputManager = new OutputManager();

            CreateTraceListener();
        }
        public static void OnTransformationEnded(TextTransformation transformation)
        {
            try
            {
                if (transformation == null)
                {
                    throw new ArgumentNullException("transformation");
                }

                if (TransformationContext.transformation != null && !TransformationContext.Errors.HasErrors)
                {
                    //Update the files in the default AppDomain to avoid remoting errors on Database projects
                    //BindingFlags invokeInternalStaticMethod = BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.NonPublic;
                    //AppDomain defaultDomain = (AppDomain)typeof(AppDomain).InvokeMember("GetDefaultDomain", invokeInternalStaticMethod, null, null, null, CultureInfo.InvariantCulture);

                    //var bd1 = defaultDomain.BaseDirectory;

                    //var setup = new AppDomainSetup();
                    //setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
                    //AppDomain serverAppDomain = AppDomain.CreateDomain("ServerAppDomain", null, setup);

                    //var udf = TransformationContext.outputManager;
                    //defaultDomain.DoCallBack(udf.UpdateFiles);

                    OutputProcessor.Host = Host;
                    outputManager.UpdateFiles();
                }

                TransformationContext.transformation = null;
                TransformationContext.outputManager = null;
                TransformationContext.project = null;
                TransformationContext.projectItem = null;
                TransformationContext.dte = null;

                if (TransformationContext.TransformationEnded != null)
                {
                    TransformationContext.TransformationEnded(null, EventArgs.Empty);
                }
            }
            catch (TransformationException e)
            {
                // Display expected errors in the Error List window without the call stack
                CompilerErrorCollection errors = new CompilerErrorCollection();
                CompilerError error = new CompilerError();
                error.ErrorText = e.Message;
                error.FileName = Host.TemplateFile;
                errors.Add(error);
                TransformationContext.Host.LogErrors(errors);
            }
            finally
            {
                DestroyTraceListener();
            }
        }