public ActionResult Upload(string text, bool noupdate) { string host = Util.Host; var runningtotals = new UploadPeopleRun { Started = DateTime.Now, Count = 0, Processed = 0 }; DbUtil.Db.UploadPeopleRuns.InsertOnSubmit(runningtotals); DbUtil.Db.SubmitChanges(); var pid = Util.UserPeopleId; var cs = Util.GetConnectionString(host); Alias.Task.Factory.StartNew(() => { Thread.CurrentThread.Priority = ThreadPriority.Lowest; var Db = new CMSDataContext(cs); Db.Host = host; try { var m = new UploadPeopleModel(Db, pid ?? 0, noupdate, cs); m.DoUpload(text, testing: true); Db.Dispose(); Db = new CMSDataContext(cs); Db.Host = host; runningtotals = new UploadPeopleRun { Started = DateTime.Now, Count = 0, Processed = 0 }; Db.UploadPeopleRuns.InsertOnSubmit(runningtotals); Db.SubmitChanges(); m = new UploadPeopleModel(Db, pid ?? 0, noupdate, cs); m.DoUpload(text); } catch (Exception ex) { Db.Dispose(); Db = new CMSDataContext(cs); Db.Host = host; var q = from r in Db.UploadPeopleRuns where r.Id == Db.UploadPeopleRuns.Max(rr => rr.Id) select r; var rt = q.Single(); rt.Error = ex.Message.Truncate(200); Db.SubmitChanges(); } }); return Redirect("/UploadPeople/Progress"); }
public ActionResult Index(string text, bool noupdate) { string host = Util.Host; var runningtotals = new UploadPeopleRun { Started = DateTime.Now, Count = 0, Processed = 0 }; DbUtil.Db.UploadPeopleRuns.InsertOnSubmit(runningtotals); DbUtil.Db.SubmitChanges(); var pid = Util.UserPeopleId; HostingEnvironment.QueueBackgroundWorkItem(ct => { var Db = DbUtil.Create(host); try { var m = new UploadPeopleModel(host, pid ?? 0, noupdate, testing: true); m.DoUpload(text); Db.Dispose(); Db = DbUtil.Create(host); runningtotals = new UploadPeopleRun { Started = DateTime.Now, Count = 0, Processed = 0 }; Db.UploadPeopleRuns.InsertOnSubmit(runningtotals); Db.SubmitChanges(); m = new UploadPeopleModel(host, pid ?? 0, noupdate); m.DoUpload(text); } catch (Exception ex) { Db.Dispose(); Db = DbUtil.Create(host); var q = from r in Db.UploadPeopleRuns where r.Id == Db.UploadPeopleRuns.Max(rr => rr.Id) select r; Elmah.ErrorLog.GetDefault(null).Log(new Elmah.Error(ex)); var rt = q.Single(); rt.Error = ex.Message.Truncate(200); Db.SubmitChanges(); } }); return Redirect("/UploadPeople/Progress"); }