public ApiGraph(string title, Color backgroundColor, Color borderColor, uint delay, uint span) { this.Name = title; this.TimeSpan = span; this.FillColor = backgroundColor; this.LineColor = borderColor; this.Delay = delay; string graphValueName = "graphValue"; string graphHandleName = "gHtml"; lock (Sync) { graphValueName += _varIndex; graphHandleName += _varIndex++; } this.Variable = graphValueName; this.GraphCtx = graphHandleName; this.Code = GraphPageSplicer.SpliceGraph( graphValueName, graphHandleName, graphHandleName + "_create", title, delay, span, backgroundColor, borderColor); }
public ApiGraphPage(string handle, string title, ApiGraph[] graphs, byte width) { this.ApiHandle = handle; this.Title = title; this.Graphs = graphs; var graphCodeStr = new List <string>(); var graphCodeHandles = new List <string>(); var declareVariablesInScript = new List <string>(); foreach (var graph in graphs) { graphCodeStr.Add(graph.Code); graphCodeHandles.Add(graph.GraphCtx); declareVariablesInScript.Add(graph.Variable); } var script = GraphPageSplicer.SpliceMainScript( IConfigurationStore.GetByType <RequiemConfig>().ApiPort, handle, declareVariablesInScript.ToArray(), graphCodeStr.ToArray(), graphCodeHandles.ToArray()); this.Code = GraphPageSplicer.SpliceFinalHtml(script, title, graphCodeHandles.ToArray(), width); using var ms = new MemoryStream(); using var headers = new HttpResponseHeaders(Code.Length, ResponseStatusCode.Ok200, new IResponseField[] { new FieldAcceptRanges("bytes"), new FieldContentType("text/html"), new FieldServer(HttpConstant.ServerName) }, "HTTP/1.1"); this.Header = headers.Compile(); ms.Write(Header.Item1, 0, Header.Item2); ms.Write(Encoding.UTF8.GetBytes(this.Code)); this.Stream = ms.ToArray(); var httpHandle = new SpecialHandler(handle, async(ctx) => await ctx.SafeWriteAsync(Stream)); HttpHandleStore.AddHandler(httpHandle); this.Api = new ApiHandleHolder(handle); WebApiHandleStore.Add(this.Api); }