/// <summary> /// Initializes a new instance of the <see cref="PhunFileSystem" /> class. /// </summary> /// <param name="api">The API.</param> /// <param name="connector">The connector.</param> /// <param name="context">The context.</param> public PhunFileSystem(IPhunApi api, IContentConnector connector) { this.connector = connector; this.api = api; this.config = Bootstrapper.Default.Config; this.myUtility = new ResourcePathUtility(); }
/// <summary> /// Initializes a new instance of the <see cref="PhunApi" /> class. /// </summary> /// <param name="httpContext">The HTTP context.</param> /// <param name="connector">The connector.</param> public PhunApi(HttpContextBase httpContext, IContentConnector connector) { this.utility = new ResourcePathUtility(); this.connector = connector; this.host = this.utility.GetTenantHost(httpContext.Request.Url); this.request = new PhunRequest(httpContext); this.response = new PhunResponse(httpContext); this.phunFileSystem = new PhunFileSystem(this, connector); this.phunPath = new PhunPath(); this.user = httpContext.User; this.cache = new PhunCache(httpContext); this.trace = new Trace(); this.templateCache = new TemplateCache(this, httpContext); }
/// <summary> /// Executes the specified model. /// </summary> /// <param name="model">The model.</param> /// <param name="connector">The connector.</param> /// <param name="httpContext">The HTTP context.</param> public void Render(Data.ContentModel model, IContentConnector connector, HttpContextBase httpContext) { using (var ctx = new JavascriptContext()) { // caching vashjs if (vashjsString == null) { var file = this.Utility.Config.GetResourceFile(this.Utility.GetResourcePath("/scripts/vash.js")); // load vash.js using (var stream = file.Open()) { vashjsString = System.Text.Encoding.UTF8.GetString(stream.ReadAll()); } vashjsString = vashjsString.Replace( "d.tplcache[e]||(d.tplcache[e]=b.compile(a.readFileSync(e,\"utf8\")))", "d.tplcache.get(e)||(d.tplcache.set(e,b.compile(a.readFileSync(e,\"utf8\"))))"); } var context = new PhunApi(httpContext, connector); context.FileModel = model; // set application start // set api object // set require method ctx.SetParameter("__httpcontext__", context); ctx.Run( @"phun = { api: __httpcontext__ }; module = { exports: {}, require: phun.api.require }; require = phun.api.require; console = { log: function() { // we need this for vash and everybody else try { for(var i = 0; i < arguments.length; i++) { phun.api.trace.log('' + arguments[i]); } } catch(e) { // do nothing } } };" + vashjsString + @" vash = module.exports; vash.config.cache = true; vash.helpers.tplcache = { get: function(key) { var result = phun.api.cache.get('templateCache$' + phun.api.FileModel.Path + '$' + key); return result ? eval(result) : null; }, set: function(key, value) { var result = phun.api.cache.set('templateCache$' + phun.api.FileModel.Path + '$' + key, value + ''); return value; } }; var vashHtmlReportError = vash.helpers.constructor.reportError; vashHtmlExceptionMessage = ''; vash.helpers.constructor.reportError = function(e, lineno, chr, orig, lb) { try { vashHtmlReportError(e, lineno, chr, orig, lb); } catch(ee) { vashHtmlExceptionMessage = e.stack; } }; "); if (apiScripts == null) { var sb = new StringBuilder(); // load api scripts foreach (var script in Bootstrapper.Default.ApiScripts.Values) { sb.AppendLine(script); } // execute file sb.AppendLine( @"try { vash.renderFile( phun.api.FileModel.Path, { model : {} }, function(err, html) { if (typeof(html) == 'string') { phun.api.response.write(html.split('')); } else { phun.api.response.write(err); phun.api.response.write(html); } phun.api.response.flush(); } ); } catch(ee) { // provide better exception message throw new Error(ee + '\r\n' + vashHtmlExceptionMessage); }"); apiScripts = sb.ToString(); } // finally execute entire apiScripts ctx.Run(apiScripts); httpContext.Response.End(); } }
/// <summary> /// Initializes a new instance of the <see cref="CmsController" /> class. /// </summary> /// <param name="connector">The connector.</param> protected CmsController(IContentConnector connector) { this.ContentConnector = connector; }