コード例 #1
0
 public static IEnumerable <Versioned <T> > GetLatests <T>(this LiteRevisionsDB <T> revDb)
 {
     using (var db = revDb.OpenRead())
         return(db.Version1 <T>()
                .FindAll()
                .GroupBy(_ => _.GroupId)
                .Select(_ => _.Last()));
 }
コード例 #2
0
 public static LiteDatabase OpenRead <T>(this LiteRevisionsDB <T> revDb)
 {
     if (revDb._mem == null && !File.Exists(revDb.DbPath))
     {
         var db = revDb.Connect(LiteDB.FileMode.Shared);
         db.Dispose();
     }
     return(revDb.Connect(LiteDB.FileMode.ReadOnly));
 }
コード例 #3
0
        public static T GetById <T>(this LiteRevisionsDB <T> revDb, long groupId)
            where T : class
        {
            using (var db = revDb.OpenRead())
            {
                var vers = db.Version1 <T>()
                           .Find(_ => _.GroupId == groupId)
                           .OrderBy(_ => _.Id);

                return(vers.LastOrDefault()?.Content);
            }
        }
コード例 #4
0
 public static Versioned <T> Insert <T>(this LiteRevisionsDB <T> revDb,
                                        T doc, string author, string changeLog = null)
 {
     using (var db = revDb.OpenWrite())
         return(db.InsertVersioned(new Versioned <T>
         {
             GroupId = db.CountLatests <T>() + 1,
             Content = doc,
             ChangeLog = changeLog,
             ChangedBy = author,
             ChangeDate = DateTime.Now
         }));
 }
コード例 #5
0
        public static Versioned <T> Update <T>(this LiteRevisionsDB <T> revDb,
                                               long groupId, T newDTO, string updatedBy, string changeLog)
        {
            var newVer = new Versioned <T>
            {
                GroupId    = groupId,
                Content    = newDTO,
                ChangeLog  = changeLog,
                ChangedBy  = updatedBy,
                ChangeDate = DateTime.Now
            };

            using (var db = revDb.OpenWrite())
                return(db.InsertVersioned(newVer));
        }
コード例 #6
0
        private static LiteDatabase Connect <T>(this LiteRevisionsDB <T> revDb, LiteDB.FileMode fileMode)
        {
            var db = revDb._mem != null
                   ? new LiteDatabase(revDb._mem)
                   : new LiteDatabase(new ConnectionString
            {
                Filename  = revDb.DbPath,
                Journal   = false,
                Mode      = fileMode,
                LimitSize = long.MaxValue
            });

            if (fileMode != LiteDB.FileMode.ReadOnly)
            {
                db.Version1 <T>().EnsureIndex(nameof(Versioned <T> .GroupId));
            }

            return(db);
        }
コード例 #7
0
 public static LiteDatabase OpenWrite <T>(this LiteRevisionsDB <T> revDb)
 => revDb.Connect(LiteDB.FileMode.Shared);
コード例 #8
0
 public static long CountAll <T>(this LiteRevisionsDB <T> revDb)
 {
     using (var db = revDb.OpenRead())
         return(db.CountLatests <T>());
 }
コード例 #9
0
 public static long NextDocID <T>(this LiteRevisionsDB <T> revDb)
 => revDb.CountAll() + 1;