protected void Application_Start() { var user = db.Users.FirstOrDefault(u => u.IsActive == true); if (user != null) { user.IsActive = false; db.SaveChanges(); } AreaRegistration.RegisterAllAreas(); GlobalConfiguration.Configure(WebApiConfig.Register); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); }
public ActionResult AddTimeSeries(HttpPostedFileBase fileInput, string title, string description) { if (fileInput == null) { return(null); } int c = 0; string elements = ""; using (StreamReader sr = new StreamReader(fileInput.InputStream)) { string l = ""; while ((l = sr.ReadLine()) != null) { c++; elements += l; } } int[] arr = new int[c]; for (int i = 0; i < c; i++) { arr[i] = Convert.ToInt32(elements[i]); } var el = elements; elements = elements.Replace(Environment.NewLine, ""); if (title == string.Empty) { title = fileInput.FileName; } if (description == string.Empty) { description = ""; } var ts = new TimeSeries { TimeSeriesId = Guid.NewGuid(), AmountOfElements = c, Title = title, Elements = elements, Description = description }; db.TimeSeries.Add(ts); db.SaveChanges(); ViewBag.Title = title; var chartData = new StringBuilder(); chartData.Append("["); for (int i = 0; i < c; i++) { if (i == ts.AmountOfElements - 1) { chartData.Append(string.Format("{0}", ts.Elements[i])); break; } chartData.Append(string.Format("{0},", elements[i])); } chartData.Append("]"); ViewBag.chartData = chartData; ViewBag.Title = ts.Title; return(View("TimeSeriesVisual")); }
public void AddImage(string imageInput, string description) { if (imageInput != null) { db.Images.Add(new Image { ImageId = Guid.NewGuid(), Link = imageInput }); db.SaveChanges(); } }
public ActionResult Login(string login, string password) { var user = db.Users.FirstOrDefault(u => u.Login == login && u.Password == password); if (user == null) { return(Json(new { status = "error", message = "no user" })); } user.IsActive = true; db.SaveChanges(); return(Redirect("~/TimeSeries/GetTimeSeriesAdmin")); }
public void start(string imageInput, string ts) { if (imageInput != null && ts != null) { Guid imId = Guid.Parse(imageInput); Guid tsId = Guid.Parse(ts); var image = db.Images.FirstOrDefault(i => i.ImageId == imId); var timeseries = db.TimeSeries.FirstOrDefault(t => t.TimeSeriesId == tsId); if (image != null && timeseries != null) { var startTime = System.Diagnostics.Stopwatch.StartNew(); Process process = new Process { StartInfo = new ProcessStartInfo { FileName = "cmd.exe", RedirectStandardInput = true, RedirectStandardOutput = true, UseShellExecute = false, Arguments = "/c docker pull " + image.Link } }; process.Start(); process.WaitForExit(); int indexOfChar = image.Link.IndexOf('/') + 1; string im = image.Link.Remove(0, indexOfChar); process.StartInfo = new ProcessStartInfo { FileName = "cmd.exe", RedirectStandardInput = true, RedirectStandardOutput = true, UseShellExecute = false, Arguments = "/c docker run -e ARRAY=" + timeseries.Elements.Replace(Environment.NewLine, "") + " " + im }; process.Start(); StreamReader srIncoming = process.StandardOutput; string result = srIncoming.ReadToEnd(); startTime.Stop(); var resultTime = startTime.Elapsed; process.Close(); var res = new Result { ResultId = Guid.NewGuid(), ImageId = image.ImageId, TimeSeriesId = timeseries.TimeSeriesId, Accuracy = result, Time = resultTime }; db.Results.Add(res); db.SaveChanges(); } } }
public ActionResult Start(string imageInput, string ts) { if (imageInput != null && ts != null) { int total = (int)GC.GetTotalMemory(true); Guid imId = Guid.Parse(imageInput); Guid tsId = Guid.Parse(ts); var image = db.Images.FirstOrDefault(i => i.ImageId == imId); var timeseries = db.TimeSeries.FirstOrDefault(t => t.TimeSeriesId == tsId); if (image != null && timeseries != null) { var startTime = System.Diagnostics.Stopwatch.StartNew(); Process process = new Process { StartInfo = new ProcessStartInfo { FileName = "cmd.exe", RedirectStandardInput = true, RedirectStandardOutput = true, UseShellExecute = false, Arguments = "/c docker pull " + image.Link } }; //process.Start(); //process.WaitForExit(); float cpu; string result; using (PerformanceCounter pcProcess = new PerformanceCounter("Process", "% Processor Time", "_Total")) { cpu = pcProcess.NextValue(); int indexOfChar = image.Link.IndexOf('/') + 1; string im = image.Link.Remove(0, indexOfChar); process.StartInfo = new ProcessStartInfo { FileName = "cmd.exe", RedirectStandardInput = true, RedirectStandardOutput = true, UseShellExecute = false, Arguments = "/c docker run -e ARRAY=" + timeseries.Elements.Replace(Environment.NewLine, "") + " " + im }; process.Start(); StreamReader srIncoming = process.StandardOutput; result = srIncoming.ReadToEnd(); startTime.Stop(); process.WaitForExit(); cpu = pcProcess.NextValue() / (float)Environment.ProcessorCount; } var c = (int)cpu; process.Close(); var resultTime = startTime.Elapsed; total = (int)GC.GetTotalMemory(true) - total; total = ((int)(total / (float)Environment.ProcessorCount)) / 1024; var res = new Result { ResultId = Guid.NewGuid(), ImageId = image.ImageId, TimeSeriesId = timeseries.TimeSeriesId, Res = result, Time = resultTime, Memory = total.ToString(), CPU = c + "%" }; db.Results.Add(res); db.SaveChanges(); return(Redirect("~/Result/GetResult/" + res.ResultId)); } } return(Content("error")); }