public void UpdateData(Position[] positions, Int64 lastModifiedDate, AucTraderDbContext db)
        {
            const int MX           = 300;
            int       mx           = MX;
            DateTime  baseDateTime = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            DateTime  datetime     = baseDateTime.AddMilliseconds(lastModifiedDate).ToLocalTime();

            for (int i = 0; i < positions.Length; i++)
            {
                Position aucPosition = positions[i];
                aucPosition.LoadDateTime = datetime;

                db.Positions.Add(aucPosition);

                if (i == mx)
                {
                    mx += MX;
                    db.SaveChanges();
                    db.Dispose();
                    db = new AucTraderDbContext();
                }
            }

            db.SaveChanges();
        }
        public ActionResult Update()
        {
            UpdateModel model = new UpdateModel()
            {
                Status = "Fail"
            };

            IAucDataLoader aucDataLoader = new AucDataLoader();

            model.Data = aucDataLoader.GetAucResponse();

            DateTime datetime;
            var      file = aucDataLoader.GetAucJsonFile(out datetime);

            Task task = new Task(() =>
            {
                AucTraderDbContext db = new AucTraderDbContext();
                const int MX          = 300;
                int mx = MX;

                StringBuilder builder = new StringBuilder();
                builder.Append("select * from Position where Auc in (");
                Int64 last = file.AucPositions.Last().Auc;
                file.AucPositions
                .ForEach(el =>
                {
                    builder.Append(el.Auc);
                    if (el.Auc != last)
                    {
                        builder.Append(", ");
                    }
                });
                builder.Append(")");

                for (int i = 0; i < file.AucPositions.Length; i++)
                {
                    Position aucPosition     = file.AucPositions[i];
                    aucPosition.LoadDateTime = datetime;

                    db.Positions.Add((Position)aucPosition);

                    if (i == mx)
                    {
                        mx += MX;
                        db.SaveChanges();
                        db.Dispose();
                        db = new AucTraderDbContext();
                    }
                }

                db.SaveChanges();
            });

            task.Start();

            return(View("Index", model));
        }
Exemple #3
0
 protected override void Dispose(bool disposing)
 {
     db.Dispose();
     base.Dispose(disposing);
 }