private string GetFileName(string Language, string[] Rows, out string Title) { StringBuilder sb = new StringBuilder(); foreach (string Row in Rows) { sb.AppendLine(Row); } string Xml = sb.ToString(); int i = Language.IndexOf(':'); if (i > 0) { Title = Language.Substring(i + 1).Trim(); Language = Language.Substring(0, i).TrimEnd(); } else { Title = string.Empty; } sb.Append(Language); string Hash = Hashes.ComputeSHA256HashString(Encoding.UTF8.GetBytes(sb.ToString())); string LayoutFolder = Path.Combine(contentRootFolder, "Layout"); string FileName = Path.Combine(LayoutFolder, Hash); string PngFileName = FileName + ".png"; if (!File.Exists(PngFileName)) { try { XmlDocument Doc = new XmlDocument(); Doc.LoadXml(Xml); Layout2DDocument LayoutDoc = new Layout2DDocument(Doc); RenderSettings Settings = new RenderSettings() { ImageSize = RenderedImageSize.ResizeImage // TODO: Theme colors, font, etc. }; using (SKImage Img = LayoutDoc.Render(Settings, out Map[] _)) // TODO: Maps
private string GetFileName(string Language, string[] Rows, out string Title, out string MapFileName, out string Hash) { StringBuilder sb = new StringBuilder(); foreach (string Row in Rows) { sb.AppendLine(Row); } string Graph = sb.ToString(); int i = Language.IndexOf(':'); if (i > 0) { Title = Language.Substring(i + 1).Trim(); Language = Language.Substring(0, i).TrimEnd(); } else { Title = string.Empty; } sb.Append(Language); Hash = Hashes.ComputeSHA256HashString(Encoding.UTF8.GetBytes(sb.ToString())); string GraphVizFolder = Path.Combine(Gateway.RootFolder, "GraphViz"); string FileName = Path.Combine(GraphVizFolder, Hash); string SvgFileName = FileName + ".svg"; MapFileName = FileName + ".map"; if (File.Exists(SvgFileName)) { if (!File.Exists(MapFileName)) { MapFileName = null; } } else { string TxtFileName = FileName + ".txt"; File.WriteAllText(TxtFileName, Graph, Encoding.Default); ProcessStartInfo ProcessInformation = new ProcessStartInfo() { FileName = Path.Combine(installationFolder, "bin", Language.ToLower() + ".exe"), Arguments = "-Tcmapx -o\"" + MapFileName + "\" -Tsvg -q -o\"" + SvgFileName + "\" \"" + TxtFileName + "\"", UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true, WorkingDirectory = GraphVizFolder, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }; Process P = new Process(); bool Error = false; P.ErrorDataReceived += (sender, e) => { Error = true; Log.Error(e.Data); }; P.StartInfo = ProcessInformation; P.Start(); if (!P.WaitForExit(60000) || Error) { Log.Error("Unable to generate graph."); return(null); } else if (P.ExitCode != 0) { Log.Error("Unable to generate graph. Exit code: " + P.ExitCode.ToString()); return(null); } string Map = File.ReadAllText(MapFileName); string[] MapRows = Map.Split(CommonTypes.CRLF, StringSplitOptions.RemoveEmptyEntries); if (MapRows.Length <= 2) { File.Delete(MapFileName); MapFileName = null; } } return(SvgFileName); }
private string GetFileName(string Language, string[] Rows, ResultType Type, out string Title) { StringBuilder sb = new StringBuilder(); foreach (string Row in Rows) { sb.AppendLine(Row); } string Graph = sb.ToString(); int i = Language.IndexOf(':'); if (i > 0) { Title = Language.Substring(i + 1).Trim(); Language = Language.Substring(0, i).TrimEnd(); } else { Title = string.Empty; } sb.Append(Language); string FileName = Hashes.ComputeSHA256HashString(Encoding.UTF8.GetBytes(sb.ToString())); string PlantUmlFolder = Path.Combine(contentRootFolder, "PlantUML"); FileName = Path.Combine(PlantUmlFolder, FileName); string ResultFileName; switch (Type) { case ResultType.Svg: default: ResultFileName = FileName + ".svg"; break; case ResultType.Png: ResultFileName = FileName + ".png"; break; } if (!File.Exists(ResultFileName)) { string TxtFileName = FileName + ".txt"; File.WriteAllText(TxtFileName, Graph, Encoding.UTF8); ProcessStartInfo ProcessInformation = new ProcessStartInfo() { FileName = javaPath, Arguments = "-jar \"" + jarPath + "\" -charset UTF-8 -t" + Type.ToString().ToLower() + " -quiet \"" + TxtFileName + "\" \"" + ResultFileName + "\"", UseShellExecute = false, RedirectStandardError = true, RedirectStandardOutput = true, WorkingDirectory = PlantUmlFolder, CreateNoWindow = true, WindowStyle = ProcessWindowStyle.Hidden }; Process P = new Process(); bool Error = false; P.ErrorDataReceived += (sender, e) => { Error = true; Log.Error(e.Data); }; P.StartInfo = ProcessInformation; P.Start(); if (!P.WaitForExit(60000) || Error) { Log.Error("Unable to generate graph."); return(null); } else if (P.ExitCode != 0) { Log.Error("Unable to generate graph. Exit code: " + P.ExitCode.ToString()); return(null); } } return(ResultFileName); }
private string ComputeDigest(string Key) { return(Hashes.ComputeSHA256HashString(Encoding.UTF8.GetBytes(Key + ":" + this.defaultFacility))); }