public static CachedFunctionInformation Deserialize(string filePath) { var lines = C1File.ReadAllLines(filePath); if (lines == null || lines.Length == 0) { return(null); } Type type = TypeManager.TryGetType(lines[0]); if (type == null) { return(null); } bool preventCaching = bool.Parse(lines[1]); string description = string.Join(Environment.NewLine, lines.Skip(2)); return(new CachedFunctionInformation { Description = description, PreventCaching = preventCaching, ReturnType = type }); }
private void EmbedSourceCodeInformation(HttpCompileException ex) { var compilationErrors = ex.Results.Errors; if (!compilationErrors.HasErrors) { return; } CompilerError firstError = null; for (int i = 0; i < compilationErrors.Count; i++) { if (!compilationErrors[i].IsWarning) { firstError = compilationErrors[i]; break; } } Verify.IsNotNull(firstError, "Failed to finding an error in the compiler results."); // Not showing source code of not related files if (!firstError.FileName.StartsWith(PathUtil.Resolve(VirtualPath), StringComparison.OrdinalIgnoreCase)) { return; } string[] sourceCode = C1File.ReadAllLines(firstError.FileName); XhtmlErrorFormatter.EmbedSourceCodeInformation(ex, sourceCode, firstError.Line); }
private void EmbedExceptionSourceCode(Exception ex) { if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException || ex is ThreadInterruptedException) { return; } var stackTrace = new StackTrace(ex, true); foreach (var frame in stackTrace.GetFrames()) { string fileName = frame.GetFileName(); if (fileName != null && File.Exists(fileName)) { var sourceCode = C1File.ReadAllLines(fileName); XhtmlErrorFormatter.EmbedSourceCodeInformation(ex, sourceCode, frame.GetFileLineNumber()); return; } } }
private void EmbedExecutionExceptionSourceCode(Exception ex) { if (ex is ThreadAbortException || ex is StackOverflowException || ex is OutOfMemoryException || ex is ThreadInterruptedException) { return; } var stackTrace = new StackTrace(ex, true); string fullFilePath = PathUtil.Resolve(VirtualPath); foreach (var frame in stackTrace.GetFrames()) { string fileName = frame.GetFileName(); if (fileName != null && fileName.StartsWith(fullFilePath, StringComparison.InvariantCultureIgnoreCase)) { var sourceCode = C1File.ReadAllLines(fileName); XhtmlErrorFormatter.EmbedSourceCodeInformation(ex, sourceCode, frame.GetFileLineNumber()); return; } } }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["PiggyBagId"] == null) { ElementInformationPlaceHolder.Controls.Add(new LiteralControl("No entity token.... nothing to do.... ")); return; } Guid piggybagId = new Guid(Request.QueryString["PiggyBagId"]); string filename = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.TempDirectory), string.Format("{0}.showinfo", piggybagId)); string[] showinfo = C1File.ReadAllLines(filename); string serializedEntityToken = showinfo[0]; string serializedPiggyBag = showinfo[1]; EntityToken entityToken = EntityTokenSerializer.Deserialize(serializedEntityToken); Dictionary <string, string> dic = StringConversionServices.ParseKeyValueCollection(serializedPiggyBag); Dictionary <string, string> piggybag = new Dictionary <string, string>(); foreach (var kvp in dic) { piggybag.Add(kvp.Key, StringConversionServices.DeserializeValueString(kvp.Value)); } string entityTokenHtml = entityToken.GetPrettyHtml(piggybag); ElementInformationPlaceHolder.Controls.Add(new LiteralControl(entityTokenHtml)); }
/// <summary> /// Renders a url and return a full path to a rendered image, or <value>null</value> when rendering process is failing or inaccessible. /// </summary> public static async Task <RenderingResult> RenderUrlAsync(HttpContext context, string url, string mode) { string dropFolder = GetCacheFolder(mode); if (!C1Directory.Exists(dropFolder)) { C1Directory.CreateDirectory(dropFolder); } string urlHash = Convert.ToBase64String(BitConverter.GetBytes(url.GetHashCode())).Substring(0, 6).Replace('+', '-').Replace('/', '_'); string outputImageFileName = Path.Combine(dropFolder, urlHash + ".png"); string outputFileName = Path.Combine(dropFolder, urlHash + ".output"); string redirectLogFileName = Path.Combine(dropFolder, urlHash + ".redirect"); string errorFileName = Path.Combine(dropFolder, urlHash + ".error"); if (C1File.Exists(outputImageFileName) || C1File.Exists(outputFileName)) { #if BrowserRender_NoCache File.Delete(outputFileName); #else string[] output = C1File.Exists(outputFileName) ? C1File.ReadAllLines(outputFileName) : null; return(new RenderingResult { FilePath = outputImageFileName, Output = output, Status = RenderingResultStatus.Success }); #endif } if (!Enabled) { return(null); } var result = await MakePreviewRequestAsync(context, url, outputImageFileName, mode); if (result.Status >= RenderingResultStatus.Error) { C1File.WriteAllLines(errorFileName, result.Output); } if (!Enabled) { return(null); } if (result.Status == RenderingResultStatus.Success) { C1File.WriteAllLines(outputFileName, result.Output); } else if (result.Status == RenderingResultStatus.Redirect) { C1File.WriteAllLines(redirectLogFileName, result.Output); } return(result); }
private void EmbedSourceCodeInformation(HttpParseException ex) { // Not showing source code of not related files if (!ex.FileName.StartsWith(PathUtil.Resolve(VirtualPath), StringComparison.OrdinalIgnoreCase)) { return; } string[] sourceCode = C1File.ReadAllLines(ex.FileName); XhtmlErrorFormatter.EmbedSourceCodeInformation(ex, sourceCode, ex.Line); }
public static CachedTemplateInformation DeserializeFromFile(string filePath) { var lines = C1File.ReadAllLines(filePath); if (lines == null || lines.Length == 0) { return(null); } Guid templateId = Guid.Parse(lines[0]); string title = string.Join(Environment.NewLine, lines.Skip(1)); return(new CachedTemplateInformation { TemplateId = templateId, Title = title }); }
/** * Process request. */ public void ProcessRequest(HttpContext context) { if (CookieHandler.Get("mode") == "develop") { context.Response.Cache.SetExpires(DateTime.Now.AddMonths(-1)); context.Response.Cache.SetCacheability(HttpCacheability.NoCache); } else { context.Response.Cache.SetExpires(DateTime.Now.AddMonths(1)); context.Response.Cache.SetCacheability(HttpCacheability.Private); } string webPath = context.Request.Path; string cssPath = webPath.Substring(0, webPath.LastIndexOf(".aspx")); string filePath = context.Server.MapPath(cssPath); context.Response.ContentType = "text/css"; State state = new State(context); User user = new User(context); Colors colors = new Colors(user); if (C1File.Exists(filePath)) { var sb = new StringBuilder(); string[] lines = C1File.ReadAllLines(filePath); foreach (string line in lines) { // context.Response.Write ( "/*" + line.ToString() + "*/" + "\n" ); string result = Parse(line, user, state, colors); if (result != null) { sb.Append(result).Append("\n"); } } context.Response.Write(sb.ToString()); } else { // Make it obvious that there is some kind of css fåk up. context.Response.Write("body { border: 1px solid red ! important; }"); context.Response.StatusCode = 404; } }
object IFunction.Execute(ParameterList parameters, FunctionContextContainer context) { if (_errors.CompileErrors.Count > 0) { var error = _errors.CompileErrors[0]; var exception = new InvalidOperationException("{1} Line {0}: {2}".FormatWith(error.Item1, error.Item2, error.Item3)); if (_sourceCode == null) { string filepath = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.InlineCSharpFunctionDirectory), _function.CodePath); if (C1File.Exists(filepath)) { _sourceCode = C1File.ReadAllLines(filepath); } else { _sourceCode = new string[0]; } } if (_sourceCode.Length > 0) { XhtmlErrorFormatter.EmbedSourceCodeInformation(exception, _sourceCode, error.Item1); } throw exception; } if (_errors.LoadingException != null) { throw _errors.LoadingException; } throw new InvalidOperationException("Function wasn't loaded due to compilation errors"); }
private static XElement SourceCodePreview(string filePath, int errorLine) { string[] lines = C1File.ReadAllLines(filePath); return(SourceCodePreview(lines, errorLine)); }
protected void Page_Load(object sender, EventArgs e) { string idString = Request.QueryString["Id"]; if (string.IsNullOrEmpty(idString) == true) { return; } Guid id = new Guid(idString); string filename = Path.Combine(PathUtil.Resolve(GlobalSettingsFacade.TempDirectory), string.Format("{0}.RelationshipGraph", id)); EntityToken startEntityToken = EntityTokenSerializer.Deserialize(C1File.ReadAllLines(filename)[0]); RelationshipOrientedGraph graph = new RelationshipOrientedGraph(startEntityToken); IEnumerable <IEnumerable <EntityToken> > paths = graph.Root.GetAllPaths(); RelationshipOrientedGraphPlaceHolder.Controls.Add(new LiteralControl(string.Format("<div><b>Path count: {0}</b></div>", paths.Count()))); int pathCounter = 1; foreach (IEnumerable <EntityToken> path in paths) { EntityTokenHtmlPrettyfierHelper helper = new EntityTokenHtmlPrettyfierHelper(); helper.StartTable(); helper.AddHeading(string.Format("<b>Path: {0}</b>", pathCounter++)); int levelCounter = 0; foreach (EntityToken entityToken in path) { helper.StartRow(); helper.AddCell(string.Format("<center><b>Level: {0}</b></center>", levelCounter++), 2, "#aaaaaa"); helper.EndRow(); helper.StartRow(); helper.AddCell("<b>Id</b>"); helper.AddCell(entityToken.OnGetIdPrettyHtml()); helper.EndRow(); helper.StartRow(); helper.AddCell("<b>Type</b>"); helper.AddCell(entityToken.OnGetTypePrettyHtml()); helper.EndRow(); helper.StartRow(); helper.AddCell("<b>Source</b>"); helper.AddCell(entityToken.OnGetSourcePrettyHtml()); helper.EndRow(); string extra = entityToken.OnGetExtraPrettyHtml(); if (string.IsNullOrEmpty(extra) == false) { helper.StartRow(); helper.AddCell("<b>Extra</b>"); helper.AddCell(extra); helper.EndRow(); } helper.StartRow(); helper.AddCell("<b>RTT</b>"); helper.AddCell(TypeManager.SerializeType(entityToken.GetType())); helper.EndRow(); } helper.EndTable(); RelationshipOrientedGraphPlaceHolder.Controls.Add(new LiteralControl(helper.GetResult())); } }