Exemplo n.º 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();
                }
            }
        }
Exemplo n.º 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();
                }
            }
        }
        /// <summary>Retrieves a Template singleton instance (downloading it if it has not already been pulled).</summary>
        /// <param name="url">The URL that contains the template.</param>
        /// <param name="selector">The CSS selector for the script block containing the template HTML.</param>
        /// <param name="callback">Callback to return the template in.</param>
        public void GetAsync(string url, string selector, TemplateCallback callback)
        {
            // Setup initial conditions.
            if (callback == null) return;

            // Check cache for pre-existing template.
            Template template = Get(selector);
            if (template != null)
            {
                callback(template);
                return;
            }

            // NB: The actual download is only invoked once (logic handled within the 'Download' method).
            Download(url, delegate
                              {
                                  template = GetInternal(selector, false); // Don't recheck cahce.  Cache has already checked prior to downloading.
                                  callback(template);
                              });
        }