Exemple #1
0
        /// <summary>
        /// Transforms the template and adds the content with the given name to the specified parent.
        /// </summary>
        public IItemContainer Unfold(string name, IItemContainer parent)
        {
            Guard.NotNull(() => parent, parent);
            Guard.NotNullOrEmpty(() => name, name);

            //var sessionHost = this.templating as ITextTemplatingSessionHost;

            using (tracer.StartActivity(Resources.TextTemplate_TraceStartUnfold, this.templateFile, parent.GetLogicalPath()))
            {
                this.templating.BeginErrorSession();
                try
                {
                    // TODO: add support for parameters.
                    //foreach (var parameter in Parameters)
                    //{
                    //    sessionHost.Session[parameter.Name] = parameter.GetTypedValue();
                    //}
                    var callback   = new TemplateCallback(tracer, templateFile);
                    var content    = this.templating.ProcessTemplate(templateFile, templateContent, callback);
                    var targetName = name;
                    if (!Path.HasExtension(targetName))
                    {
                        targetName = targetName + callback.FileExtension;
                    }

                    // BUGFIX: FBRT does not checkout the file, if SCC.
                    var targetItem = parent.Find <IItem>(targetName).FirstOrDefault();
                    if (targetItem != null)
                    {
                        targetItem.Checkout();
                    }

                    using (new TempFileCleaner())
                    {
                        // HACK: \o/ feature runtime VsFileContentTemplate creates a temp file and
                        // doesn't delete it, so we go FSW to detect it.
                        return(parent.AddContent(content, targetName, true, false, callback.OutputEncoding));
                    }
                }
                finally
                {
                    this.templating.EndErrorSession();
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Transforms the template and adds the content with the given name to the specified parent.
        /// </summary>
        public IItemContainer Unfold(string name, IItemContainer parent)
        {
            Guard.NotNull(() => parent, parent);
            Guard.NotNullOrEmpty(() => name, name);

            //var sessionHost = this.templating as ITextTemplatingSessionHost;

            using (tracer.StartActivity(Resources.TextTemplate_TraceStartUnfold, this.templateFile, parent.GetLogicalPath()))
            {
                this.templating.BeginErrorSession();
                try
                {
                    // TODO: add support for parameters.
                    //foreach (var parameter in Parameters)
                    //{
                    //    sessionHost.Session[parameter.Name] = parameter.GetTypedValue();
                    //}
                    var callback = new TemplateCallback(tracer, templateFile);
                    var content = this.templating.ProcessTemplate(templateFile, templateContent, callback);
                    var targetName = name;
                    if (!Path.HasExtension(targetName))
                    {
                        targetName = targetName + callback.FileExtension;
                    }

                    // BUGFIX: FBRT does not checkout the file, if SCC.
                    var targetItem = parent.Find<IItem>(targetName).FirstOrDefault();
                    if (targetItem != null)
                    {
                        targetItem.Checkout();
                    }

                    using (new TempFileCleaner())
                    {
                        // HACK: \o/ feature runtime VsFileContentTemplate creates a temp file and 
                        // doesn't delete it, so we go FSW to detect it.
                        return parent.AddContent(content, targetName, true, false, callback.OutputEncoding);
                    }
                }
                finally
                {
                    this.templating.EndErrorSession();
                }
            }
        }