Example #1
0
        public ActionResult CheckPurchaseItem()
        {
            SyncResult result = new SyncResult();

            try
            {
                IRepository <Packages> Packages = new GenericRepository <Packages>(db);
                IRepository <Items>    Items    = new GenericRepository <Items>(db);

                string[] productIDs = Packages.GetAll(true).Where(p => p.ProcessStatus == (int)EnumData.ProcessStatus.待出貨).Join(Items.GetAll(true), p => p.ID, i => i.PackageID, (p, i) => i.ProductID).Distinct().ToArray();

                if (productIDs.Length == 0)
                {
                    return(Content(JsonConvert.SerializeObject(result.set_error("沒有需要同步的產品!")), "appllication/json"));
                }

                TaskFactory factory    = System.Web.HttpContext.Current.Application.Get("TaskFactory") as TaskFactory;
                ThreadTask  threadTask = new ThreadTask("產品序號同步工作");

                lock (factory)
                {
                    threadTask.AddWork(factory.StartNew(Session =>
                    {
                        threadTask.Start();

                        string message = "";
                        HttpSessionStateBase session = (HttpSessionStateBase)Session;

                        try
                        {
                            SyncProcess Sync = new SyncProcess(session);
                            message          = Sync.Sync_PurchaseItem(productIDs);
                        }
                        catch (DbEntityValidationException ex)
                        {
                            var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
                            message           = string.Join("; ", errorMessages);
                        }
                        catch (Exception e)
                        {
                            message = e.Message;
                        }

                        return(message);
                    }, HttpContext.Session));
                }

                result.taskID = threadTask.ID;
            }
            catch (Exception e)
            {
                return(Content(JsonConvert.SerializeObject(result.set_error(e.Message)), "appllication/json"));
            }

            return(Content(JsonConvert.SerializeObject(result), "appllication/json"));
        }
Example #2
0
        public ActionResult GetOrder(List <string> orderIDs)
        {
            SyncResult result = new SyncResult();

            if (!orderIDs.Any())
            {
                return(Content(JsonConvert.SerializeObject(result.set_error("沒有取得訂單號碼!")), "appllication/json"));
            }

            try
            {
                TaskFactory factory = System.Web.HttpContext.Current.Application.Get("TaskFactory") as TaskFactory;

                foreach (string orderID in orderIDs)
                {
                    ThreadTask threadTask = new ThreadTask(string.Format("訂單管理區 - 訂單【{0}】資料同步", orderID));

                    lock (factory)
                    {
                        threadTask.AddWork(factory.StartNew(Session =>
                        {
                            threadTask.Start();

                            string message = "";
                            HttpSessionStateBase session = (HttpSessionStateBase)Session;

                            try
                            {
                                SyncProcess Sync = new SyncProcess(session);
                                message          = Sync.Sync_Order(int.Parse(orderID));
                            }
                            catch (DbEntityValidationException ex)
                            {
                                var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
                                message           = string.Join("; ", errorMessages);
                            }
                            catch (Exception e)
                            {
                                message = e.InnerException != null && !string.IsNullOrEmpty(e.InnerException.Message) ? e.InnerException.Message : e.Message;
                            }

                            return(message);
                        }, HttpContext.Session));
                    }
                }
            }
            catch (Exception e)
            {
                return(Content(JsonConvert.SerializeObject(result.set_error(e.Message)), "appllication/json"));
            }

            return(Content(JsonConvert.SerializeObject(result), "appllication/json"));
        }
Example #3
0
        public ActionResult CheckOrder(int day)
        {
            SyncResult result = new SyncResult();

            try
            {
                TaskFactory factory    = System.Web.HttpContext.Current.Application.Get("TaskFactory") as TaskFactory;
                ThreadTask  threadTask = new ThreadTask(string.Format("同步{0}天訂單資料", day));

                lock (factory)
                {
                    threadTask.AddWork(factory.StartNew(Session =>
                    {
                        threadTask.Start();

                        string message = "";
                        HttpSessionStateBase session = (HttpSessionStateBase)Session;

                        try
                        {
                            SyncProcess Sync = new SyncProcess(session, factory);
                            message          = Sync.Sync_Orders(day);
                        }
                        catch (DbEntityValidationException ex)
                        {
                            var errorMessages = ex.EntityValidationErrors.SelectMany(x => x.ValidationErrors).Select(x => x.ErrorMessage);
                            message           = string.Join("; ", errorMessages);
                        }
                        catch (Exception e)
                        {
                            message = e.InnerException != null && !string.IsNullOrEmpty(e.InnerException.Message) ? e.InnerException.Message : e.Message;
                        }

                        return(message);
                    }, Session));
                }
            }
            catch (Exception e)
            {
                return(Content(JsonConvert.SerializeObject(result.set_error(e.Message)), "appllication/json"));
            }

            return(Content(JsonConvert.SerializeObject(result), "appllication/json"));
        }