public virtual string Render(IRenderSettings settings) { if (settings == null) { throw new ArgumentNullException(RenderSettingsNotFound); } string html = null; if (!string.IsNullOrEmpty(settings.CacheName) && config.GetRenderedHtmlCache != null) { html = config.GetRenderedHtmlCache(settings); } if (string.IsNullOrEmpty(html)) { var data = CreateData(settings); html = RenderTemplate(settings, data); html = AddCurrentJsonToTemplate(settings, data, html); if (!string.IsNullOrEmpty(settings.CacheName) && config.SetRenderedHtmlCache != null) { config.SetRenderedHtmlCache(settings, html); } } return(html); }
public virtual string AddCurrentJsonToTemplate(IRenderSettings settings, object data, string html) { if (settings.ShowJson && data != null && data.ToString() != string.Empty) { var json = JsonConvert.SerializeObject(data, Formatting.Indented); return(string.Format("{0}<pre data-app=\"JSONHelper\">{1}</pre>", html, HttpUtility.HtmlEncode(json))); } return(html); }
public virtual object CreateData(IRenderSettings settings) { if (settings.Data != null) { return(settings.Data()); } else { return new { } }; }
public RenderContext(IRenderSettings settings, IPromise status, GameObject rootPrefab, Func <CardAction, bool> handler) { this.settings = settings; this.rootPrefab = rootPrefab; cardActionHandler = handler; Status = status; if (settings is MonoBehaviour) { dispatcher = settings as MonoBehaviour; } }
public string Render <E>(object model, bool showJson = false, IRenderSettings settings = null, HtmlHelper html = null, IDictionary <string, object> mappingItems = null) #endif { if (settings == null) { settings = new RenderSettings() { ShowJson = showJson } } ; if (model != null) { if (mappingItems == null) { mappingItems = new Dictionary <string, object>(); } if (!mappingItems.ContainsKey("HtmlHelper") && html != null) { mappingItems.Add("HtmlHelper", html); } foreach (var a in mapperAddItems) { a.Add(mappingItems); } if (string.IsNullOrEmpty(settings.Template)) { settings.Template = GetSuspectTemplateName(typeof(E)); } settings.Data = () => { var output = typeFactoryRunner.Run <E>(mappingItems); if (output != null) { return(output); } else { return(mapper.Map <E>(model, mappingItems)); } }; } return(Render(settings)); }
public virtual string RenderTemplate(IRenderSettings settings, object data) { var templates = config.GetTemplatesCache(); if (templates == null) { templates = config.SetTemplatesCache(); } if (!templates.ContainsKey(settings.Template)) { throw new Exception(string.Format(TemplatesNotFoundMessage, settings.Template)); } return(templates[settings.Template](data)); }
private void Start() { scroller = ChatPanel?.GetComponentInParent <ScrollRectTweener>(); if (Bot == null) { Bot = GetComponent <IBot>(); } if (Settings == null) { Settings = GetComponent <IRenderSettings>(); } Bot.Storage.Load() .Then(store => GetHistoryInfoFromStore(store)); SetupInputs(); }
public static IHtmlString RenderYuzu(this HtmlHelper helper, IRenderSettings settings) { var fe = DependencyResolver.Current.GetService <IYuzuDefinitionTemplates>(); return(helper.Raw(fe.Render(settings))); }
public static IHtmlString RenderYuzu <E>(this HtmlHelper helper, object model, IDictionary <string, object> mappingItems, IRenderSettings settings = null) { var fe = DependencyResolver.Current.GetService <IYuzuDefinitionTemplates>(); return(helper.Raw(fe.Render <E>(model, false, settings, helper, mappingItems))); }
public string Render <E>(object model, bool showJson = false, IRenderSettings settings = null, IHtmlHelper html = null, IDictionary <string, object> mappingItems = null)
protected static XmlElement CreateAndAppendTablesNode(XmlDocument xmlDocument, IRenderSettings settings) { var xmlRoot = xmlDocument.CreateElement("tables"); xmlRoot.SetAttribute("source", "LiveIntegration"); xmlRoot.SetAttribute("submitType", settings.LiveIntegrationSubmitType.ToString()); xmlRoot.SetAttribute("referenceName", settings.ReferenceName); xmlDocument.AppendChild(xmlRoot); return(xmlRoot); }
public static IHtmlContent RenderYuzu(this IHtmlHelper helper, IRenderSettings settings) { var fe = helper.ViewContext.HttpContext.RequestServices.GetService <IYuzuDefinitionTemplates>(); return(helper.Raw(fe.Render(settings))); }
public static IHtmlContent RenderYuzu <E>(this IHtmlHelper helper, object model, IDictionary <string, object> mappingItems, IRenderSettings settings = null) { var fe = helper.ViewContext.HttpContext.RequestServices.GetService <IYuzuDefinitionTemplates>(); return(helper.Raw(fe.Render <E>(model, false, settings, helper, mappingItems))); }
/// <summary> /// Excutes the passed in script /// </summary> /// <param name="containerId"></param> /// <param name="url"></param> /// <param name="props"></param> /// <param name="inBrowserScript"></param> /// <param name="measurements"></param> /// <returns></returns> public string Execute(IRenderSettings settings, out string inBrowserScript, out ReactPerformaceMeasurements measurements, bool disableServerSide = false) { measurements = new ReactPerformaceMeasurements(); var bootstrapper = BootstrapCommand + "(" + JsonConvert.SerializeObject(settings, SerializationSettings) + ");"; if (disableServerSide) { inBrowserScript = bootstrapper; return(""); } try { var stopwatch = new Stopwatch(); var engineFlags = V8ScriptEngineFlags.None; if (DisableGlobalMembers) { engineFlags = V8ScriptEngineFlags.DisableGlobalMembers; } stopwatch.Start(); using (var engine = Runtime.CreateScriptEngine(engineFlags)) { stopwatch.Stop(); measurements.EngineInitializationTime = stopwatch.ElapsedMilliseconds; //Firstly we'll add the libraries to the engine! if (EnableCompilation) { // Use the pre-compiled ones for speed stopwatch.Restart(); engine.Execute(CompiledShimms); stopwatch.Stop(); measurements.ShimmInitializationTime = stopwatch.ElapsedMilliseconds; stopwatch.Restart(); engine.Execute(Compiled); stopwatch.Stop(); measurements.ScriptsInitializationTime = stopwatch.ElapsedMilliseconds; } else { // Use the raw uncompiled ones, these will be parsed a fresh each time by the JS engine stopwatch.Restart(); engine.Execute(JavascriptShimms.ConsoleShim); stopwatch.Stop(); measurements.ShimmInitializationTime = stopwatch.ElapsedMilliseconds; stopwatch.Restart(); engine.Execute(ScriptRaw); stopwatch.Stop(); measurements.ScriptsInitializationTime = stopwatch.ElapsedMilliseconds; } // Kick off the render stopwatch.Restart(); engine.Execute(bootstrapper); // TODO: Might swap this timeout stuff for an actual Timespan check instead var timeOutCounter = 0; var maxCyclesBeforeTimeout = 10; // TODO: Config this // Poll the engine to see if the router callback has fired while ( ( !engine.HasVariable(ROUTER_OUTPUT_KEY) || string.IsNullOrEmpty(engine.GetVariableValue <string>(ROUTER_OUTPUT_KEY)) ) && timeOutCounter <= maxCyclesBeforeTimeout ) { timeOutCounter++; Thread.Sleep(10); // DIRTY! See here of reasoning https://github.com/Offroadcode/SuperchargedReact.Net/issues/1#issuecomment-118848133 // But it works, need to bench mark if this is quicker than linking the JS engine to the .net context as then we could // ping the value straight out form within JS. Alternatively we could get away with just reducing this sleep time but // it depends on how much code we have running, machine speed etc. Its "fast enough" for now though. } stopwatch.Stop(); measurements.ComponentGenerationTime = stopwatch.ElapsedMilliseconds; // Default to a timeout message var html = "<p>Router init timed out waiting for response, try increasing the timeout in React.Config</p>"; if (timeOutCounter <= maxCyclesBeforeTimeout) { html = engine.ExecuteCommand(ROUTER_OUTPUT_KEY);// engine.GetVariableValue<string>(); } //get the console statements out of the engine var consoleStatements = engine.Evaluate <string>("console.getCalls()"); inBrowserScript = consoleStatements + ";" + bootstrapper; //Cleanup the engine stopwatch.Restart(); Cleanup(engine); stopwatch.Stop(); measurements.CleanupTime = stopwatch.ElapsedMilliseconds; return(string.Format( "<{2} id=\"{0}\">{1}</{2}>", settings.ContainerId, html, "div" )); } } catch (Microsoft.ClearScript.ScriptEngineException e) { throw new Exception(e.ErrorDetails); } }
internal void UnregisterSettings(IRenderSettings renderForm) { this.RenderChangeEvent -= new SettingsChangeDelegate(renderForm.RenderChange); }