Ejemplo n.º 1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            BeatMachineDataContext context = new BeatMachineDataContext(
                BeatMachineDataContext.DBConnectionString);

            context.AnalyzedSongs.DeleteAllOnSubmit(
                context.AnalyzedSongs.ToList());
            context.SubmitChanges();
        }
Ejemplo n.º 2
0
        public SettingsViewModel(IMessenger messenger)
            : base(messenger)
        {
            ////if (IsInDesignMode)
            ////{
            ////    // Code runs in Blend --> create design time data.
            ////}
            ////else
            ////{
            ////    // Code runs "for real"
            ////}

            MessengerInstance.Register<NewSongsAddedMessage>(
                this,
                m =>
                {
                    DispatcherHelper.CheckBeginInvokeOnUI(() =>
                    {
                        SongsAnalyzed = true;
                    });
                });

            ReanalyzeSongsCommand = new RelayCommand(() =>
            {
                MessengerInstance.Send<MediaPlayerStopMessage>(
                    new MediaPlayerStopMessage());

                using (BeatMachineDataContext context = new BeatMachineDataContext(
                    BeatMachineDataContext.DBConnectionString))
                {
                    context.AnalyzedSongs.DeleteAllOnSubmit(
                        context.AnalyzedSongs.ToList());
                    context.Summary.DeleteAllOnSubmit(
                        context.Summary.ToList());
                    context.SubmitChanges();
                }
            });

            SendErrorLogsCommand = new RelayCommand(() =>
            {
                MemoryTarget target = LogManager.Configuration.FindTargetByName("memory") as MemoryTarget;

                StringBuilder sb = new StringBuilder();
                foreach (string entry in target.Logs)
                {
                    sb.AppendLine(entry);
                }

                EmailComposeTask emailComposeTask = new EmailComposeTask();
                emailComposeTask.Subject = "mu:ru error log";
                emailComposeTask.Body = sb.ToString();
                emailComposeTask.To = "*****@*****.**";
                emailComposeTask.Show();
            });
        }
Ejemplo n.º 3
0
        private void StoreDownloadedSongs(Catalog cat)
        {
            logger.Debug("Downloaded {0} songs", cat.Items.Count);

            var analyzedSongs = cat.Items.
                Select<Song, AnalyzedSong>(s => new AnalyzedSong
                {
                    ItemId = s.Request.ItemId,
                    ArtistName = s.ArtistName ?? s.Request.ArtistName,
                    SongName = s.SongName ?? s.Request.SongName,
                    AudioSummary = s.AudioSummary != null ?
                    new AnalyzedSong.Summary
                    {
                        Tempo = s.AudioSummary.Tempo,
                        ItemId = s.Request.ItemId
                    } : null
                }).
                Where<AnalyzedSong>(s =>
                {
                    bool matches = SongsToAnalyzeIds.Contains(s.ItemId);
                    if (matches)
                    {
                        logger.Trace("Song '{0}' matches a song we're looking for", s);
                    }
                    return matches;
                });

            int analyzedCount = analyzedSongs.Count();

            logger.Debug("Matched {0} songs", analyzedCount);

            if (analyzedCount > 0)
            {
                using (BeatMachineDataContext context = new BeatMachineDataContext(
                    BeatMachineDataContext.DBConnectionString))
                {
                    context.AnalyzedSongs.InsertAllOnSubmit(analyzedSongs);
                    context.SubmitChanges();
                }

                logger.Debug("Stored all matches to database");

                foreach (AnalyzedSong s in analyzedSongs)
                {
                    SongsToAnalyze.Remove(
                        SongsToAnalyze.Where(x => String.Equals(x.ItemId, s.ItemId)).First());
                    SongsToAnalyzeIds.Remove(s.ItemId);
                }

                logger.Debug("Removed matches from list of songs to analyze");

                NewSongsAdded = true;
            }
        }
Ejemplo n.º 4
0
        static void Api_CatalogReadCompleted(object sender, EchoNestApiEventArgs e)
        {
            if (e.Error == null)
            {
                App thisApp = App.Current as App;
                BeatMachineDataContext context = new BeatMachineDataContext(
                    BeatMachineDataContext.DBConnectionString);

                Catalog cat = (Catalog)e.GetResultData();

                // TODO This check doesn't work well, it won't terminate
                // especially in the case where the catalog has more items that
                // the client doesn't know about

                if (!(cat.Items.Count == 0 &&
                    context.AnalyzedSongs.Count() ==
                    thisApp.Model.SongsToAnalyzeBatchSize))
                {
                    context.AnalyzedSongs.InsertAllOnSubmit(
                        cat.Items.Select<Song, AnalyzedSong>(
                        s => new AnalyzedSong
                        {
                            ItemId = s.Request.ItemId,
                            ArtistName = s.ArtistName ?? s.Request.ArtistName,
                            SongName = s.SongName ?? s.Request.SongName,
                            AudioSummary = s.AudioSummary != null ?
                                new AnalyzedSong.Summary {
                                    Tempo = s.AudioSummary.Tempo
                                } : null
                        }
                       ));
                    context.SubmitChanges();

                    downloadSkip = context.AnalyzedSongs.Count();

                    DownloadAnalyzedSongsNeedsToRunAgain();
                }
                else
                {
                    thisApp.Model.SongsToAnalyzeBatchDownloadReady = true;
                }

            } else {
                DownloadAnalyzedSongsNeedsToRunAgain();
            }
        }