private Guid CreateDocument(List<Employee> emps, Random r) { Guid id = Guid.NewGuid(); DateTime opStart = DateTime.Now; using (var context = new DataModelDataContext()) { var author = emps[r.Next(0, emps.Count)]; var controller = emps[r.Next(0, emps.Count)]; var doc = new Document(); doc.Id = id; doc.AuthorId = author.Id; doc.StateName = "Draft"; doc.Name = "AG_Doc " + doc.Number.ToString(); if (r.Next(0, 2) == 1) { doc.EmloyeeControlerId = controller.Id; } doc.Comment = string.Format("Auto-generated documnet. {0}.", DateTime.Now.ToShortTimeString()); doc.Sum = r.Next(1, 10000); context.Documents.InsertOnSubmit(doc); context.SubmitChanges(); } AddOperation(opStart, DateTime.Now, "CreatingDocument"); return id; }
public ActionResult Clean() { using (var context = new DataModelDataContext()) { context.LoadTestingOperations.DeleteAllOnSubmit(context.LoadTestingOperations); context.SubmitChanges(); } return Content(""); }
private SettingsModel GetModel() { var model = new SettingsModel(); model.SchemeName = "SimpleWF"; using (var context = new DataModelDataContext()) { var lo = new DataLoadOptions(); lo.LoadWith<Employee>(c => c.StructDivision); lo.LoadWith<EmployeeRole>(c => c.Role); lo.LoadWith<Employee>(c => c.EmployeeRoles); context.LoadOptions = lo; var wfSheme = context.WorkflowSchemes.FirstOrDefault(c => c.Code == model.SchemeName); if (wfSheme != null) model.WFSchema = wfSheme.Scheme; model.Employees = context.Employees.ToList(); model.Roles = context.Roles.ToList(); model.StructDivision = context.StructDivisions.ToList(); } return model; }
public ActionResult Edit(SettingsModel model) { using (var context = new DataModelDataContext()) { var wfSheme = context.WorkflowSchemes.FirstOrDefault(c => c.Code == "SimpleWF"); if(wfSheme == null) { wfSheme = new WorkflowScheme() { Code = "SimpleWF", Scheme = string.Empty }; context.WorkflowSchemes.InsertOnSubmit(wfSheme); } wfSheme.Scheme = model.WFSchema ?? string.Empty; model.WFSchema = wfSheme.Scheme; context.SubmitChanges(); } return View(GetModel()); }
public ActionResult Edit(Guid? Id, DocumentModel model, string button) { using (var context = new DataModelDataContext()) { if (!ModelState.IsValid) { return View(model); } Document target = null; if (model.Id != Guid.Empty) { target = context.Documents.SingleOrDefault(d=>d.Id == model.Id); if (target == null) { ModelState.AddModelError("", "Row not found!"); return View(model); } } else { target = new Document(); target.Id = Guid.NewGuid(); target.AuthorId = model.AuthorId; target.StateName = model.StateName; context.Documents.InsertOnSubmit(target); } target.Name = model.Name; target.EmloyeeControlerId = model.EmloyeeControlerId; target.Comment = model.Comment; target.Sum = model.Sum; try { context.SubmitChanges(); } catch (Exception ex) { var sb = new StringBuilder("Ошибка сохранения. " + ex.Message); if (ex.InnerException != null) sb.AppendLine(ex.InnerException.Message); ModelState.AddModelError("", sb.ToString()); return View(model); } if (button == "SaveAndExit") return RedirectToAction("Index"); if (button != "Save") { ExecuteCommand(target.Id, button, model); } return RedirectToAction("Edit", new {target.Id}); } return View(model); }
private List<LoadTestingStatisticsModel> GetStatistics(int unit) { TimeSpan ts = new TimeSpan(0, 0, unit); var res = new List<LoadTestingStatisticsModel>(); using (var context = new DataModelDataContext()) { foreach (var op in context.LoadTestingOperations) { op.Date = Floor(op.Date, ts); var r = res.FirstOrDefault(c => c.Date == op.Date); if (r == null) { r = new LoadTestingStatisticsModel() { Date = op.Date }; res.Add(r); } var item = r.Items.FirstOrDefault(c => c.Type == op.Type); if (item == null) { item = new LoadTestingStatisticItemModel() { Type = op.Type }; r.Items.Add(item); } item.Duration += op.DurationMilliseconds; item.CheckDurationMinMax(op.DurationMilliseconds); item.Count++; } } return res; }
private void AddOperation(DateTime opStart, DateTime opEnd, string type) { using (var context = new DataModelDataContext()) { TimeSpan duration = opEnd - opStart; context.LoadTestingOperations.InsertOnSubmit(new LoadTestingOperation() { Id = Guid.NewGuid(), Date = opStart, Type = type, DurationMilliseconds = duration.TotalMilliseconds }); context.SubmitChanges(); } }
private void WFCommandExecute(object cnt) { var emps = EmployeeHelper.GetAll(); Random r = new Random(Environment.TickCount); int count = (int)cnt; for (int i = 0; i < count; ) { int oldI = i; for (int k = 0; k < emps.Count - 1; k++) { var employee = emps[k]; Guid? docId = null; using (var context = new DataModelDataContext()) { int inboxCount = context.WorkflowInboxes.Count(c => c.IdentityId == employee.Id); if (inboxCount > 0) { var tmp = context.WorkflowInboxes .Where(c => c.IdentityId == employee.Id) .Skip(r.Next(0, inboxCount)) .Take(1) .FirstOrDefault(); if (tmp != null) docId = tmp.ProcessId; } } if (docId.HasValue) { DateTime opStart = DateTime.Now; var commands = WorkflowInit.Runtime.GetAvailableCommands(docId.Value, employee.Id.ToString("N")).ToArray(); AddOperation(opStart, DateTime.Now, "GetAvailableCommands"); if (commands.Length > 0) { var c = commands[r.Next(0, commands.Length)]; c.SetParameter("Comment", "Load testing. ExecuteCommand"); opStart = DateTime.Now; try { WorkflowInit.Runtime.ExecuteCommand(docId.Value, employee.Id.ToString("N"), employee.Id.ToString("N"), c); } catch (ImpossibleToSetStatusException ex) { //If process is Running then ignore it's continue; } catch (CommandNotValidForStateException ex) { //If process is changed state then ignore it's continue; } AddOperation(opStart, DateTime.Now, "ExecuteCommand"); i++; break; } } } if (oldI == i) break; } }