public async Task SendMessage(string pointArray) { if (pointArray == "repeat") { if (points.returnData().Count > 0) { points.add(points.returnData()[points.returnData().Count - 1]); } } else { List <Point> pointsOfCurrentLayer = new List <Point>(); int id = 0; foreach (string pointString in pointArray.Split(',')) { Point point = new Point(); string[] xyPoints = pointString.Split('&'); point.x = Int32.Parse(xyPoints[0]); point.y = Int32.Parse(xyPoints[1]); point.id = id; pointsOfCurrentLayer.Add(point); id++; } //Todo: Clean the data better by distincting it. pointsOfCurrentLayer = pointsOfCurrentLayer.GroupBy(f => f.id).Select(r => r.FirstOrDefault()).ToList(); points.add(pointsOfCurrentLayer); foreach (Point p in pointsOfCurrentLayer) { Console.Write("(" + p.x + "," + p.y + ") "); } Console.WriteLine(); Console.WriteLine(points.getLength()); await Clients.Caller.SendAsync("ReceiveMessage", pointArray); } }
public IActionResult OnPost() { string fileName = Guid.NewGuid().ToString() + ".gcode"; float currentZ = 0; float currentE = 0; List <string> gcodeFile = new List <string>() { ";Made With Simple Print :)", "M107", "M190 S" + bedTemp, "M104 S" + extTemp, "G28", "M109 S" + extTemp, "G21", "G90", "M82", "G92 E0" }; foreach (List <Point> pointsInLayer in points.returnData()) { foreach (Point point in pointsInLayer) { gcodeFile.Add("G1 X" + point.x + " Y" + point.y + " Z" + currentZ + " E" + currentE); currentE += float.Parse(eRate); } currentZ += float.Parse(zRate); } gcodeFile.Add("G92 E0"); var gcode = System.IO.File.CreateText("wwwroot/gcode/" + fileName); foreach (string line in gcodeFile) { gcode.WriteLine(line); } gcode.Flush(); gcode.Dispose(); var net = new System.Net.WebClient(); var data = net.DownloadData("wwwroot/gcode/" + fileName); var content = new System.IO.MemoryStream(data); System.IO.File.Delete("wwwroot/gcode/" + fileName); points.deleteAll(); return(File(content, "application/force-download", "your-simpleprint-design.gcode")); }