private async void Tell()
        {
            try
            {
                var posId = await ViewModelLocator.Vkontakte.Wall.Post(message: MainResources.AboutTellMessage, attachments:
                    new[] { new VkLinkAttachment() { Url = "http://meridianvk.com" } });

                if (posId != 0)
                {
                    var flyout = new FlyoutControl();
                    flyout.FlyoutContent = new TellResultView(posId);
                    flyout.Show();
                }
            }
            catch (Exception ex)
            {
                LoggingService.Log(ex);
            }
        }
Пример #2
0
        private void InitializeCommands()
        {
            CloseWindowCommand = new RelayCommand(() => Application.Current.MainWindow.Close());

            MinimizeWindowCommand = new RelayCommand(() => WindowState = WindowState.Minimized);

            MaximizeWindowCommand = new RelayCommand(() => WindowState = IsWindowMaximized ? WindowState.Normal : WindowState.Maximized);

            GoToPageCommand = new RelayCommand<string>(page => OnNavigateToPage(new NavigateToPageMessage() { Page = page }));

            GoToSettingsCommand = new RelayCommand(() =>
            {
                ShowSidebar = false;
                OnNavigateToPage(new NavigateToPageMessage() { Page = "/Settings.SettingsView" });
            });

            PrevAudioCommand = new RelayCommand(AudioService.Prev);

            NextAudioCommand = new RelayCommand(AudioService.SkipNext);

            PlayPauseCommand = new RelayCommand(() =>
            {
                if (IsPlaying)
                    AudioService.Pause();
                else
                    AudioService.Play();
            });

            GoBackCommand = new RelayCommand(() =>
            {
                var frame = Application.Current.MainWindow.GetVisualDescendents().OfType<Frame>().FirstOrDefault(f => f.Name == "RootFrame");
                if (frame == null)
                    return;

                if (frame.CanGoBack)
                    frame.GoBack();

                UpdateCanGoBack();
            });

            SearchCommand = new RelayCommand<string>(query =>
            {
                if (!string.IsNullOrWhiteSpace(query))
                {
                    MessengerInstance.Send(new NavigateToPageMessage()
                    {
                        Page = "/Search.SearchResultsView",
                        Parameters = new Dictionary<string, object>()
                                {
                                    {"query", query}
                                }
                    });
                }
            });

            RestartCommand = new RelayCommand(() =>
            {
                Process.Start(Application.ResourceAssembly.Location);
                Application.Current.Shutdown();
            });

            AddRemoveAudioCommand = new RelayCommand<Audio>(audio =>
            {
                audio.IsAddedByCurrentUser = !audio.IsAddedByCurrentUser;
                LikeDislikeAudio(audio);
            });

            EditAudioCommand = new RelayCommand<Audio>(audio =>
            {
                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new EditAudioView(audio);
                flyout.Show();
            });

            ShowLyricsCommand = new RelayCommand<Audio>(audio =>
            {
                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new LyricsView(audio);
                flyout.Show();
            });

            CopyInfoCommand = new RelayCommand<Audio>(audio =>
            {
                if (audio == null)
                    return;

                try
                {
                    Clipboard.SetData(DataFormats.UnicodeText, audio.Artist + " - " + audio.Title);
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                }
            });

            PlayAudioNextCommand = new RelayCommand<Audio>(track =>
            {
                AudioService.PlayNext(track);
            });

            AddToNowPlayingCommand = new RelayCommand<Audio>(track =>
            {
                AudioService.Playlist.Add(track);
            });

            RemoveFromNowPlayingCommand = new RelayCommand<Audio>(track =>
            {
                AudioService.Playlist.Remove(track);
            });

            ShareAudioCommand = new RelayCommand<Audio>(audio =>
            {
                ShowShareBar = true;

                //костыль #2
                var shareControl = Application.Current.MainWindow.GetVisualDescendent<ShareBarControl>();
                if (shareControl == null)
                    return;

                var shareViewModel = ((ShareViewModel)((FrameworkElement)shareControl.Content).DataContext);
                shareViewModel.Tracks.Add(audio);
            });

            SwitchUIModeCommand = new RelayCommand(() =>
            {
                if (CurrentUIMode == UIMode.Normal)
                    SwitchUIMode(UIMode.Compact);
                else
                    SwitchUIMode(UIMode.Normal);
            });

            StartTrackRadioCommand = new RelayCommand<Audio>(track =>
            {
                RadioService.StartRadioFromSong(track.Title, track.Artist);
                MessengerInstance.Send(new NavigateToPageMessage() { Page = "/Main.NowPlayingView" });
            });

            ShowArtistInfoCommand = new RelayCommand<string>(async artist =>
            {
                NotificationService.Notify(MainResources.NotificationLookingArtist);

                try
                {
                    var artists = await DataService.SearchArtists(artist);
                    if (artists != null && artists.Count > 0)
                    {
                        var a = artists.First();
                        MessengerInstance.Send(new NavigateToPageMessage()
                        {
                            Page = "/Search.ArtistView",
                            Parameters = new Dictionary<string, object>()
                            {
                                {"artist", a}
                            }
                        });
                    }
                }
                catch (Exception ex)
                {
                    LoggingService.Log(ex);
                    NotificationService.Notify(MainResources.NotificationArtistNotFound);
                }
            });

            ShowLocalSearchCommand = new RelayCommand(() =>
            {
                var frame = Application.Current.MainWindow.GetVisualDescendents().OfType<Frame>().FirstOrDefault();
                if (frame == null)
                    return;

                var page = (Page)frame.Content;
                if (page != null)
                {
                    var localSearchBox = page.GetVisualDescendents().OfType<LocalSearchControl>().FirstOrDefault();
                    if (localSearchBox != null)
                        localSearchBox.IsActive = true;
                }
            });

            AddToAlbumCommand = new RelayCommand<Audio>(track =>
            {
                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new AddToAlbumView(track);
                flyout.Show();
            });
        }
Пример #3
0
        private static void MediaPlayerOnMediaFailed(object sender, ExceptionRoutedEventArgs e)
        {
            if (e.ErrorException is InvalidWmpVersionException)
            {
                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new CommonMessageView() { Header = ErrorResources.AudioFailedErrorHeaderCommon, Message = ErrorResources.WmpMissingError };
                flyout.Show();
                return;
            }

            if (CurrentAudio != null)
                LoggingService.Log("Media failed " + CurrentAudio.Artist + " - " + CurrentAudio.Title + ". " + e.ErrorException);

            _playFailsCount++;
            if (_playFailsCount < 5)
            {
                if (RadioService.CurrentRadio == null)
                    Next();
                else
                    RadioService.InvalidateCurrentSong();
            }
        }
Пример #4
0
        private void InitializeCommands()
        {
            PlayAudioCommand = new RelayCommand<Audio>(audio =>
            {
                AudioService.Play(audio);
                AudioService.SetCurrentPlaylist(AllTracks);
            });

            ShowAllTracksCommand = new RelayCommand(() =>
            {
                MessengerInstance.Send(new NavigateToPageMessage()
                {
                    Page = "/Search.ArtistAudioView",
                    Parameters = new Dictionary<string, object>()
                    {
                        {"viewModel", this}
                    }
                });
            });

            ShowAllAlbumsCommand = new RelayCommand(() =>
            {
                MessengerInstance.Send(new NavigateToPageMessage()
                {
                    Page = "/Search.ArtistAlbumsView",
                    Parameters = new Dictionary<string, object>()
                    {
                        {"viewModel", this}
                    }
                });
            });


            GoToAlbumCommand = new RelayCommand<LastFmAlbum>(album =>
            {
                MessengerInstance.Send(new NavigateToPageMessage()
                {
                    Page = "/Search.AlbumView",
                    Parameters = new Dictionary<string, object>()
                    {
                        {"album", album}
                    }
                });
            });

            GoToArtistCommand = new RelayCommand<LastFmArtist>(artist =>
            {
                MessengerInstance.Send(new NavigateToPageMessage()
                {
                    Page = "/Search.ArtistView",
                    Parameters = new Dictionary<string, object>()
                    {
                        {"artist", artist}
                    }
                });
            });

            ShareCommand = new RelayCommand(() =>
            {
                var shareViewModel = new ShareViewModel();
                if (Tracks != null && Tracks.Count > 0)
                {
                    foreach (var track in AllTracks.Take(15))
                    {
                        shareViewModel.Tracks.Add(track);
                    }
                }

                if (File.Exists(App.Root + "/Cache/artists/" + Artist.Name + ".jpg"))
                {
                    shareViewModel.ImagePath = App.Root + "/Cache/artists/" + Artist.Name + ".jpg";
                    shareViewModel.Image = new BitmapImage(new Uri(shareViewModel.ImagePath));
                }

                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new ShareView() { DataContext = shareViewModel };
                flyout.Show();

                shareViewModel.Activate();
            });
        }
Пример #5
0
        private void InitializeCommands()
        {
            CloseSettingsCommand = new RelayCommand(() =>
            {
                ViewModelLocator.Main.ShowSidebar = true;
                ViewModelLocator.Main.GoBackCommand.Execute(null);
            });

            SaveCommand = new RelayCommand(SaveSettings);

            SaveRestartCommand = new RelayCommand(() =>
            {
                SaveSettings();

                Process.Start(Application.ResourceAssembly.Location);
                Application.Current.Shutdown();
            });

            SignOutVkCommand = new RelayCommand(AccountManager.LogOutVk);

            LoginLastFmCommand = new RelayCommand(() =>
            {
                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new LoginLastFmView();
                flyout.Show();
            });

            SignOutLastFmCommand = new RelayCommand(AccountManager.LogoutLastFm);

            CheckUpdatesCommand = new RelayCommand(() => ViewModelLocator.UpdateService.CheckUpdates());

            ClearCacheCommand = new RelayCommand(() =>
            {
                if (!Directory.Exists("Cache"))
                    return;

                foreach (var file in Directory.EnumerateFiles("Cache"))
                {
                    try
                    {
                        File.Delete(file);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                }

                foreach (var dir in Directory.EnumerateDirectories("Cache"))
                {
                    try
                    {
                        Directory.Delete(dir, true);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex);
                    }
                }

                CacheSize = StringHelper.FormatSize(Math.Round(CalculateFolderSize("Cache"), 1));
            });

            TellCommand = new RelayCommand(Tell);
        }
Пример #6
0
        private void InitializeCommands()
        {
            PlayAudioCommand = new RelayCommand<Audio>(audio =>
            {
                AudioService.Play(audio);
                AudioService.SetCurrentPlaylist(Tracks);
            });

            SaveCommand = new RelayCommand(Save);

            ShareCommand = new RelayCommand(() =>
            {
                var shareViewModel = new ShareViewModel();
                if (Tracks != null && Tracks.Count > 0)
                {
                    foreach (var track in Tracks.Take(15))
                    {
                        shareViewModel.Tracks.Add(track);

                    }
                }

                if (File.Exists(App.Root + "/Cache/artists/" + Album.Artist + ".jpg"))
                {
                    shareViewModel.ImagePath = App.Root + "/Cache/artists/" + Album.Artist + ".jpg";
                    shareViewModel.Image = new BitmapImage(new Uri(shareViewModel.ImagePath));
                }

                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new ShareView() { DataContext = shareViewModel };
                flyout.Show();

                shareViewModel.Activate();
            });
        }
Пример #7
0
 private void TellFriendsRequest()
 {
     var flyout = new FlyoutControl();
     flyout.FlyoutContent = new TellFriendsRequestView();
     flyout.Show();
 }
Пример #8
0
        public void InitializeCommands()
        {
            CancelCommand = new RelayCommand(() =>
            {
                Tracks.Clear();
                ViewModelLocator.Main.ShowShareBar = false;
            });

            CloseCommand = new RelayCommand(() =>
            {
                Close();
            });

            GoNextCommand = new RelayCommand(() =>
            {
                ViewModelLocator.Main.ShowShareBar = false;

                var flyout = new FlyoutControl();
                flyout.FlyoutContent = new ShareView() { DataContext = this };
                flyout.Show();

                Activate();
            });

            RemoveTrackCommand = new RelayCommand<VkAudio>(track => Tracks.Remove(track));

            PublishCommand = new RelayCommand(() =>
            {
                if (ShareToSociety && SelectedSociety == null)
                    return;

                if (ShareToUser && SelectedFriend == null)
                    return;

                var progress = new Progress<int>(p =>
                {
                    Progress += p;
                });

                Share(progress, _cancellationToken.Token);
            });

            ClearImageCommand = new RelayCommand(() =>
            {
                Image = null;
                ImagePath = null;
            });

            AddImageCommand = new RelayCommand(() =>
            {
                var fileOpenDialog = new OpenFileDialog();
                fileOpenDialog.Filter = "Images|*.png;*.jpg";
                if (fileOpenDialog.ShowDialog() == DialogResult.OK)
                {
                    ImagePath = fileOpenDialog.FileName;
                    Image = new BitmapImage(new Uri(ImagePath));
                }
            });
        }