public static void UpdateFrom <T>(this IDbRecord record, T sourceEntity) where T : IDbEntity { if (sourceEntity == null) { return; } var map = DbMapping.Get(sourceEntity.GetType()); if (map == null || map.PropertiesInfos == null || map.PropertiesInfos.Count == 0) { return; } foreach (var property in map.PropertiesInfos) { var value = property.GetValue(sourceEntity); if (value == null) { continue; } if (record[property.Name] != value) { record[property.Name] = value; } } }
public static void LoadAppWithArguments(string arguments) { var args = arguments.Split('=', '&'); if (!args?.Any() == null || string.IsNullOrEmpty(arguments)) { return; } string action = args[1]; if (action.Contains("view")) { string pageParameter = args[5]; IDbRecord record = null; if (action.Contains("Album")) { record = SharedLogic.Instance.AlbumArtistService.GetAlbumByIdAsync(Convert.ToInt64(pageParameter)); } else if (action.Contains("Artist")) { record = SharedLogic.Instance.AlbumArtistService.GetArtistByIdAsync(Convert.ToInt64(pageParameter)); } else if (action.Contains("Playlist")) { record = SharedLogic.Instance.PlaylistService.GetPlaylistByIdAsync(Convert.ToInt64(pageParameter)); } if (record == null) { return; } SplitViewMenu.SplitViewMenu.UnSelectAll(); NavigationService.Instance.Frame.Navigate(typeof(PlaylistView), record); } }
public static bool Populate <T>(this IDbRecord record, ref T entityToPopulate) where T : IDbEntity { var map = DbMapping.Get(typeof(T)); if (map?.PropertiesInfos == null || map.PropertiesInfos.Count == 0) { return(false); } var result = false; //Property Key var keyValue = map.PropertyInfoKey.GetValue(entityToPopulate) as string; if (keyValue != record.Id) { map.PropertyInfoKey.SetValue(entityToPopulate, record.Id); result = true; } //Others foreach (var fieldName in record.FieldNames) { var property = map.PropertiesInfos.FirstOrDefault(p => p.Name == fieldName); if (property != null) { var oldValue = property.GetValue(entityToPopulate); var value = record[fieldName]; if (oldValue != value) { property.SetValue(entityToPopulate, value.ConvertValue(property.PropertyType)); result = true; } } } return(result); }
public async Task InsertRecord(IDbRecord record) { await Task.Run(() => { ReinitEngine(); using (var tran = _engine.GetTransaction()) { tran.Technical_SetTable_OverwriteIsNotAllowed(_tableName); record.Id = tran.ObjectGetNewIdentity <long>(_tableName); tran.ObjectInsert(_tableName, new DBreezeObject <IDbRecord> { Indexes = new List <DBreezeIndex> { new DBreezeIndex(1, record.Id) { PrimaryIndex = true } }, NewEntity = true, //Changes Select-Insert pattern to Insert (speeds up insert process) Entity = record //Entity itself }, true); tran.TextInsert(_textTableName, record.Id.To_8_bytes_array_BigEndian(), record.GetTextSearchKey()); tran.Commit(); } }); }
public Task RemoveRecord(IDbRecord record) { return(Task.Run(() => { currentCollection.Delete(record.Id); })); }
public Task InsertRecord(IDbRecord record) { return(Task.Run(() => { record.Id = Guid.NewGuid().GetHashCode(); currentCollection.Insert(record); })); }
protected internal void SetInitialRecordValues(IDbRecord record) { var now = Now; record.DateCreated = now; record.LastModified = now; record.Deleted = false; }
public void Delete(IDbRecord record, bool autoSync = true) { record.DeleteRecord(); if (autoSync) { Store.Sync(); } }
public async Task InsertTracksAsync(IEnumerable <Mediafile> fileCol, IDbRecord pList) { IEnumerable <ChildSong> playlistSongs = fileCol.Select(x => new ChildSong() { SongId = x.Id, PlaylistId = pList.Id }); Database.ChangeTable(_tablename, _texttablename); await Database.InsertRecords(playlistSongs); }
public async Task RemoveRecord(IDbRecord record) { await Task.Run(() => { using (var tran = _engine.GetTransaction()) { tran.ObjectRemove(_tableName, 1.ToIndex(record.Id)); //remove from text engine too tran.TextRemove(_textTableName, record.Id.To_8_bytes_array_BigEndian(), record.GetTextSearchKey()); tran.Commit(); } }); }
public async Task RemoveRecord(IDbRecord record) { await Task.Run(() => { using (var tran = _engine.GetTransaction()) { tran.SynchronizeTables("Tracks", "TracksText", "Playlists", "Albums", "AlbumsText", "PlaylistsText", "PlaylistSongs", "PlaylistSongsText"); tran.ObjectRemove(_tableName, 1.ToIndex(record.Id)); //remove from text engine too tran.TextRemove(_textTableName, record.Id.To_8_bytes_array_BigEndian(), record.GetTextSearchKey()); tran.Commit(); } }); }
public async Task InsertTracksAsync(IEnumerable <Mediafile> fileCol, IDbRecord pList) { List <ChildSong> playlistSongs = new List <ChildSong>(); foreach (var file in fileCol) { playlistSongs.Add(new ChildSong { SongId = file.Id, PlaylistId = pList.Id }); } Database.ChangeTable(_tablename, _texttablename); await Database.InsertRecords(playlistSongs); }
public DbRecordChangedEventArgs(IDbRecord dbRecord) { DbRecord = dbRecord; }
/// <summary> /// Call this method whenever the value of a collection item has changed. /// </summary> /// <param name="Record">The collection item that has changed.</param> public void RecordChanged(IDbRecord Record) { if (SelectedRecord == null) return; UpdateRecordInListView(Record); }
/// <summary> /// Adds a specific record to the given list view. /// </summary> /// <param name="Record">The record to add to the list view.</param> /// <returns>The newly created list view item.</returns> /// <exception cref="System.ArgumentNullException">Thrown when one of the input parameters is null.</exception> protected virtual ListViewItem AddRecordToListView(IDbRecord Record) { if (Record == null) throw new ArgumentNullException("Record"); ListViewItem item = new ListViewItem(); UpdateListViewItemForRecord(Record, item); return List.Items.Add(item); }
/// <summary> /// Updates a single record in the right list view without the need to recreate the whole list view. /// </summary> /// <param name="Record">The record whose changes should be propagated to the list view.</param> /// <exception cref="System.ArgumentNullException">Thrown when one of the input parameters is null.</exception> protected virtual void UpdateRecordInListView(IDbRecord Record) { if (Record == null) throw new ArgumentNullException("Record"); foreach (ListViewItem item in List.Items) { if ((IEditableDbRecord)item.Tag != Record) continue; UpdateListViewItemForRecord(Record, item); break; } }
/// <summary> /// Updates the list view item with the information provided by the record and according the the column definition. /// </summary> /// <param name="Record">The record to use.</param> /// <param name="Item">The item to apply the information too.</param> /// <exception cref="System.ArgumentNullException">Thrown when one of the input parameters is null.</exception> protected virtual void UpdateListViewItemForRecord(IDbRecord Record, ListViewItem Item) { if (Record == null) throw new ArgumentNullException("Record"); if (Item == null) throw new ArgumentNullException("Item"); // Use the column definition to set up the text to be shown for (int i = 0; i < Columns.Length; i++) { ColumnDefinition column = Columns[i]; string text = column.GetFormattedValue(Record); if (i == 0) { Item.Text = text; } else { // Item.Text counts towards Item.SubItems.Count, thus -1 if (Item.SubItems.Count - 1 < i) Item.SubItems.Add(text); else Item.SubItems[i].Text = text; } } Item.Tag = Record; }