예제 #1
0
        public IActionResult Index(String code, String DBName, int beginId, int take,
                                   String uuid, String isWait)
        {
            var filePath = Configs.uploadFilePath;

            filePath = _hostingEnvironment.WebRootPath.TrimEnd('\\', '/')
                       + "/" + filePath.TrimEnd('\\', '/') + "/";
            System.IO.Directory.CreateDirectory(filePath);

            Response.ContentType = "text/plain;charset=utf-8";
            Response.Headers.Add("Access-Control-Allow-Origin", "*");
            Response.Headers.Add("Access-Control-Allow-Methods", "POST");
            Response.Headers.Add("Access-Control-Allow-Headers", "x-requested-with,content-type");

            String ml = filePath + "/" + code + "/";

            System.IO.Directory.CreateDirectory(ml);

            String         path   = filePath + "/" + code + "/" + DBName + ".db";
            var            lastId = 0L;
            var            locker = SqliteLock.getLockObj(path);
            String         dbUUid = null;
            DownloadResult dr     = new DownloadResult();

            lock (locker)
            {
                dbUUid = OpSqlite.getQuickSaveValue("uuid", path);
                lastId = OpSqlite.getMaxID(path) ?? 0;
                LastID.setLastId(path, lastId);
                dr.maxId = lastId;
                if (dbUUid != (uuid) && !string.IsNullOrEmpty(uuid))
                {
                    if (lastId == 0)
                    {
                        dr.status = (-2);
                    }
                    else
                    {
                        dr.status = (-1);
                    }
                }
                else if (beginId - 1 > lastId)
                {
                    dr.status = (-2);
                }
            }

            if (dr.status != -1 && dr.status != -2)
            {
                int jsq = 0;
                while (lastId != 0 && lastId < (long)beginId && jsq < 120 && "1" == (isWait))
                {
                    Thread.Sleep(500);
                    lastId = LastID.getLastId(path) ?? 0;
                    jsq++;
                }
                lock (locker)
                {
                    dr.status = (1);
                    List <DBObj> db = OpSqlite.SelectDBObj(beginId, take, path);
                    dr.uuid  = (dbUUid);
                    dr.data  = (db);
                    dr.maxId = (lastId);
                    if (db.Count > 0)
                    {
                        List <long> dels = OpSqlite.SelectDelIds(db[(0)].id, db[(db.Count - 1)].id, path);
                        dr.delIds = (dels);
                    }
                }
            }

            return(Json(dr));
        }
예제 #2
0
        public void Test2()
        {
            var filepath = "2.db";

            try
            {
                File.Delete(filepath);
            }
            catch { }
            var localGUID  = "localGUID1";
            var uploadGUID = 1;
            var data       = new List <DBObj>()
            {
                new DBObj()
                {
                    id       = 1,
                    objuuid  = "o1",
                    uuid     = "u1",
                    data     = "v1",
                    isDelete = 0
                },
                new DBObj()
                {
                    id       = 2,
                    objuuid  = "o2",
                    uuid     = "u2",
                    data     = "v2",
                    isDelete = 0
                }
            };

            Assert.AreEqual(0, OpSqlite.getMaxID(filepath) ?? 0);

            var res = OpSqlite.SelectDBObj(0, 100, filepath);

            //Assert.AreEqual(0, OpSqlite.getMaxID(filepath) ?? 0);
            OpSqlite.InsertDBObjLst(data, filepath, localGUID, uploadGUID++.ToString(), false);
            Assert.AreEqual(2, OpSqlite.getMaxID(filepath) ?? 0);
            res = OpSqlite.SelectDBObj(0, 100, filepath);
            Assert.AreEqual(2, res.Count);
            Assert.AreEqual("o1", res[0].objuuid);
            Assert.AreEqual("v2", res[1].data);

            var data2 = new List <DBObj>()
            {
                new DBObj()
                {
                    id       = 1,
                    objuuid  = "o1",
                    uuid     = "u1",
                    data     = "v1",
                    isDelete = 1
                }
            };

            OpSqlite.InsertDBObjLst(data2, filepath, localGUID, uploadGUID++.ToString(), false);

            res = OpSqlite.SelectDBObj(0, 100, filepath);

            Assert.AreEqual(1, res.First(f => f.objuuid == "o1").isDelete);

            Assert.AreEqual(3, OpSqlite.getMaxID(filepath).Value);

            Assert.AreEqual(1, OpSqlite.SelectDelIds(0, 100, filepath)[0]);
        }