public HttpResponseMessage GetAtp([FromUri] string squareString) { var response = new HttpResponseMessage(); string res = ""; try { InvestigationObject obj = new InvestigationObject(squareString); Random r = new Random(); string inputFileName = FILES_PATH + r.Next().ToString() + "_in.txt"; File.WriteAllText(inputFileName, obj.AsString("cleanSquare")); string outputFileName = FILES_PATH + r.Next().ToString() + "_out.txt"; res = Utils.CommandLine.Execute(FILES_PATH + @"atp.exe", inputFileName + " " + outputFileName); FileInfo file = new FileInfo(outputFileName); while (Utils.IsFileLocked(file)) { ; } res = File.ReadAllText(outputFileName); File.Delete(inputFileName); File.Delete(outputFileName); } catch (Exception e) { res = "error: " + e.ToString(); File.WriteAllText(FILES_PATH + @"log.txt", res); } response.Content = new StringContent(res); response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); return(response); }
public HttpResponseMessage CheckRectangles(bool flag, [FromBody] string input) { var response = new HttpResponseMessage(); if (flag) { input = Utils.Format(input); } int count = 0, countG = 0; string[] squares = input.Trim().Split(new string[] { "\n\n" }, StringSplitOptions.RemoveEmptyEntries); foreach (var s in squares) { InvestigationObject obj = new InvestigationObject(s.Replace("\n", "")); if (obj.IsPartitionTrivial()) { count++; } if (obj.IsPartitionTrivial(true)) { countG++; } } string res = "number of squares inserted: " + squares.Count(); res += "\nnumber of squares found trivial by first partition (D): " + count; res += "\npercent: " + (((double)count) / squares.Count()); res += "\nnumber of squares found trivial by first partition (G): " + countG; res += "\npercent: " + (((double)countG) / squares.Count()); res += "\nHope that helped!!"; response.Content = new StringContent(res); response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); return(response); }
public HttpResponseMessage GetInvestigationObjectForRectangle([FromUri] string squareString) { var response = new HttpResponseMessage(); string res = ""; try { InvestigationObject obj = new InvestigationObject(squareString); res = obj.AsString("all"); } catch (Exception e) { res = "error: " + e.Message; } response.Content = new StringContent(res); response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html"); return(response); }
public static InvestigationObject Get() { Process currentProcess = Process.GetCurrentProcess(); string result = string.Empty; try { ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT Caption FROM Win32_OperatingSystem"); foreach (ManagementObject os in searcher.Get()) { result = os["Caption"].ToString(); break; } } catch (Exception) { result = "Failed in InvestigationObject on Get()"; } InvestigationObject ob = new InvestigationObject { SenderShcVersion = Tcp.Version, SenderOsName = result, SenderMachineName = Environment.MachineName, SenderUserName = Environment.UserName, SenderApplicationName = currentProcess.ProcessName, SenderApplicationStarted = currentProcess.StartTime, SenderApplicationPath = Environment.CurrentDirectory, }; return ob; }