Ejemplo n.º 1
0
        /// <summary>
        /// Adds an <see cref="IVideoSource"/> to the database. If an <see cref="IVideoSource"/> with the same path ID exists,
        /// it will be updated with new settings.
        /// </summary>
        /// <param name="newSource"><see cref="EditableVideoSource"/> containing the new source data.</param>
        public async Task AddSourceAsync(EditableVideoSource newSource)
        {
            if (!dbConnection.IsInitialized)
            {
                await dbConnection.InitializeAsync();
            }

            await AddPathAsync(newSource.Path);
            var pathId = await GetPathIdAsync(newSource.Path);
            var source = new VideoSource
            {
                PathId = pathId,
                Name = newSource.Name,
                ContentType = newSource.ContentType,
                InfoSource = newSource.InfoSource,
                NoUpdate = newSource.NoUpdate
            };

            var storedModel = await dbConnection.FindAsync<VideoSource>(sm => sm.PathId == source.PathId);
            if (storedModel != null)
            {
                if (storedModel.Name != source.Name || storedModel.ContentType != source.ContentType ||
                    storedModel.InfoSource != source.InfoSource || storedModel.NoUpdate != source.NoUpdate)
                {
                    storedModel.Name = source.Name;
                    storedModel.ContentType = source.ContentType;
                    storedModel.InfoSource = source.InfoSource;
                    storedModel.NoUpdate = source.NoUpdate;
                    await dbConnection.UpdateAsync(storedModel);
                }
            }
            else
            {
                await dbConnection.InsertAsync(source);
            }
        }
Ejemplo n.º 2
0
 private void SetNewSource()
 {
     EditableVideoSource.ErrorsChanged -= RaiseCanExecuteChanged;
     videoSourceCache = null;
     EditableVideoSource = new EditableVideoSource();
     EditableVideoSource.ErrorsChanged += RaiseCanExecuteChanged;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates an existing <see cref="IVideoSource"/> with new data.
        /// </summary>
        /// <param name="existingSource">The <see cref="IVideoSource"/> that will be updated.</param>
        /// <param name="newSourceData"><see cref="EditableVideoSource"/> containing the new source data.</param>
        public async Task UpdateSourceAsync(IVideoSource existingSource, EditableVideoSource newSourceData)
        {
            if (!dbConnection.IsInitialized)
            {
                await dbConnection.InitializeAsync();
            }

            await AddPathAsync(newSourceData.Path);
            var pathId = await GetPathIdAsync(newSourceData.Path);
            existingSource.PathId = pathId;
            existingSource.Name = newSourceData.Name;
            existingSource.ContentType = newSourceData.ContentType;
            existingSource.InfoSource = newSourceData.InfoSource;
            existingSource.NoUpdate = newSourceData.NoUpdate;

            await dbConnection.UpdateAsync((VideoSource)existingSource);
        }