static NebulaClient() { AssemblyDirectory = GetAssemblyDirectory(); MainWindow = Application.Current.MainWindow as MainWindow; Settings = NebulaSettings.LoadSettings(); //Needs to be first Notifications = new NebulaNotifications(); Network = new NebulaNetClient(); MediaPlayer = new MediaPlayer(); Updater = new NebulaUpdater(); Playlists = new PlaylistsManager(); KeyboardHooker = new KeyboardHooker(); SharedSession = new NebulaSharedSession(); Session = new NebulaSession(); //Needs to be latest MediaProviders.Add(new YoutubeMediaProvider()); KeyboardHooker.KeyDown += OnGlobalKeyDown; if (Settings.General.MediaKeyEnabled) { KeyboardHooker.Hook(); } CancellationTokenSource = new CancellationTokenSource(); Task.Run(() => AppTick(CancellationTokenSource.Token, 500)); #if RELEASE CheckForUpdate(true); #endif }
/// <summary> /// Sync new Playlist with localDb and serverDb /// </summary> public void initializePlaylist() { PlaylistsNwManager.PostPlaylist(this); PlaylistsManager.db_Add_Update_Record(PlaylistsNwManager.GetPlaylists().FindLast(e => e.name == this.name)); Playlist temp = PlaylistsManager.db_GetAllPlaylists().FindLast(e => e.name == this.name); this.id = temp.id; this.resource_uri = temp.resource_uri; }
/// <summary> /// Synchronize locale Database with Server /// </summary> private void synchronizeDatabase() { NetworkHandler.SyncLocalDbWithServerDb(); // Synchronize View with local database foreach (Playlist playlist in PlaylistsManager.db_GetAllPlaylists()) { Playlists.Add(playlist.name); } }
/// <summary> /// Sync Local DB with Server DB /// </summary> public static void SyncLocalDbWithServerDb() { // Delete all local tables AlbumsManager.db_Delete_All(); ArtistsManager.db_Delete_All(); PlaylistsManager.db_Delete_All(); //Get all server tables List <Album> albums = AlbumsNwManager.GetAlbums(); List <Artist> artists = ArtistsNwManager.GetArtists(); List <Playlist> playlists = PlaylistsNwManager.GetPlaylists(); List <Track> tracks = TracksNwManager.GetTracks(); // < sync local tables with server tables > foreach (var item in albums) { AlbumsManager.db_Add_Update_Record(item); } foreach (var item in artists) { ArtistsManager.db_Add_Update_Record(item); } foreach (var item in playlists) { PlaylistsManager.db_Add_Update_Record(item); } foreach (var item in tracks) { TracksManager.db_Add_Update_Record(item); } // </ sync local tables with server tables > // < Add relations to local db > foreach (Album album in albums) { foreach (string artistId in album.artists) { AlbumFromArtistManager.db_Add_Update_Record((int)album.id, Convert.ToInt32(artistId)); } } foreach (Artist artist in artists) { foreach (string trackId in artist.songs) { TrackFromArtistManager.db_Add_Update_Record(Convert.ToInt32(trackId), (int)artist.id); } } // </ Add relations to local db > }
/// <summary> /// Plays a selected playlist from ListView /// </summary> /// <param name="selectedPlaylist"></param> private void playSelectedPlaylist(string selectedPlaylist) { Playlist currentPlaylist = PlaylistsManager.db_GetAllPlaylists().Find(x => x.name == selectedPlaylist); musicplayer.Musicqueue.LoadPlayableContainerInQueue(currentPlaylist); //To decide between all Tracks and a Playlist SelectAllTracks = false; musicplayer.NextTrack(); musicplayer.PrevTrack(); playMusic(); Tracks.Clear(); CurrentFrame = "TitleView.xaml"; foreach (Track track in currentPlaylist.Tracks) { Tracks.Add(new TrackMetadata { Title = track.title }); } }
public MainViewModel() { musicplayer.Musicqueue.PropertyChanged += TrackChanged; // Subscribes to all View Commands this.StartPlayerCommand = new RelayCommand(this.changePlayerState); this.PlayPreviousCommand = new RelayCommand(this.playPrevious); this.PlayNextCommand = new RelayCommand(this.playNext); this.PlayerSettingCommand = new RelayCommand(this.setRenderingModeIcon); this.BigPlayerCommand = new RelayCommand(this.createBigPlayerView); this.ArtistsCommand = new RelayCommand(this.createArtistsView); this.AlbumsCommand = new RelayCommand(this.createAlbumsView); this.TracksCommand = new RelayCommand(this.createTracksView); this.ListViewCommand = new RelayCommand <TrackMetadata>((item) => this.playSelectedTrack(item)); this.PlaylistCommand = new RelayCommand <string>((item) => this.playSelectedPlaylist(item)); this.ChangeViewCommand = new RelayCommand(this.changeView); this.LoginCommand = new RelayCommand(this.openLoginDialog); this.SleepCommand = new RelayCommand(this.controlSleepTimer); this.UploadCommand = new RelayCommand(this.uploadFiles); this.DownloadCommand = new RelayCommand(this.synchronizeDatabase); // Set inital values _volumn = musicplayer.Mediaplayer.Volume; foreach (Playlist playlist in PlaylistsManager.db_GetAllPlaylists()) { Playlists.Add(playlist.name); } DispatcherTimer timer = new DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1); timer.Tick += timer_Tick; timer.Start(); }
private static void InitializeProgram() { Program.splashForm.StepProgress("ルートオプションの読み込み"); if (!RootOptions.TryDeserialize(Path.Combine(Program.GetWorkingDirectory(WorkingDirectory.UserSettings), "RootOptions.xml"), out Program.rootOptions)) { Program.rootOptions = new RootOptions(); } Program.splashForm.StepProgress("アイコンの読み込み"); try { string iconFileName = Program.RootOptions.AppBasicOptions.IconFile; if (string.IsNullOrEmpty(iconFileName)) { iconFileName = Path.GetFileNameWithoutExtension(Application.ExecutablePath) + ".ico"; } if (File.Exists(iconFileName)) { BaseForm.CustomIcon = new Icon(iconFileName); } } catch (Exception e) { Program.DisplayException("アイコンの読み込みエラー", e); } Program.splashForm.StepProgress("クッキーの設定"); Program.cookieContainer = new CookieContainer(); try { retry: int cookieSize = 0; if (!WindowsFunctions.InternetGetCookie(GUriBuilder.TopPageUri.AbsoluteUri, null, null, ref cookieSize)) { if (Marshal.GetLastWin32Error() != (int)WinError.ERROR_NO_MORE_ITEMS) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } else { switch (MessageBox.Show("クッキーの読み込みに失敗しました.視聴設定ページで視聴設定を行ってください.\n\n・はい: 視聴設定用のウィンドウを開く\n・いいえ: この警告を無視してアプリケーションを起動する\n・キャンセル: アプリケーションを終了する", "クッキーの読み込み失敗", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)) { case DialogResult.Yes: RegistrationForm regForm = new RegistrationForm(); regForm.ShowDialog(); regForm.Dispose(); goto retry; case DialogResult.No: break; case DialogResult.Cancel: Environment.Exit(0); return; } } } else { StringBuilder cookieSb = new StringBuilder(cookieSize); if (!WindowsFunctions.InternetGetCookie(GUriBuilder.TopPageUri.AbsoluteUri, null, cookieSb, ref cookieSize)) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error()); } string cookieStr = cookieSb.ToString(); if (!cookieStr.Contains("Cookie_UserId")) { switch (MessageBox.Show("クッキーに Cookie_UserId がありません.視聴設定ページで視聴設定を行ってください.\n\n・はい: 視聴設定用のウィンドウを開く\n・いいえ: この警告を無視してアプリケーションを起動する\n・キャンセル: アプリケーションを終了する\n\nクッキーの中身:\n" + cookieStr, "Cookie_UserId がない", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning)) { case DialogResult.Yes: RegistrationForm regForm = new RegistrationForm(); regForm.ShowDialog(); regForm.Dispose(); goto retry; case DialogResult.No: break; case DialogResult.Cancel: Environment.Exit(0); return; } } Program.cookieContainer.SetCookies(GUriBuilder.TopPageUri, cookieSb.ToString().Replace(';', ',')); } } catch (Exception e) { Program.DisplayException("クッキーの読み込み失敗", e); } Program.splashForm.StepProgress("キャッシュの初期化と読み込み"); Program.cacheController = new CacheController(Program.GetWorkingDirectory(WorkingDirectory.Cache), Program.CookieContainer, Program.RootOptions.CacheControllerOptions); if (Program.RootOptions.AppBasicOptions.UseDefaultGenres) { Program.CacheController.ResetToDefaultGenres(); } else { Program.CacheController.DeserializeGenreTable(); } Program.cacheController.DeserializePackageAndContentTables(); Program.splashForm.StepProgress("プレイリストコレクションの読み込み"); Program.playlistsManager = new PlaylistsManager(); Program.playlistsManager.DeserializePlaylists(Path.Combine(Program.GetWorkingDirectory(WorkingDirectory.UserSettings), "PlaylistCollection.xml")); Program.splashForm.StepProgress("仕分けルールの読み込み"); Program.contentClassificatinoRulesManager = new ContentClassificationRulesManager(); Program.contentClassificatinoRulesManager.TryDeserialize(Path.Combine(Program.GetWorkingDirectory(WorkingDirectory.UserSettings), "ContentClassificationRules.xml")); Program.splashForm.StepProgress("外部コマンドの読み込み"); Program.externalCommandsManager = new ExternalCommandsManager(); Program.externalCommandsManager.TryDeserialize(Path.Combine(Program.GetWorkingDirectory(WorkingDirectory.UserSettings), "ExternalCommands.xml")); Program.splashForm.StepProgress("メインフォームの作成"); Program.mainForm = new MainForm(); }
/// <summary> /// Delete Playlist from Database /// </summary> public void Delete() { PlaylistsManager.db_Delete_Record(this.id); PlaylistsNwManager.DeletePlaylist(this.id); }
private void PlaylistsViewCControl_Load(object sender, EventArgs e) { if (base.DesignMode) return; List<ToolStripItem> sortMenuItems = new List<ToolStripItem>(this.lvPlaylists.Columns.Count); foreach (ColumnHeader ch in this.lvPlaylists.Columns) { ToolStripMenuItem tsmi = new ToolStripMenuItem(ch.Text); tsmi.Tag = ch.Index; tsmi.Click += delegate(object sender2, EventArgs e2) { this.PushComparison((int)(sender2 as ToolStripMenuItem).Tag); }; sortMenuItems.Add(tsmi); } this.tsmiSort.DropDownItems.AddRange(sortMenuItems.ToArray()); if (null == Program.PlaylistsManager) return; this.plManager = Program.PlaylistsManager; this.plManager.PlaylistsManagerChanged += new EventHandler(this.plManager_PlaylistsManagerChanged); this.plManager.CurrentContentAndPlaylistChanged += new EventHandler(this.plManager_CurrentContentAndPlaylistChanged); this.Disposed += delegate { this.plManager.PlaylistsManagerChanged -= new EventHandler(this.plManager_PlaylistsManagerChanged); this.plManager.CurrentContentAndPlaylistChanged -= new EventHandler(this.plManager_CurrentContentAndPlaylistChanged); }; this.lvPlaylists.BeginUpdate(); this.UpdateListItems(); this.UpdatePlayingMark(); this.ScrollToTop(); this.lvPlaylists.EndUpdate(); this.UpdateStatusMessages(); this.ChangeEnabilityOfMenuItems(); }