Esempio n. 1
0
        public DataAsyncResult EnqueueRequest(Func<object> operation, TaskParam parameters)
        {
            DataAsyncResult result = new DataAsyncResult(null, false);
            var newRequest = new Task()
            {
                Operation = operation,
                AsyncResult = result,
                Parameters = parameters
            };

            lock (this.taskSyncRoot)
            {
                this.tasks.Enqueue(newRequest);
            }
            return result;
        }
Esempio n. 2
0
 private DataAsyncResult Initialize(TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         var entities = base.GlobalDataService.SelectAll();
         this.Videos = entities.Videos;
         this.Songs = entities.Songs;
         this.Albums = entities.Albums;
         this.Artists = entities.Artists;
         this.Playlists = entities.Playlists;
         this.PlaylistsAudioMedia = entities.PlaylistsAudioMedia;
         this.Bind(this.Artists, this.Albums, this.Songs, this.Playlists, this.PlaylistsAudioMedia);
         this.CheckFilesystemIds(this.Songs, this.Videos);
         this.DisableProtectModeInternal();
         return null;
     });
 }
Esempio n. 3
0
 public DataAsyncResult UpdatePlaylist(Playlist entity, TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         base.PlaylistDataService.Update(entity);
         return null;
     });
 }
Esempio n. 4
0
 public DataAsyncResult UpdateVideoMedia(VideoMedia entity, string title, bool isProtected, TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         entity.Title = title;
         entity.IsProtected = isProtected;
         base.VideoMediaDataService.Update(entity);
         return null;
     });
 }
Esempio n. 5
0
 public DataAsyncResult UpdateAlbum(Album entity, TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         base.AlbumDataService.Update(entity);
         return null;
     });
 }
Esempio n. 6
0
        public DataAsyncResult UpdateAudioMedia(AudioMedia entity, string title, string album, string artist, bool isProtected, List<int> playlistsToAdd, List<int> playlistsToRemove, TaskParam taskParam)
        {
            return this.EnqueueRequest(taskParam, () =>
            {
                // find or create artist entity
                var artistEntity = this.Artists.FirstOrDefault(x => x.Name.Trim().ToUpper() == artist.Trim().ToUpper());
                if (artistEntity == null)
                {
                    artistEntity = new Artist() { Name = artist };
                    base.ArtistDataService.Insert(artistEntity);
                    this.Artists.Add(artistEntity);
                }

                // find or create album entity
                var albumEntity = artistEntity.Albums.FirstOrDefault(x => x.Title.Trim().ToUpper() == album.Trim().ToUpper());
                if (albumEntity == null)
                {
                    albumEntity = new Album() { ArtistId = artistEntity.Id, Title = album };
                    base.AlbumDataService.Insert(albumEntity);
                    artistEntity.Albums.Add(albumEntity);
                    this.Albums.Add(albumEntity);
                    albumEntity.Artist = artistEntity;
                }

                // update audiomedia entity
                int previousAlbumId = entity.Album.Id;
                entity.Title = title;
                entity.IsProtected = isProtected;
                entity.AlbumId = albumEntity.Id;
                entity.Album = albumEntity;
                base.AudioMediaDataService.Update(entity);

                // reflect changes into database and the cache
                if (previousAlbumId != albumEntity.Id)
                {
                    albumEntity.Songs.Add(entity);
                    var previousAlbum = this.Albums.FirstOrDefault(x => x.Id == previousAlbumId);
                    previousAlbum.Songs.Remove(entity);
                    if (previousAlbum.Songs.Count == 0)
                    {
                        var previousArtist = previousAlbum.Artist;
                        base.AlbumDataService.Delete(new Album() { Id = previousAlbum.Id });
                        previousArtist.Albums.Remove(previousAlbum);
                        this.Albums.Remove(previousAlbum);
                        if (previousArtist.Albums.Count == 0)
                        {
                            base.ArtistDataService.Delete(new Artist() { Id = previousArtist.Id });
                            this.Artists.Remove(previousArtist);
                        }
                    }
                }

                foreach (var item in playlistsToAdd)
                {
                    var playlist = this.Playlists.First(x => x.Id == item);
                    this.AddAudioMediaToPlaylist(entity, playlist);
                }

                foreach (var item in playlistsToRemove)
                {
                    var playlist = this.Playlists.First(x => x.Id == item);
                    this.RemoveAudioMediaFromPlaylist(entity, playlist);
                }

                return null;
            });
        }
Esempio n. 7
0
        public DataAsyncResult ImportOldMedias(TaskParam taskParam)
        {
            Action<string, string, bool, string> import = (directory, type, protect, destination) =>
            {
                using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
                {
                    if (store.DirectoryExists(directory))
                    {
                        var files = store.GetFileNames(directory + "\\*");
                        foreach (var file in files)
                        {
                            string title = Path.GetFileNameWithoutExtension(file);
                            string extension = Path.GetExtension(file);
                            string filesystemId = Guid.NewGuid().ToString() + extension;
                            if (type == "audio")
                            {
                                this.AddAudioMediaInternal(title, "", "", filesystemId, protect);
                            }
                            else
                            {
                                this.AddVideoMediaInternal(title, filesystemId, protect);
                            }
                            store.MoveFile(Path.Combine(directory, file), Path.Combine(destination, filesystemId));
                        }
                    }
                }
            };

            using (IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (!store.DirectoryExists("medias"))
                {
                    store.CreateDirectory("medias");
                }
            }

            return this.EnqueueRequest(taskParam, () =>
            {
                Thread.Sleep(10000);
                import("/mediaMusic", "audio", false, "medias");
                import("/mediaMusic/protected", "audio", true, "medias");
                import("/mediaVideo", "video", false, "medias");
                import("/mediaVideo/protected", "video", true, "medias");
                this.DisableProtectModeInternal();
                return null;
            });
        }
Esempio n. 8
0
 public DataAsyncResult SendToVideoLibrary(AudioMedia entity, TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         var title = entity.Title;
         var fileSystemId = entity.FilesystemId;
         var isProtected = entity.IsProtected;
         this.DeleteAudioMediaInternal(entity);
         this.AddVideoMediaInternal(title, fileSystemId, isProtected);
         return null;
     });
 }
Esempio n. 9
0
 public DataAsyncResult DisableProtectMode(TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         this.DisableProtectModeInternal();
         return null;
     });
 }
Esempio n. 10
0
        public DataAsyncResult EnableProtectMode(TaskParam taskParam)
        {
            return this.EnqueueRequest(taskParam, () =>
            {
                for (int i = 0; i < this.Artists.Count; i++)
                {
                    var artist = this.Artists[i];
                    artist.Visible = true;
                    for (int j = 0; j < artist.Albums.Count; j++)
                    {
                        var album = artist.Albums[j];
                        album.Visible = true;
                        for (int k = 0; k < album.Songs.Count; k++)
                        {
                            album.Songs[k].Visible = true;
                        }
                    }
                }

                for (int i = 0; i < this.Videos.Count; i++)
                {
                    this.Videos[i].Visible = true;
                }

                for (int i = 0; i < this.Playlists.Count; i++)
                {
                    this.Playlists[i].Visible = true;
                }
                return null;
            });
        }
Esempio n. 11
0
 public DataAsyncResult DeleteVideoMedia(VideoMedia entity, TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         DeleteVideoMediaInternal(entity);
         return null;
     });
 }
Esempio n. 12
0
 public DataAsyncResult DeleteAllProtectedMedia(TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         var songsToDelete = this.Songs.Where(x => x.IsProtected).ToList();
         foreach (var song in songsToDelete)
         {
             this.DeleteAudioMediaInternal(song);
         }
         var videosToDelete = this.Videos.Where(x => x.IsProtected).ToList();
         foreach (var video in videosToDelete)
         {
             this.DeleteVideoMediaInternal(video);
         }
         return null;
     });
 }
Esempio n. 13
0
 public DataAsyncResult AddVideoMedia(string title, string filesystemId, bool isProtected, TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         this.AddVideoMediaInternal(title, filesystemId, isProtected);
         return null;
     });
 }
Esempio n. 14
0
 public DataAsyncResult AddPlaylist(string title, TaskParam taskParam)
 {
     return this.EnqueueRequest(taskParam, () =>
     {
         var entity = new Playlist()
         {
             Title = title,
             Visible = true
         };
         base.PlaylistDataService.Insert(entity);
         this.Playlists.Add(entity);
         return null;
     });
 }
 public DataAsyncResult EnqueueRequest(TaskParam parameters, Func<object> operation)
 {
     return scheduler.EnqueueRequest(operation, parameters);
 }