コード例 #1
0
        public EnqueuedCollection Enqueue(MusicService service, IMediaCollection collection, string pathFormat)
        {
            var item = new EnqueuedCollection
            {
                Service         = service,
                PathFormat      = pathFormat,
                MediaCollection = collection
            };

            Add(item);
            return(item);
        }
コード例 #2
0
        public async Task UpdatePlaylist()
        {
            MusicService _service = new MusicService(new UnitOfWork(GetContext()));
            Playlist     entity   = new Playlist()
            {
                Id = 1, Author = "WhiteInferno#2755", Name = "MyPlaylist", Urls = "https://youtu.be/2_R3Q5cgSsY|https://www.youtube.com/watch?v=FW5NKlh88ik"
            };
            var   task = _service.Update(entity);
            await task;

            Debug.WriteLine("The playlist has been updated successfully!");
        }
コード例 #3
0
ファイル: ServiceLocator.cs プロジェクト: txotxopue/RamasHope
 /// <summary>
 /// Sets a new Music Service as the active one.
 /// </summary>
 /// <param name="pMusicService">Music Service to register as currently active</param>
 public static void ProvideMusicService(MusicService pMusicService)
 {
     if (pMusicService != null)
     {
         _musicService = pMusicService;
     }
     else
     {
         // If it is null, we provide a new Music Service that does nothing
         _musicService = new NullMusicService();
     }
 }
 public async Task <AuthenticationResult> Authenticate(MusicService service)
 {
     ServiceBeginAuthenticating(service);
     try
     {
         return(new AuthenticationResult(service, await service.AsAuthenticatableAsync().AuthenticateAsync()));
     }
     finally
     {
         ServiceEndAuthenticating(service);
     }
 }
コード例 #5
0
        public async Task CreatePlaylist()
        {
            MusicService _service = new MusicService(new UnitOfWork(GetContext()));
            Playlist     entity   = new Playlist()
            {
                Author = "WhiteInferno#2755", Name = "MyPlaylist", Urls = ""
            };
            var   task = _service.Create(entity);
            await task;

            Debug.WriteLine("The playlist has been added successfully!");
        }
コード例 #6
0
        public PlayingRotateService(DiscordSocketClient client, IBotConfigProvider bcp, MusicService music, DbService db)
        {
            _client = client;
            _bcp    = bcp;
            _music  = music;
            _db     = db;
            _log    = LogManager.GetCurrentClassLogger();
            _rep    = new ReplacementBuilder()
                      .WithClient(client)
                      .WithStats(client)
                      .WithMusic(music)
                      .Build();

            _t = new Timer(async(objState) =>
            {
                try
                {
                    bcp.Reload();

                    var state = (TimerState)objState;
                    if (!BotConfig.RotatingStatuses)
                    {
                        return;
                    }
                    if (state.Index >= BotConfig.RotatingStatusMessages.Count)
                    {
                        state.Index = 0;
                    }

                    if (!BotConfig.RotatingStatusMessages.Any())
                    {
                        return;
                    }
                    var status = BotConfig.RotatingStatusMessages[state.Index++].Status;
                    if (string.IsNullOrWhiteSpace(status))
                    {
                        return;
                    }

                    status = _rep.Replace(status);

                    try { await client.SetGameAsync(status).ConfigureAwait(false); }
                    catch (Exception ex)
                    {
                        _log.Warn(ex);
                    }
                }
                catch (Exception ex)
                {
                    _log.Warn("Rotating playing status errored.\n" + ex);
                }
            }, new TimerState(), TimeSpan.FromMinutes(1), TimeSpan.FromMinutes(1));
        }
コード例 #7
0
        public void UpdateMusic_EmptyName_InvalidDataException()
        {
            // Arrange
            var(unitOfWork, musicRepo, dbCollectionMusic) = GetMocks();
            var service = new MusicService(unitOfWork.Object);
            var music   = new Music()
            {
                Name = ""
            };

            // Act + Assert
            Assert.ThrowsAsync <InvalidDataException>(async() => await service.UpdateMusic(27, music));
        }
コード例 #8
0
        public void UpdateMusic_NoItemForUpdate_NullReferenceException()
        {
            // Arrange
            var(unitOfWork, musicRepo, dbCollectionMusic) = GetMocks();
            var service = new MusicService(unitOfWork.Object);
            var music   = new Music()
            {
                Name = "Update Track"
            };

            // Act + Assert
            Assert.ThrowsAsync <NullReferenceException>(async() => await service.UpdateMusic(0, music));
        }
コード例 #9
0
        public async void MusicListView_OnTapped(object sender, TappedRoutedEventArgs e)
        {
            if (SelectTrack == null)
            {
                return;
            }

            SelectPlaylist.TracksFiles = Tracks.ToList();

            await MusicService.PlayMusic(SelectTrack, 2, SelectPlaylist);

            //throw new NotImplementedException();
        }
コード例 #10
0
        public async Task StartLoading(string blockId)
        {
            IsLoading = true;
            Changed("IsLoading");
            var tracksVk = await MusicX.Core.VKontakte.Music.Artists.GetPopularTracks(blockId);

            var tracks = await MusicService.ConvertToAudioFile(tracksVk);

            Tracks = new ObservableCollection <AudioFile>(tracks);
            Changed("Tracks");
            IsLoading = false;
            Changed("IsLoading");
        }
コード例 #11
0
        private void AddServiceListViewItem(MusicService service)
        {
            var lvItem = new ListViewItem
            {
                Text = "Please wait..."
            };

            lvItem.SubItems.Add(service.Info.Name);
            lvItem.SubItems.Add(LocalisableAccountNameFormat.GetFormattedName(service.AsAuthenticatable().Account));
            serviceLvItems.Add(service, lvItem);
            animator.Add(lvItem);
            servicesListView.Items.Add(lvItem);
        }
コード例 #12
0
        /// <summary>
        /// 初始化MainPage类的新实例
        /// </summary>
        public MainPage()
        {
            ViewModel = new MainPageViewModel();
            this.InitializeComponent();
            MusicService          = ViewModel.MusicService;
            MusicInfomation       = ViewModel.MusicInfomation;
            App.MainPageViewModel = ViewModel;

            MusicService.MediaPlaybackList.CurrentItemChanged += MediaPlaybackList_CurrentItemChanged;

            processSlider.AddHandler(PointerReleasedEvent, new PointerEventHandler(UIElement_OnPointerReleased), true);
            processSlider.AddHandler(PointerPressedEvent, new PointerEventHandler(UIElement_EnterPressedReleased), true);
        }
コード例 #13
0
 public DiscordEventHandler(DiscordShardedClient client, CommandHandler commandHandler
                            , ServerActivityLogger serverActivityLogger, WasagotchiTimer wasagotchiTimer, Events events, MessageRewardHandler messageRewardHandler, MusicService musicService, LavaShardClient lavaShardClient, LavaRestClient lavaRestClient)
 {
     _client               = client;
     _commandHandler       = commandHandler;
     _serverActivityLogger = serverActivityLogger;
     _wasagotchiTimer      = wasagotchiTimer;
     _events               = events;
     _messageRewardHandler = messageRewardHandler;
     _musicService         = musicService;
     _lavaShardClient      = lavaShardClient;
     _lavaRestClient       = lavaRestClient;
 }
 public async Task <AuthenticationResult> Authenticate(MusicService service, string username, string password, bool rememberMe)
 {
     ServiceBeginAuthenticating(service);
     try
     {
         return
             (new AuthenticationResult(service, await service.AsUsernamePasswordAuthenticatable().AuthenticateAsync(username, password, rememberMe)));
     }
     finally
     {
         ServiceEndAuthenticating(service);
     }
 }
コード例 #15
0
ファイル: MusicController.cs プロジェクト: LevakZlk/MPlayer
        public ActionResult MusicViewSearch(string sText, string sType)
        {
            var musics = MusicService.GetAll().Select(music => new MusicModel()
            {
                Id         = music.Id,
                Name       = music.Name,
                Path       = music.Path,
                SingerName = SingerService.GetById(music.SingerId).Name,
                GenreName  = GenreService.GetById(music.GenreId).Name
            }).ToList();

            return(View("MusicView", musics));
        }
コード例 #16
0
        public void Get(string path, [FromQuery] string sign)
        {
            if (CommonHelper.Md5(path + CommonHelper.SignKey) != sign)
            {
                Response.StatusCode = 403;
                return;
            }
            if (string.IsNullOrEmpty(path))
            {
                Response.StatusCode = 403;
                return;
            }
            var paths = path.Split('.');

            if (paths.Length != 2)
            {
                Response.StatusCode = 403;
                return;
            }
            var keys = paths[0].Split('_');

            if (keys.Length != 3)
            {
                Response.StatusCode = 403;
                return;
            }
            var linkInfo = MusicService.GetMusic(keys[0]).GetSongUrl(keys[2], keys[1], paths[1]);

            if (linkInfo == null)
            {
                Response.StatusCode = 404;
                return;
            }
            if (linkInfo.StartsWith("http://"))
            {
                Response.StatusCode = 302;
                Response.Headers.Add("Location", linkInfo);
            }
            else
            {
                if (string.IsNullOrEmpty(linkInfo))
                {
                    Response.StatusCode = 404;
                }
                else
                {
                    Response.StatusCode = 200;
                    Response.WriteAsync(linkInfo);
                }
            }
        }
コード例 #17
0
        public async Task <List <AudioFile> > GetMoreAudio(CancellationToken token, uint offset)
        {
            if (InternetService.Connected)
            {
                try
                {
                    if (firstLoading)
                    {
                        IsLoading = true;
                        Changed("IsLoading");
                    }
                    IList <IAudioFile> tracks = new List <IAudioFile>();
                    List <AudioFile>   music  = new List <AudioFile>();
                    try
                    {
                        tracks = await Recommendations.Tracks(20, Tracks.Count);

                        music = await MusicService.ConvertToAudioFile(tracks);
                    }
                    catch (Flurl.Http.FlurlHttpException)
                    {
                        music = new List <AudioFile>();

                        InternetService.GoToOfflineMode();
                        await ContentDialogService.Show(new ErrorConnectContentDialog());
                    }

                    if (music.Count < 20)
                    {
                        hasMoreLoading = false;
                    }

                    firstLoading = false;

                    IsLoading = false;
                    Changed("IsLoading");
                    return(music);
                }catch (Exception e)
                {
                    await ContentDialogService.Show(new ExceptionDialog("Неизвестная ошибка при получении рекомендаций", "Мы не смогли получить рекомендации ВКонтакте", e));

                    return(new List <AudioFile>());
                }
            }
            else
            {
                hasMoreLoading = false;
                InternetService.GoToOfflineMode();
                return(new List <AudioFile>());
            }
        }
コード例 #18
0
        public bool CanRestore(MusicService service)
        {
            if (IsAuthenticating(service))
            {
                return(false);
            }
            var ias = service.AsAuthenticatable();

            if (ias == null)
            {
                return(false);
            }
            return(ias.HasSavedSession && !ias.IsAuthenticated && ias.Account != null);
        }
コード例 #19
0
        public EnqueuedCollection Enqueue(MusicService service, IMediaCollection collection, string destination, string pathFormat)
        {
            var item = new EnqueuedCollection
            {
                Destination     = destination,
                Service         = service,
                PathFormat      = pathFormat,
                MediaCollection = collection,
                Type            = MediaCollectionAsType(collection)
            };

            Add(item);
            return(item);
        }
コード例 #20
0
        public void DeleteMusic_ItemDoesNotExists_NullReferenceException()
        {
            // Arrange
            var(unitOfWork, musicRepo, dbCollectionMusic) = GetMocks();
            var service = new MusicService(unitOfWork.Object);
            var music   = new Music
            {
                Id   = 0,
                Name = "Delete Track"
            };

            // Act + Assert
            Assert.ThrowsAsync <NullReferenceException>(async() => await service.DeleteMusic(music));
        }
コード例 #21
0
        public AuthProgressForm RestoreSingle(MusicService service)
        {
            if (!am.CanRestore(service))
            {
                TaskDialogHelper.ShowMessage(caption: "Cannot restore this service right now.",
                                             message: "The service is already being restored in the background. Please try again in a moment.",
                                             icon: TaskDialogStandardIcon.Error, buttons: TaskDialogStandardButtons.Ok, owner: parent.Handle);
                return(null);
            }
            var form = new AuthProgressForm(new[] { service });

            form.Show(parent);
            return(form);
        }
コード例 #22
0
        public ActionResult Edit(string id)
        {
            var list = MusicService.GetAll().Select(m => new { Id = m.Id, Name = m.Name }).ToList();

            var playlist = PlaylistService.GetById(id);

            PlaylistChangeModel.GetMusicSelectItems = new MultiSelectList(list, "Id", "Name", playlist.Musics.Select(x => x.Id).ToList());
            PlaylistChangeModel gm = new PlaylistChangeModel()
            {
                Id   = playlist.Id,
                Name = playlist.Name
            };

            return(View(gm));
        }
コード例 #23
0
ファイル: MainForm.cs プロジェクト: kkhrychikov/Athame
        private void AddToQueue(MusicService service, IMediaCollection item, string destination, string pathFormat)
        {
            var enqueuedItem = mediaDownloadQueue.Enqueue(service, item, destination, pathFormat);
            var header       = MakeGroupHeader(enqueuedItem);
            var group        = new ListViewGroup(header, HorizontalAlignment.Center);
            var groupIndex   = queueListView.Groups.Add(group);
            var finalTracks  = new List <string>();

            for (var i = 0; i < item.Tracks.Count; i++)
            {
                var t      = item.Tracks[i];
                var lvItem = new ListViewItem
                {
                    Group = group,
                    Tag   = new MediaItemTag
                    {
                        Track             = t,
                        Collection        = enqueuedItem,
                        GroupIndex        = groupIndex,
                        IndexInCollection = i
                    }
                };
                if (!t.IsDownloadable)
                {
                    Log.Warning(Tag, $"Adding non-downloadable track {service.Info.Name}/{t.Id}");
                    lvItem.BackColor = SystemColors.Control;
                    lvItem.ForeColor = SystemColors.GrayText;
                    lvItem.ImageKey  = "not_downloadable";
                    lvItem.Text      = "Unavailable";
                }
                else
                {
                    lvItem.ImageKey = "ready";
                    lvItem.Text     = "Ready to download";
                }
                lvItem.SubItems.Add(t.DiscNumber + " / " + t.TrackNumber);
                lvItem.SubItems.Add(t.Title);
                lvItem.SubItems.Add(t.Artist.Name);
                lvItem.SubItems.Add(t.Album.Title);
                lvItem.SubItems.Add(BuildFlags(t.CustomMetadata));
                lvItem.SubItems.Add(Path.Combine(destination, t.GetBasicPath(enqueuedItem.PathFormat, item)));

                finalTracks.Add(t.Artist.Name + " - " + t.Title);
                group.Items.Add(lvItem);
                queueListView.Items.Add(lvItem);
            }
            group.Header = MakeGroupHeader(enqueuedItem);
        }
コード例 #24
0
        public async Task UploadFiles()
        {
            var serverUploadFolder = ConfigurationManager.AppSettings["MediaServerSaveBaseUrl"];
            var streamProvider     = new MultipartFormDataStreamProvider(serverUploadFolder);
            await Request.Content.ReadAsMultipartAsync(streamProvider);

            MusicService service = new MusicService();

            for (int i = 0; i < streamProvider.Contents.Count; i++)
            {
                string fileOriginalName = streamProvider.Contents[i].Headers.ContentDisposition.FileName.Trim(new char[] { '\"' });
                string fileGuid         = Path.GetFileName(streamProvider.FileData[i].LocalFileName);

                service.Store(fileOriginalName, fileGuid);
            }
        }
コード例 #25
0
        public PlayButtonListViewModel()
        {
            BASS.BASS_Init(-1, 44100, BASSInitFlags.BASS_DEVICE_DEFAULTS, IntPtr.Zero);
            this.musics = new ObservableCollection <Music>();

            _eventAggregator.GetEvent <MusicAddFileEvent>().Subscribe(e => AddFile(e));


            MusicService musicservice = new MusicService();
            var          _music       = musicservice.AddTestMusic(@"D:\CodeBase\音效软件\Win32\Debug\单车.mp3");

            this.musics.Add(_music);

            _music = musicservice.AddTestMusic(@"D:\CodeBase\音效软件\Win32\Debug\苦瓜.mp3");
            this.musics.Add(_music);
        }
コード例 #26
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.Configure <KestrelServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });
            services.Configure <IISServerOptions>(options =>
            {
                options.AllowSynchronousIO = true;
            });

            MusicService collection = new MusicService();

            services.AddSingleton(collection);
            services.AddControllers();
        }
コード例 #27
0
 public async Task <AuthenticationResult> Authenticate(MusicService service)
 {
     ServiceBeginAuthenticating(service);
     try
     {
         return(new AuthenticationResult(service, await service.AsAuthenticatableAsync().AuthenticateAsync(), null));
     }
     catch (Exception ex)
     {
         return(new AuthenticationResult(service, false, ex));
     }
     finally
     {
         ServiceEndAuthenticating(service);
     }
 }
コード例 #28
0
        public async Task CreateMusic_FullInfo_Success()
        {
            // Arrange
            var(unitOfWork, musicRepo, dbCollection) = GetMocks();
            var service = new MusicService(unitOfWork.Object);
            var music   = new Music
            {
                Id   = 28,
                Name = "New Track"
            };

            // Act
            await service.CreateMusic(music);

            // Assert
            Assert.IsTrue(dbCollection.ContainsKey(music.Id));
        }
コード例 #29
0
 public List <SongResult> CollectSearch([FromQuery] string t, [FromQuery] string id, [FromQuery] int p, [FromQuery] int s)
 {
     if (string.IsNullOrEmpty(t) || string.IsNullOrEmpty(id))
     {
         Response.StatusCode = 403;
         return(null);
     }
     if (p == 0)
     {
         p = 1;
     }
     if (s == 0)
     {
         s = 1000;
     }
     return(MusicService.GetMusic(t).CollectSearch(id, p, s));
 }
コード例 #30
0
        private void servicesListBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            selectedInstance = services[servicesListBox.SelectedIndex];
            selectedService  = selectedInstance.Service;
            serviceUiPanel.Controls.Clear();
            var ssv = new ServiceSettingsView(selectedInstance)
            {
                Dock = DockStyle.Fill
            };

            serviceUiPanel.Controls.Add(ssv);
            serviceNameLabel.Text        = selectedService.Info.Name;
            serviceDescriptionLabel.Text = selectedService.Info.Description;
            serviceAuthorLabel.Text      = selectedService.Info.Author;
            serviceWebsiteLabel.Text     = selectedService.Info.Website.ToString();
            serviceVersionLabel.Text     = selectedInstance.Assembly.GetName().Version.ToString();
        }
コード例 #31
0
ファイル: ChannelsController.cs プロジェクト: uheerme/core
 /// <summary>
 /// Default ChannelsController constructor.
 /// </summary>
 /// <param name="channels">The ChannelService automaticly injected.</param>
 /// <param name="musics">The MusicService automaticly injected.</param>
 public ChannelsController(ChannelService channels, MusicService musics)
 {   
     _channels = channels;
     _musics   = musics;
 }
コード例 #32
0
ファイル: MusicsController.cs プロジェクト: uheerme/core
 /// <summary>
 /// Constructor for Music resource's controller.
 /// </summary>
 /// <param name="musics">The music service which will be injected.</param>
 public MusicsController(MusicService musics)
 {
     _musics = musics;
 }
コード例 #33
0
 public LoginViewModel()
 {
     AccountName = NotLoggedInString;
     MusicService = MusicService.None;
 }