public ActionResult UploadAddresses(string text)
        {
            string host = Util.Host;
            var pid = Util.UserPeopleId;
            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                var db = DbUtil.Create(host);
                try
                {
                    var runningtotals = new UploadPeopleRun { Started = DateTime.Now, Count = 0, Processed = 0 };
                    db.UploadPeopleRuns.InsertOnSubmit(runningtotals);
                    db.SubmitChanges();

                    var m = new UploadAddressesModel(db, pid ?? 0);
                    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("/Batch/UploadAddressesProgress");
        }
示例#2
0
        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");
        }