Beispiel #1
0
        public static DBNote ToDBNote(this DTONote dto, DBUser user, bool encrypt = false)
        {
            // ServiceStack's .PopulateWith is for some reasons
            // ORDERS of magnitudes slower than manually copying
            // TODO evaluate PopulateWith performance / bottleneck
            // or other mappers like ValueInjecter

            var db = new DBNote();

            db.Guid  = dto.Guid;
            db.Title = dto.Title;
            db.Text  = dto.Text;
            db.Tags  = dto.Tags;

            // dates
            db.ChangeDate         = dto.ChangeDate;
            db.MetadataChangeDate = dto.MetadataChangeDate;
            db.CreateDate         = dto.CreateDate;

            db.OpenOnStartup = dto.OpenOnStartup;
            db.Pinned        = dto.Pinned;

            db.Username = user.Username;

            return(db);
        }
Beispiel #2
0
        protected void SaveDBNote(DBNote db_note)
        {
            // archive any previously existing note into its own table
            // TODO: evaluate how we could re-use the same DBNote table, which will save us
            // a select + reinsert operation
            if (UseHistory)
            {
                var old_note = db.FirstOrDefault <DBNote> (n => n.CompoundPrimaryKey == db_note.CompoundPrimaryKey);
                if (old_note != null)
                {
                    var archived_note = new DBArchivedNote().PopulateWith(old_note);
                    // set the last known revision

                    if (Manifest.NoteRevisions.Keys.Contains(db_note.Guid))
                    {
                        archived_note.LastSyncRevision = Manifest.NoteRevisions[db_note.Guid];
                    }
                    db.Insert <DBArchivedNote> (archived_note);
                }
            }

            // unforunately, we can't know if that note already exist
            // so we delete any previous incarnations of that note and
            // re-insert
            db.Delete <DBNote> (n => n.CompoundPrimaryKey == db_note.CompoundPrimaryKey);
            db.Insert(db_note);
        }
Beispiel #3
0
        public static DBNote ToDBNote(this DTONote dto, DBUser user, bool encrypt = false)
        {
            // ServiceStack's .PopulateWith is for some reasons
            // ORDERS of magnitudes slower than manually copying
            // TODO evaluate PopulateWith performance / bottleneck
            // or other mappers like ValueInjecter

            var db = new DBNote ();

            db.Guid = dto.Guid;
            db.Title = dto.Title;
            db.Text = dto.Text;
            db.Tags = dto.Tags;

            // dates
            db.ChangeDate = dto.ChangeDate;
            db.MetadataChangeDate = dto.MetadataChangeDate;
            db.CreateDate = dto.CreateDate;

            db.OpenOnStartup = dto.OpenOnStartup;
            db.Pinned = dto.Pinned;

            db.Username = user.Username;

            return db;
        }
Beispiel #4
0
        private void EncryptNoteBody(DBNote note)
        {
            // decrypt the per note key
            var plaintext_key = note.EncryptedKey.DecryptWithKey(encryptionMasterKey, User.MasterKeySalt);

            note.IsEncypted = true;
            note.Text       = User.EncryptString(plaintext_key.ToByteArray(), note.Text).ToHexString();
        }
Beispiel #5
0
        private void DecryptNoteBody(DBNote note)
        {
            if (!note.IsEncypted)
            {
                return;
            }

            note.Decrypt(User, encryptionMasterKey);
            note.IsEncypted = false;
        }
Beispiel #6
0
        public static DTONote ToDTONote(this DBNote db)
        {
            var dto = new DTONote();

            dto.Guid  = db.Guid;
            dto.Title = db.Title;
            dto.Text  = db.Text;
            dto.Tags  = db.Tags;

            // dates
            dto.ChangeDate         = db.ChangeDate;
            dto.MetadataChangeDate = db.MetadataChangeDate;
            dto.CreateDate         = db.CreateDate;

            dto.OpenOnStartup = db.OpenOnStartup;
            dto.Pinned        = db.Pinned;

            return(dto);
        }
Beispiel #7
0
        private string GetEncryptedNoteKey(DBNote note)
        {
            // re-use the same key when saving a note
            string encrypted_per_note_key;

            var saved_note = db.FirstOrDefault <DBNote> (n => n.CompoundPrimaryKey == note.CompoundPrimaryKey);

            if (saved_note != null)
            {
                encrypted_per_note_key = saved_note.EncryptedKey;
            }
            else
            {
                // new note, generate a new key
                var rng = new RNGCryptoServiceProvider();
                encrypted_per_note_key = rng.Create256BitLowerCaseHexKey().EncryptWithKey(encryptionMasterKey, User.MasterKeySalt);
            }
            return(encrypted_per_note_key);
        }