public OptimizedObservableCollectionMocker(IEnumerable <object> items)
            {
                OptimizedObservableCollection = new OptimizedObservableCollection <object>(items);
                OptimizedObservableCollection.CollectionChanged += (s, e) =>
                {
                    switch (e.Action)
                    {
                    case NotifyCollectionChangedAction.Add:
                        ItemsAddedCount++;
                        break;

                    case NotifyCollectionChangedAction.Remove:
                        ItemsRemovedCount++;
                        break;

                    case NotifyCollectionChangedAction.Replace:
                        ItemsReplacedCount++;
                        break;

                    case NotifyCollectionChangedAction.Reset:
                        ItemsResetCount++;
                        break;
                    }
                };
            }
Exemplo n.º 2
0
        private void Configure()
        {
            TracksByDateAdded = new OptimizedObservableCollection <Track>(
                _libraryService.Tracks.OrderByDescending(p => p.CreatedAt));
            TracksByTitle = AlphaKeyGroup.CreateGroups(_libraryService.Tracks, CultureInfo.CurrentCulture,
                                                       item => ((Track)item).Title);
            TracksByArtist = AlphaKeyGroup.CreateGroups(_libraryService.Tracks, CultureInfo.CurrentCulture,
                                                        item => ((Track)item).DisplayArtist);
            TracksByAlbum = AlphaKeyGroup.CreateGroups(_libraryService.Tracks, CultureInfo.CurrentCulture,
                                                       item => ((Track)item).AlbumTitle);

            ArtistsByName = AlphaKeyGroup.CreateGroups(
                _libraryService.Artists.Where(p => !p.IsSecondaryArtist), CultureInfo.CurrentCulture,
                item => ((Artist)item).Name);

            AlbumsByDateAdded = new OptimizedObservableCollection <Album>(
                _libraryService.Albums.OrderByDescending(p => p.Tracks.Min(track => track.CreatedAt)));
            AlbumsByTitle = AlphaKeyGroup.CreateGroups(_libraryService.Albums, CultureInfo.CurrentCulture,
                                                       item => ((Album)item).Title);
            AlbumsByArtist = AlphaKeyGroup.CreateGroups(_libraryService.Albums, CultureInfo.CurrentCulture,
                                                        item => ((Album)item).Artist.Name);

            _libraryService.Tracks.CollectionChanged  += OnCollectionChanged;
            _libraryService.Artists.CollectionChanged += OnCollectionChanged;
            _libraryService.Albums.CollectionChanged  += OnCollectionChanged;
        }
Exemplo n.º 3
0
 public CollectionService(
     ISqlService sqlService,
     ISqlService bgSqlService,
     IAppSettingsHelper appSettingsHelper,
     IDispatcherHelper dispatcher,
     IBitmapFactory bitmapFactory,
     IBitmapImage missingArtwork,
     string localFilePrefix,
     string artworkFilePath,
     string artistArtworkFilePath)
 {
     _bgSqlService          = bgSqlService;
     _sqlService            = sqlService;
     _dispatcher            = dispatcher;
     _appSettingsHelper     = appSettingsHelper;
     _bitmapFactory         = bitmapFactory;
     _missingArtwork        = missingArtwork;
     _localFilePrefix       = localFilePrefix;
     _artworkFilePath       = artworkFilePath;
     _artistArtworkFilePath = artistArtworkFilePath;
     Songs                = new OptimizedObservableCollection <Song>();
     Artists              = new OptimizedObservableCollection <Artist>();
     Albums               = new OptimizedObservableCollection <Album>();
     Playlists            = new OptimizedObservableCollection <Playlist>();
     PlaybackQueue        = new OptimizedObservableCollection <QueueSong>();
     ShufflePlaybackQueue = new OptimizedObservableCollection <QueueSong>();
 }
Exemplo n.º 4
0
 public CollectionService(
     ISqlService sqlService,
     ISqlService bgSqlService,
     IAppSettingsHelper appSettingsHelper,
     IDispatcherHelper dispatcher,
     IBitmapFactory bitmapFactory,
     IBitmapImage missingArtwork,
     string localFilePrefix,
     string artworkFilePath,
     string artistArtworkFilePath)
 {
     _bgSqlService = bgSqlService;
     _sqlService = sqlService;
     _dispatcher = dispatcher;
     _appSettingsHelper = appSettingsHelper;
     _bitmapFactory = bitmapFactory;
     _missingArtwork = missingArtwork;
     _localFilePrefix = localFilePrefix;
     _artworkFilePath = artworkFilePath;
     _artistArtworkFilePath = artistArtworkFilePath;
     Songs = new OptimizedObservableCollection<Song>();
     Artists = new OptimizedObservableCollection<Artist>();
     Albums = new OptimizedObservableCollection<Album>();
     Playlists = new OptimizedObservableCollection<Playlist>();
     PlaybackQueue = new OptimizedObservableCollection<QueueSong>();
     ShufflePlaybackQueue = new OptimizedObservableCollection<QueueSong>();
 }
Exemplo n.º 5
0
 public UserOperationViewModel(IUserOperationView view)
 {
     View           = view;
     View.ViewModel = this;
     SaveCommand    = new CommandHandler <object, object>(SaveCommandAction);
     CloseCommand   = new CommandHandler <object, object>(CloseCommandAction);
     _hardwares     = new OptimizedObservableCollection <Hardware>();
 }
Exemplo n.º 6
0
 public CustomArrayAdapter(Context context, int textViewResourceId, OptimizedObservableCollection <T> collection,
                           Func <int, View, ViewGroup, View> getView)
     : base(context, textViewResourceId, collection)
 {
     _getView    = getView;
     _collection = collection;
     collection.CollectionChanged += ObjectsOnCollectionChanged;
 }
Exemplo n.º 7
0
 public BbSearchOperationViewModel(IBbSearchOperationView view, CompositionContainer compositionContainer)
 {
     View                  = view;
     View.ViewModel        = this;
     ShellContainer        = compositionContainer;
     SaveDepartmentCommand = new CommandHandler <object, object>(SaveDepartmentCommandAction);
     _searchByCollection   = new OptimizedObservableCollection <BbSearchBy>();
 }
 public BbCircularOperationViewModel(IBbCircularOperationView view, CompositionContainer compositionContainer)
 {
     View                = view;
     View.ViewModel      = this;
     ShellContainer      = compositionContainer;
     _deptCollection     = new OptimizedObservableCollection <BbDepartment>();
     _categoryCollection = new OptimizedObservableCollection <BbCategory>();
     BrowseFileCommand   = new CommandHandler <object, object>(BrowseFileCommandAction);
 }
Exemplo n.º 9
0
 public BbSearchViewModel(IBbSearchView view, CompositionContainer compositionContainer)
 {
     View                  = view;
     View.ViewModel        = this;
     ShellContainer        = compositionContainer;
     Tag                   = "BB Search Category";
     _departmentCollection = new OptimizedObservableCollection <BbDepartment>();
     _categoryCollection   = new OptimizedObservableCollection <BbCategory>();
     NewBbCircularCommand  = new CommandHandler <object, object>(NewBbCircularCommandAction);
 }
Exemplo n.º 10
0
        OptimizedObservableCollection <Song> ConvertToObservable(IEnumerable <Song> enumerable)
        {
            OptimizedObservableCollection <Song> _songs = new OptimizedObservableCollection <Song>();

            foreach (Song song in enumerable)
            {
                _songs.Add(song);
            }
            return(_songs);
        }
Exemplo n.º 11
0
 public BbCircularViewModel(IBbCircularView view, CompositionContainer compositionContainer)
 {
     View                    = view;
     View.ViewModel          = this;
     ShellContainer          = compositionContainer;
     Tag                     = "Bangladesh Bank Circular";
     SearchCommand           = new CommandHandler <object, object>(SearchCommandAction);
     DownloadCommand         = new CommandHandler <object, object>(DownloadCommandAction);
     _bbSearchByCollection   = new OptimizedObservableCollection <BbSearchBy>();
     _bbSearchtermCollection = new OptimizedObservableCollection <BbCircularSearch>();
 }
Exemplo n.º 12
0
        public MainViewModel()
        {
            _client           = new TraktClient(Constants.TraktId);
            SearchSuggestions = new OptimizedObservableCollection <TraktShow>();
            TrendyShows       = new OptimizedObservableCollection <TraktShow>();
            PopularShows      = new OptimizedObservableCollection <TraktShow>();
            Shows             = new OptimizedObservableCollection <TraktShow>();

            PullSearchSuggestionsCommand = new DelegateCommandAsync <bool>(PullSearchSuggestionAsync);
            PerformSearchQueryCommand    = new DelegateCommandAsync <TraktShow>(PerformSearchQueryAsync);
        }
Exemplo n.º 13
0
 public PlayerService(ISettingsUtility settingsUtility, IDispatcherUtility dispatcherUtility,
                      IMatchEngineService matchEngineService, IConverter <WebSong, Track> webSongConverter)
 {
     _settingsUtility    = settingsUtility;
     _dispatcherUtility  = dispatcherUtility;
     _matchEngineService = matchEngineService;
     _webSongConverter   = webSongConverter;
     // Setup the initialization lock
     _backgroundAudioTaskStarted = new AutoResetEvent(false);
     _settingsUtility.Write(ApplicationSettingsConstants.AppState, AppState.Active);
     PlaybackQueue = new OptimizedObservableCollection <QueueTrack>();
 }
Exemplo n.º 14
0
 public HardwareOperationViewModel(IHardwareOperationView view)
 {
     View           = view;
     View.ViewModel = this;
     SaveCommand    = new CommandHandler <object, object>(SaveCommandAction);
     CloseCommand   = new CommandHandler <object, object>(CloseCommandAction);
     _categories    = new OptimizedObservableCollection <HardwareCategory>();
     _statuses      = new OptimizedObservableCollection <HardwareStatus>();
     _computerUsers = new OptimizedObservableCollection <User>();
     _categories.AddRange(Enum.GetValues(typeof(HardwareCategory)).Cast <HardwareCategory>().ToList());
     _statuses.AddRange(Enum.GetValues(typeof(HardwareStatus)).Cast <HardwareStatus>().ToList());
 }
Exemplo n.º 15
0
 public PlayerService(ISettingsUtility settingsUtility, IDispatcherUtility dispatcherUtility,
     IMatchEngineService matchEngineService, IConverter<WebSong, Track> webSongConverter)
 {
     _settingsUtility = settingsUtility;
     _dispatcherUtility = dispatcherUtility;
     _matchEngineService = matchEngineService;
     _webSongConverter = webSongConverter;
     // Setup the initialization lock
     _backgroundAudioTaskStarted = new AutoResetEvent(false);
     _settingsUtility.Write(ApplicationSettingsConstants.AppState, AppState.Active);
     PlaybackQueue = new OptimizedObservableCollection<QueueTrack>();
 }
        private void Configure()
        {
            PeopleByName = new OptimizedObservableCollection <PersonViewModel>(_peopleService.People.OrderBy(p => p.Person.Name.Sort));

            PeopleByRank = new OptimizedObservableCollection <PersonViewModel>(_peopleService.People.OrderBy(p => p.Person.Stats.Rank));

            PeopleBySource = new OptimizedObservableCollection <AlphaKeyGroup>(AlphaKeyGroup.CreateGroups(_peopleService.People, CultureInfo.CurrentUICulture,
                                                                                                          x => ((PersonViewModel)x).Person.Name.Sort));

            PeopleByCountry = new OptimizedObservableCollection <AlphaKeyGroup>(AlphaKeyGroup.CreateGroups(_peopleService.People, CultureInfo.CurrentUICulture,
                                                                                                           x => ((PersonViewModel)x).Person.Place));

            Loaded?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 17
0
 private void UpdatePlaybackQueue()
 {
     try
     {
         var tracks = BackgroundMediaPlayer.Current.Source as MediaPlaybackList;
         if (tracks != null)
         {
             var queueTracks = tracks.Items.Select(p => p.Source.Queue()).ToList();
             PlaybackQueue = new OptimizedObservableCollection <QueueTrack>(queueTracks);
         }
     }
     catch (InvalidCastException)
     {
         // source is not set (odd exception tho)
     }
 }
Exemplo n.º 18
0
 public AppUserOperatorViewModel(IAppUserOperatorView view)
 {
     View           = view;
     View.ViewModel = this;
     SaveCommand    = new CommandHandler <object, object>(SaveCommandAction);
     CloseCommand   = new CommandHandler <object, object>(CloseCommandAction);
     _userRoles     = new OptimizedObservableCollection <UserRole>();
     _userRoles.Add(new UserRole {
         RoleId = Role.ADMIN, RoleName = "ADMIN"
     });
     _userRoles.Add(new UserRole {
         RoleId = Role.MANAGER, RoleName = "MANAGER"
     });
     _userRoles.Add(new UserRole {
         RoleId = Role.OPERATOR, RoleName = "OPERATOR"
     });
 }
Exemplo n.º 19
0
        public void Load()
        {
            const string kauaiArtwork =
                "https://runthetrap.com/wp-content/uploads/2014/10/stream-childish-gambino-kauai-ep1.jpg";
            const string gambinoArtwork =
                "http://static1.1.sqspcdn.com/static/f/362468/13350786/1311549110307/Childish-Gambino.jpg?token=%2F%2FxvckXhTw1vqbFHcrSvgEN5hhE%3D";

            Tracks = new OptimizedObservableCollection <Track>
            {
                new Track
                {
                    Title            = "Sober",
                    DisplayArtist    = "Childish Gambino",
                    AlbumTitle       = "Kauai",
                    ArtworkUri       = gambinoArtwork,
                    ArtistArtworkUri = kauaiArtwork
                }
            };

            Albums = new OptimizedObservableCollection <Album>
            {
                new Album
                {
                    Title  = "Kauai",
                    Artist = new Artist
                    {
                        Name       = "Childish Gambino",
                        ArtworkUri = gambinoArtwork
                    },
                    ArtworkUri = kauaiArtwork,
                    Tracks     = Tracks
                }
            };

            Artists = new OptimizedObservableCollection <Artist>
            {
                new Artist
                {
                    Name       = "Childish Gambino",
                    ArtworkUri = gambinoArtwork
                }
            };

            Loaded?.Invoke(this, EventArgs.Empty);
        }
Exemplo n.º 20
0
        public void Load()
        {
            const string kauaiArtwork =
                "https://runthetrap.com/wp-content/uploads/2014/10/stream-childish-gambino-kauai-ep1.jpg";
            const string gambinoArtwork =
                "http://static1.1.sqspcdn.com/static/f/362468/13350786/1311549110307/Childish-Gambino.jpg?token=%2F%2FxvckXhTw1vqbFHcrSvgEN5hhE%3D";

            Tracks = new OptimizedObservableCollection<Track>
            {
                new Track
                {
                    Title = "Sober",
                    DisplayArtist = "Childish Gambino",
                    AlbumTitle = "Kauai",
                    ArtworkUri = gambinoArtwork,
                    ArtistArtworkUri = kauaiArtwork
                }
            };

            Albums = new OptimizedObservableCollection<Album>
            {
                new Album
                {
                    Title = "Kauai",
                    Artist = new Artist
                    {
                        Name = "Childish Gambino",
                        ArtworkUri = gambinoArtwork
                    },
                    ArtworkUri = kauaiArtwork,
                    Tracks = Tracks
                }
            };

            Artists = new OptimizedObservableCollection<Artist>
            {
                new Artist
                {
                    Name = "Childish Gambino",
                    ArtworkUri = gambinoArtwork
                }
            };

            Loaded?.Invoke(this, EventArgs.Empty);
        }
        public DesignLibraryCollectionService(ILibraryService libraryService)
        {
            TracksByDateAdded = new OptimizedObservableCollection<Track>(
                libraryService.Tracks.OrderByDescending(p => p.CreatedAt));
            TracksByTitle = AlphaKeyGroup.CreateGroups(libraryService.Tracks, CultureInfo.CurrentCulture,
                item => ((Track) item).Title);
            TracksByArtist = AlphaKeyGroup.CreateGroups(libraryService.Tracks, CultureInfo.CurrentCulture,
                item => ((Track) item).DisplayArtist);
            TracksByAlbum = AlphaKeyGroup.CreateGroups(libraryService.Tracks, CultureInfo.CurrentCulture,
                item => ((Track) item).AlbumTitle);

            ArtistsByName = AlphaKeyGroup.CreateGroups(
                libraryService.Artists.Where(p => !p.IsSecondaryArtist), CultureInfo.CurrentCulture,
                item => ((Artist) item).Name);

            AlbumsByTitle = AlphaKeyGroup.CreateGroups(libraryService.Albums, CultureInfo.CurrentCulture,
                item => ((Album) item).Title);
        }
        public DesignLibraryCollectionService(ILibraryService libraryService)
        {
            TracksByDateAdded = new OptimizedObservableCollection <Track>(
                libraryService.Tracks.OrderByDescending(p => p.CreatedAt));
            TracksByTitle = AlphaKeyGroup.CreateGroups(libraryService.Tracks, CultureInfo.CurrentCulture,
                                                       item => ((Track)item).Title);
            TracksByArtist = AlphaKeyGroup.CreateGroups(libraryService.Tracks, CultureInfo.CurrentCulture,
                                                        item => ((Track)item).DisplayArtist);
            TracksByAlbum = AlphaKeyGroup.CreateGroups(libraryService.Tracks, CultureInfo.CurrentCulture,
                                                       item => ((Track)item).AlbumTitle);

            ArtistsByName = AlphaKeyGroup.CreateGroups(
                libraryService.Artists.Where(p => !p.IsSecondaryArtist), CultureInfo.CurrentCulture,
                item => ((Artist)item).Name);

            AlbumsByTitle = AlphaKeyGroup.CreateGroups(libraryService.Albums, CultureInfo.CurrentCulture,
                                                       item => ((Album)item).Title);
        }
Exemplo n.º 23
0
 public ReportViewModel(IReportView view)
 {
     View                        = view;
     View.ViewModel              = this;
     PrintHWReportCommand        = new CommandHandler <object, object>(PrintHWReportCommandAction);
     PrintRunningHWCommand       = new CommandHandler <object, object>(PrintRunningHWCommandAction);
     PrintInactiveHWCommand      = new CommandHandler <object, object>(PrintInactiveHWCommandAction);
     PrintRepairHWCommand        = new CommandHandler <object, object>(PrintRepairHWCommandAction);
     PrintUserReportCommand      = new CommandHandler <object, object>(PrintUserReportCommandAction);
     SearchByUserCommand         = new CommandHandler <object, object>(SearchByUserCommandAction);
     _userCollection             = new OptimizedObservableCollection <User>();
     _allHardwares               = new OptimizedObservableCollection <Hardware>();
     _hardwareCollection         = new OptimizedObservableCollection <HardwareCountReport>();
     _activeHardwareCollection   = new OptimizedObservableCollection <HardwareReport>();
     _inActiveHardwareCollection = new OptimizedObservableCollection <HardwareReport>();
     _inRepairHardwareCollection = new OptimizedObservableCollection <HardwareReport>();
     _userReportCollection       = new OptimizedObservableCollection <HardwareReport>();
 }
Exemplo n.º 24
0
        private void ResetSortedCollections()
        {
            var dateAdded = new OptimizedObservableCollection <Track>(
                _libraryService.Tracks.OrderByDescending(p => p.CreatedAt));

            TracksByDateAdded.SwitchTo(dateAdded);

            var tracksByTitle = AlphaKeyGroup.CreateGroups(_libraryService.Tracks, CultureInfo.CurrentCulture,
                                                           item => ((Track)item).Title);

            TracksByTitle.SwitchTo(tracksByTitle);

            var tracksByArtist = AlphaKeyGroup.CreateGroups(_libraryService.Tracks, CultureInfo.CurrentCulture,
                                                            item => ((Track)item).DisplayArtist);

            TracksByArtist.SwitchTo(tracksByArtist);

            var tracksByAlbum = AlphaKeyGroup.CreateGroups(_libraryService.Tracks, CultureInfo.CurrentCulture,
                                                           item => ((Track)item).AlbumTitle);

            TracksByAlbum.SwitchTo(tracksByAlbum);

            var artistsByName = AlphaKeyGroup.CreateGroups(
                _libraryService.Artists.Where(p => !p.IsSecondaryArtist), CultureInfo.CurrentCulture,
                item => ((Artist)item).Name);

            ArtistsByName = artistsByName;

            var albumsByDateAdded = new OptimizedObservableCollection <Album>(
                _libraryService.Albums.OrderByDescending(p => p.Tracks.Min(track => track.CreatedAt)));

            AlbumsByDateAdded = albumsByDateAdded;

            var albumsByTitle = AlphaKeyGroup.CreateGroups(_libraryService.Albums, CultureInfo.CurrentCulture,
                                                           item => ((Album)item).Title);

            AlbumsByTitle = albumsByTitle;

            var albumsByArtist = AlphaKeyGroup.CreateGroups(_libraryService.Albums, CultureInfo.CurrentCulture,
                                                            item => ((Album)item).Artist.Name);

            AlbumsByArtist = albumsByArtist;
        }
Exemplo n.º 25
0
 public HardwareOperationViewModel(IHardwareOperationView view)
 {
     View = view;
     View.ViewModel = this;
     SaveCommand = new CommandHandler<object, object>(SaveCommandAction);
     CloseCommand = new CommandHandler<object, object>(CloseCommandAction);
     _categories = new OptimizedObservableCollection<HardwareCategory>();
     _statuses = new OptimizedObservableCollection<HardwareStatus>();
     _computerUsers = new OptimizedObservableCollection<User>();
     _categories.AddRange(Enum.GetValues(typeof(HardwareCategory)).Cast<HardwareCategory>().ToList());
     _statuses.AddRange(Enum.GetValues(typeof(HardwareStatus)).Cast<HardwareStatus>().ToList());
 }
Exemplo n.º 26
0
 public DetailViewModel()
 {
     _client        = new TraktClient(Constants.TraktId);
     Actors         = new OptimizedObservableCollection <TraktCastMember>();
     RecentEpisodes = new OptimizedObservableCollection <TraktEpisode>();
 }
Exemplo n.º 27
0
 public Artist()
 {
     Albums = new OptimizedObservableCollection <Album>();
     Tracks = new OptimizedObservableCollection <Track>();
     TracksThatAppearsIn = new OptimizedObservableCollection <Track>();
 }
Exemplo n.º 28
0
 public Album()
 {
     Songs = new OptimizedObservableCollection<Song>();
     AddableTo = new ObservableCollection<AddableCollectionItem>();
 }
Exemplo n.º 29
0
        public void LoadLibrary()
        {
            if (IsLibraryLoaded)
            {
                return;
            }

            /*
             * Sqlite makes a transaction to create a shared lock
             * Wrapping it in one single transactions assures it is only lock and release once
             */
            _sqlService.BeginTransaction();

            var songs = _sqlService.SelectAll<Song>().OrderByDescending(p => p.Id).ToList();
            var artists = _sqlService.SelectAll<Artist>().OrderByDescending(p => p.Id).ToList();
            var albums = _sqlService.SelectAll<Album>().OrderByDescending(p => p.Id).ToList();
            Stations =
                new OptimizedObservableCollection<RadioStation>(
                    _sqlService.SelectAll<RadioStation>().OrderByDescending(p => p.Id).ToList());

            // Let go of the lock
            _sqlService.Commit();

            var isForeground = _dispatcher != null;

            foreach (var song in songs)
            {
                song.Artist = artists.FirstOrDefault(p => p.Id == song.ArtistId);
                song.Album = albums.FirstOrDefault(p => p.Id == song.AlbumId);
            }

            if (isForeground)
            {
                _dispatcher.RunAsync(() => Songs.AddRange(songs)).Wait();
            }
            else
            {
                Songs.AddRange(songs);
            }

            if (isForeground)
                foreach (var artist in artists)
                {
                    _dispatcher.RunAsync(
                        () =>
                        {
                            var artworkPath = string.Format(_artistArtworkFilePath, artist.Id);
                            artist.Artwork = artist.HasArtwork
                                ? _bitmapFactory.CreateImage(
                                    new Uri(_localFilePrefix + artworkPath))
                                : null;

                            if (ScaledImageSize != 0 && artist.Artwork != null)
                            {
                                artist.Artwork.SetDecodedPixel(ScaledImageSize);
                            }
                        }).Wait();
                }

            foreach (var album in albums)
            {
                album.Songs.AddRange(songs.Where(p => !p.IsTemp && p.AlbumId == album.Id).OrderBy(p => p.TrackNumber));
                album.PrimaryArtist = artists.FirstOrDefault(p => p.Id == album.PrimaryArtistId);

                if (isForeground)
                {
                    _dispatcher.RunAsync(
                        () =>
                        {
                            var artworkPath = string.Format(_artworkFilePath, album.Id);
                            if (album.HasArtwork)
                            {
                                var path = _localFilePrefix + artworkPath;

                                album.Artwork = _bitmapFactory.CreateImage(new Uri(path));

                                if (ScaledImageSize != 0)
                                {
                                    album.Artwork.SetDecodedPixel(ScaledImageSize);

                                    album.MediumArtwork = _bitmapFactory.CreateImage(new Uri(path));
                                    album.MediumArtwork.SetDecodedPixel(ScaledImageSize/2);

                                    album.SmallArtwork = _bitmapFactory.CreateImage(new Uri(path));
                                    album.SmallArtwork.SetDecodedPixel(50);
                                }
                            }
                            else
                            {
                                var artwork = album.PrimaryArtist.HasArtwork
                                    ? album.PrimaryArtist.Artwork
                                    : _missingArtwork;
                                album.Artwork = artwork;
                                album.MediumArtwork = artwork;
                                album.SmallArtwork = artwork;
                            }
                        }).Wait();
                }
            }

            if (isForeground)
            {
                _dispatcher.RunAsync(() => Albums.AddRange(albums)).Wait();
            }
            else
            {
                Albums.AddRange(albums);
            }

            foreach (var artist in artists)
            {
                artist.Songs.AddRange(songs.Where(p => !p.IsTemp && p.ArtistId == artist.Id).OrderBy(p => p.Name));
                artist.Albums.AddRange(
                    albums.Where(p => p.PrimaryArtistId == artist.Id && p.Songs.Count > 0).OrderBy(p => p.Name));

                var songsAlbums = artist.Songs.Select(p => p.Album);
                artist.Albums.AddRange(songsAlbums.Where(p => p.Songs.Count > 0 && !artist.Albums.Contains(p)));
            }

            if (isForeground)
            {
                _dispatcher.RunAsync(() => Artists.AddRange(artists)).Wait();
            }
            else
            {
                Artists.AddRange(artists);
            }

            IsLibraryLoaded = true;

            LoadQueue(songs);
            LoadPlaylists();

            if (!isForeground)
            {
                return;
            }

            var corruptSongs =
                Songs.ToList()
                    .Where(p => string.IsNullOrEmpty(p.Name) || p.Album == null || p.Artist == null)
                    .ToList();
            foreach (var corruptSong in corruptSongs)
            {
                DeleteSongAsync(corruptSong).Wait();
            }

            _dispatcher.RunAsync(
                () =>
                {
                    if (LibraryLoaded != null)
                    {
                        LibraryLoaded(this, null);
                    }
                }).Wait();

            try
            {
                CleanupFiles(albums, artists);
            }
            catch
            {
                // ignored
            }
        }
 public OptimizedObservableCollectionMocker(IEnumerable<object> items)
 {
     OptimizedObservableCollection = new OptimizedObservableCollection<object>(items);
     OptimizedObservableCollection.CollectionChanged += (s, e) =>
     {
         switch (e.Action)
         {
             case NotifyCollectionChangedAction.Add:
                 ItemsAddedCount++;
                 break;
             case NotifyCollectionChangedAction.Remove:
                 ItemsRemovedCount++;
                 break;
             case NotifyCollectionChangedAction.Replace:
                 ItemsReplacedCount++;
                 break;
             case NotifyCollectionChangedAction.Reset:
                 ItemsResetCount++;
                 break;
         }
     };
 }
Exemplo n.º 31
0
 public Album()
 {
     Tracks = new OptimizedObservableCollection<Track>();
 }
Exemplo n.º 32
0
 public Artist()
 {
     Albums = new OptimizedObservableCollection<Album>();
     Tracks = new OptimizedObservableCollection<Track>();
     TracksThatAppearsIn = new OptimizedObservableCollection<Track>();
 }
Exemplo n.º 33
0
 private void UpdatePlaybackQueue()
 {
     try
     {
         var tracks = BackgroundMediaPlayer.Current.Source as MediaPlaybackList;
         if (tracks != null)
         {
             var queueTracks = tracks.Items.Select(p => p.Source.Queue()).ToList();
             PlaybackQueue = new OptimizedObservableCollection<QueueTrack>(queueTracks);
         }
     }
     catch (InvalidCastException)
     {
         // source is not set (odd exception tho)
     }
 }
Exemplo n.º 34
0
 public SupplierOperationViewModel(ISupplierOperationView view)
 {
     View = view;
     View.ViewModel = this;
     SaveCommand = new CommandHandler<object, object>(SaveCommandAction);
     CloseCommand = new CommandHandler<object, object>(CloseCommandAction);
     _hardwares = new OptimizedObservableCollection<Hardware>();
 }
Exemplo n.º 35
0
        public void LoadLibrary()
        {
            if (IsLibraryLoaded)
            {
                return;
            }

            /*
             * Sqlite makes a transaction to create a shared lock
             * Wrapping it in one single transactions assures it is only lock and release once
             */
            _sqlService.BeginTransaction();

            var songs   = _sqlService.SelectAll <Song>().OrderByDescending(p => p.Id).ToList();
            var artists = _sqlService.SelectAll <Artist>().OrderByDescending(p => p.Id).ToList();
            var albums  = _sqlService.SelectAll <Album>().OrderByDescending(p => p.Id).ToList();

            Stations =
                new OptimizedObservableCollection <RadioStation>(
                    _sqlService.SelectAll <RadioStation>().OrderByDescending(p => p.Id).ToList());

            // Let go of the lock
            _sqlService.Commit();

            var isForeground = _dispatcher != null;

            foreach (var song in songs)
            {
                song.Artist = artists.FirstOrDefault(p => p.Id == song.ArtistId);
                song.Album  = albums.FirstOrDefault(p => p.Id == song.AlbumId);
            }

            if (isForeground)
            {
                _dispatcher.RunAsync(() => Songs.AddRange(songs)).Wait();
            }
            else
            {
                Songs.AddRange(songs);
            }

            if (isForeground)
            {
                foreach (var artist in artists)
                {
                    _dispatcher.RunAsync(
                        () =>
                    {
                        var artworkPath = string.Format(_artistArtworkFilePath, artist.Id);
                        artist.Artwork  = artist.HasArtwork
                                ? _bitmapFactory.CreateImage(
                            new Uri(_localFilePrefix + artworkPath))
                                : null;

                        if (ScaledImageSize != 0 && artist.Artwork != null)
                        {
                            artist.Artwork.SetDecodedPixel(ScaledImageSize);
                        }
                    }).Wait();
                }
            }

            foreach (var album in albums)
            {
                album.Songs.AddRange(songs.Where(p => !p.IsTemp && p.AlbumId == album.Id).OrderBy(p => p.TrackNumber));
                album.PrimaryArtist = artists.FirstOrDefault(p => p.Id == album.PrimaryArtistId);

                if (isForeground)
                {
                    _dispatcher.RunAsync(
                        () =>
                    {
                        var artworkPath = string.Format(_artworkFilePath, album.Id);
                        if (album.HasArtwork)
                        {
                            var path = _localFilePrefix + artworkPath;

                            album.Artwork = _bitmapFactory.CreateImage(new Uri(path));

                            if (ScaledImageSize != 0)
                            {
                                album.Artwork.SetDecodedPixel(ScaledImageSize);

                                album.MediumArtwork = _bitmapFactory.CreateImage(new Uri(path));
                                album.MediumArtwork.SetDecodedPixel(ScaledImageSize / 2);

                                album.SmallArtwork = _bitmapFactory.CreateImage(new Uri(path));
                                album.SmallArtwork.SetDecodedPixel(50);
                            }
                        }
                        else
                        {
                            var artwork = album.PrimaryArtist.HasArtwork
                                    ? album.PrimaryArtist.Artwork
                                    : _missingArtwork;
                            album.Artwork       = artwork;
                            album.MediumArtwork = artwork;
                            album.SmallArtwork  = artwork;
                        }
                    }).Wait();
                }
            }

            if (isForeground)
            {
                _dispatcher.RunAsync(() => Albums.AddRange(albums)).Wait();
            }
            else
            {
                Albums.AddRange(albums);
            }

            foreach (var artist in artists)
            {
                artist.Songs.AddRange(songs.Where(p => !p.IsTemp && p.ArtistId == artist.Id).OrderBy(p => p.Name));
                artist.Albums.AddRange(
                    albums.Where(p => p.PrimaryArtistId == artist.Id && p.Songs.Count > 0).OrderBy(p => p.Name));

                var songsAlbums = artist.Songs.Select(p => p.Album);
                artist.Albums.AddRange(songsAlbums.Where(p => p.Songs.Count > 0 && !artist.Albums.Contains(p)));
            }

            if (isForeground)
            {
                _dispatcher.RunAsync(() => Artists.AddRange(artists)).Wait();
            }
            else
            {
                Artists.AddRange(artists);
            }

            IsLibraryLoaded = true;

            LoadQueue(songs);
            LoadPlaylists();

            if (!isForeground)
            {
                return;
            }

            var corruptSongs =
                Songs.ToList()
                .Where(p => string.IsNullOrEmpty(p.Name) || p.Album == null || p.Artist == null)
                .ToList();

            foreach (var corruptSong in corruptSongs)
            {
                DeleteSongAsync(corruptSong).Wait();
            }

            _dispatcher.RunAsync(
                () =>
            {
                if (LibraryLoaded != null)
                {
                    LibraryLoaded(this, null);
                }
            }).Wait();

            try
            {
                CleanupFiles(albums, artists);
            }
            catch
            {
                // ignored
            }
        }
Exemplo n.º 36
0
 public ReportViewModel(IReportView view)
 {
     View = view;
     View.ViewModel = this;
     PrintHWReportCommand = new CommandHandler<object, object>(PrintHWReportCommandAction);
     PrintRunningHWCommand = new CommandHandler<object, object>(PrintRunningHWCommandAction);
     PrintInactiveHWCommand = new CommandHandler<object, object>(PrintInactiveHWCommandAction);
     PrintRepairHWCommand = new CommandHandler<object, object>(PrintRepairHWCommandAction);
     PrintUserReportCommand = new CommandHandler<object, object>(PrintUserReportCommandAction);
     SearchByUserCommand = new CommandHandler<object, object>(SearchByUserCommandAction);
     _userCollection = new OptimizedObservableCollection<User>();
     _allHardwares = new OptimizedObservableCollection<Hardware>();
     _hardwareCollection = new OptimizedObservableCollection<HardwareCountReport>();
     _activeHardwareCollection = new OptimizedObservableCollection<HardwareReport>();
     _inActiveHardwareCollection = new OptimizedObservableCollection<HardwareReport>();
     _inRepairHardwareCollection = new OptimizedObservableCollection<HardwareReport>();
     _userReportCollection = new OptimizedObservableCollection<HardwareReport>();
 }
Exemplo n.º 37
0
 public Album()
 {
     Songs     = new OptimizedObservableCollection <Song>();
     AddableTo = new ObservableCollection <AddableCollectionItem>();
 }
Exemplo n.º 38
0
        public void LoadLibrary()
        {
            Songs = new OptimizedObservableCollection <Song>
            {
                new Song
                {
                    Name   = "Maps",
                    Artist =
                        new Artist
                    {
                        Name    = "Maroon 5",
                        Artwork =
                            _bitmapFactory.CreateImage(
                                new Uri(
                                    "http://musicimage.xboxlive.com/content/music.1F154700-0200-11DB-89CA-0019B92A3933/image?locale=en-US"))
                    },
                    Album =
                        new Album
                    {
                        Name    = "V",
                        Artwork =
                            _bitmapFactory.CreateImage(
                                new Uri("http://static.musictoday.com/store/bands/93/product_medium/IXDDM501.JPG"))
                    }
                },
                new Song
                {
                    Name   = "Animal",
                    Artist = new Artist {
                        Name = "Maroon 5"
                    },
                    Album =
                        new Album
                    {
                        Name    = "V",
                        Artwork =
                            _bitmapFactory.CreateImage(
                                new Uri("http://static.musictoday.com/store/bands/93/product_medium/IXDDM501.JPG"))
                    }
                }
            };

            Albums = new OptimizedObservableCollection <Album>
            {
                new Album
                {
                    Id      = 0,
                    Name    = "V",
                    Artwork =
                        _bitmapFactory.CreateImage(
                            new Uri("http://static.musictoday.com/store/bands/93/product_medium/IXDDM501.JPG")),
                    PrimaryArtist = new Artist {
                        Name = "Maroon 5"
                    },
                    Genre = "Pop",
                    Songs = new OptimizedObservableCollection <Song>(Songs)
                }
            };

            Artists = new OptimizedObservableCollection <Artist>
            {
                new Artist {
                    Name = "Maroon 5", Albums = Albums, Songs = Songs
                },
                new Artist {
                    Name = "Taylor Swift"
                }
            };

            Playlists = new OptimizedObservableCollection <Playlist>
            {
                new Playlist
                {
                    Name = "Fav 5"
                },
                new Playlist
                {
                    Name = "workout fun!"
                }
            };

            var pSongs = new ObservableCollection <PlaylistSong>();

            foreach (var song in Songs)
            {
                pSongs.Add(new PlaylistSong
                {
                    Song = song
                });
            }

            foreach (var playlist in Playlists)
            {
                playlist.Songs = pSongs;
            }

            PlaybackQueue = new OptimizedObservableCollection <QueueSong>(pSongs);
        }
Exemplo n.º 39
0
 public AppUserOperatorViewModel(IAppUserOperatorView view)
 {
     View = view;
     View.ViewModel = this;
     SaveCommand = new CommandHandler<object, object>(SaveCommandAction);
     CloseCommand = new CommandHandler<object, object>(CloseCommandAction);
     _userRoles = new OptimizedObservableCollection<UserRole>();
     _userRoles.Add(new UserRole { RoleId = Role.ADMIN, RoleName = "ADMIN"});
     _userRoles.Add(new UserRole { RoleId = Role.MANAGER, RoleName = "MANAGER" });
     _userRoles.Add(new UserRole { RoleId = Role.OPERATOR, RoleName = "OPERATOR" });
 }
Exemplo n.º 40
0
 public Album()
 {
     Tracks = new OptimizedObservableCollection <Track>();
 }
Exemplo n.º 41
0
 public MassUpdater(OptimizedObservableCollection <T> parent)
 {
     this.parent = parent;
     parent._shouldRaiseNotifications = false;
 }
Exemplo n.º 42
0
        public void LoadLibrary()
        {
            Songs = new OptimizedObservableCollection<Song>
            {
                new Song
                {
                    Name = "Maps",
                    Artist =
                        new Artist
                        {
                            Name = "Maroon 5",
                            Artwork =
                                _bitmapFactory.CreateImage(
                                    new Uri(
                                        "http://musicimage.xboxlive.com/content/music.1F154700-0200-11DB-89CA-0019B92A3933/image?locale=en-US"))
                        },
                    Album =
                        new Album
                        {
                            Name = "V",
                            Artwork =
                                _bitmapFactory.CreateImage(
                                    new Uri("http://static.musictoday.com/store/bands/93/product_medium/IXDDM501.JPG"))
                        }
                },
                new Song
                {
                    Name = "Animal",
                    Artist = new Artist {Name = "Maroon 5"},
                    Album =
                        new Album
                        {
                            Name = "V",
                            Artwork =
                                _bitmapFactory.CreateImage(
                                    new Uri("http://static.musictoday.com/store/bands/93/product_medium/IXDDM501.JPG"))
                        }
                }
            };

            Albums = new OptimizedObservableCollection<Album>
            {
                new Album
                {
                    Id = 0,
                    Name = "V",
                    Artwork =
                        _bitmapFactory.CreateImage(
                            new Uri("http://static.musictoday.com/store/bands/93/product_medium/IXDDM501.JPG")),
                    PrimaryArtist = new Artist {Name = "Maroon 5"},
                    Genre = "Pop",
                    Songs = new OptimizedObservableCollection<Song>(Songs)
                }
            };

            Artists = new OptimizedObservableCollection<Artist>
            {
                new Artist {Name = "Maroon 5", Albums = Albums, Songs = Songs},
                new Artist {Name = "Taylor Swift"}
            };

            Playlists = new OptimizedObservableCollection<Playlist>
            {
                new Playlist
                {
                    Name = "Fav 5"
                },
                new Playlist
                {
                    Name = "workout fun!"
                }
            };

            var pSongs = new ObservableCollection<PlaylistSong>();
            foreach (var song in Songs)
            {
                pSongs.Add(new PlaylistSong
                {
                    Song = song
                });
            }

            foreach (var playlist in Playlists)
            {
                playlist.Songs = pSongs;
            }

            PlaybackQueue = new OptimizedObservableCollection<QueueSong>(pSongs);
        }