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;
                    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"));
        }
Ejemplo n.º 2
0
        public ActionResult Index(HttpPostedFileBase file, bool noupdate)
        {
            string host          = Util.Host;
            var    runningtotals = new UploadPeopleRun {
                Started = DateTime.Now, Count = 0, Processed = 0
            };

            CurrentDatabase.UploadPeopleRuns.InsertOnSubmit(runningtotals);
            CurrentDatabase.SubmitChanges();
            var pid = Util.UserPeopleId;

            var package = new ExcelPackage(file.InputStream);

            HostingEnvironment.QueueBackgroundWorkItem(ct =>
            {
                try
                {
                    var db = DbUtil.Create(host);

                    var m = new UploadPeopleModel(host, pid ?? 0, noupdate, testing: true);
                    m.DoUpload(package);
                    CurrentDatabase.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(package);
                }
                catch (Exception ex)
                {
                    //CurrentDatabase.Dispose();
                    var 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"));
        }
Ejemplo n.º 3
0
        private UploadPeopleRun ProcessImport(CMSDataContext db, bool noupdate, string host, int?pid, ExcelPackage package, bool testing)
        {
            var rt = new UploadPeopleRun {
                Started = DateTime.Now, Count = 0, Processed = 0
            };

            db.UploadPeopleRuns.InsertOnSubmit(rt);
            db.SubmitChanges();

            var upload = new UploadPeopleModel(db, host, pid ?? 0, noupdate, testing);

            upload.DoUpload(package);

            return(rt);
        }
Ejemplo n.º 4
0
        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"));
        }