Esempio n. 1
0
        // Code to execute when the application is launching (eg, from Start)
        // This code will not execute when the application is reactivated
        private void Application_Launching(object sender, LaunchingEventArgs e)
        {
            Model = new Model.DataModel();
            Api = new EchoNestApi("R2O4VVBVN5EFMCJRP", false);
            bool songsOnDeviceReady = false;
            bool analyzedSongsReady = false;
            bool catalogIdReady = false;

            ExecutionQueue.Enqueue(
                new WaitCallback(BeatMachine.Model.DataModel.GetAnalyzedSongs),
                ExecutionQueue.Policy.Immediate);
            ExecutionQueue.Enqueue(
                new WaitCallback(BeatMachine.Model.DataModel.GetSongsOnDevice),
                ExecutionQueue.Policy.Immediate);
            ExecutionQueue.Enqueue(
                new WaitCallback(BeatMachine.Model.DataModel.LoadCatalogId),
                ExecutionQueue.Policy.Immediate);
            Model.PropertyChanged += new PropertyChangedEventHandler(
                (pSender, pE) =>
                {
                    if (String.Equals(pE.PropertyName, "CatalogId") &&
                        !String.IsNullOrEmpty(Model.CatalogId))
                    {
                        catalogIdReady = true;
                    }
                    else if (String.Equals(pE.PropertyName, "SongsOnDeviceLoaded"))
                    {
                        songsOnDeviceReady = true;
                    }
                    else if (String.Equals(pE.PropertyName, "AnalyzedSongsLoaded"))
                    {
                        analyzedSongsReady = true;
                    }
                    if (catalogIdReady && songsOnDeviceReady && analyzedSongsReady)
                    {
                        ExecutionQueue.Enqueue(
                            new WaitCallback(BeatMachine.Model.DataModel.DiffSongs),
                            ExecutionQueue.Policy.Immediate);

                        // Make sure we only run this once
                        catalogIdReady = false;
                        songsOnDeviceReady = false;
                        analyzedSongsReady = false;
                    }
                });
            Model.PropertyChanged += new PropertyChangedEventHandler(
                (pSender, pE) =>
                {
                    if (String.Equals(pE.PropertyName, "SongsToAnalyzeLoaded"))
                    {
                        if ((pSender as DataModel).SongsToAnalyzeLoaded)
                        {
                            ExecutionQueue.Enqueue(
                                new WaitCallback(
                                    BeatMachine.Model.DataModel.AnalyzeSongs),
                                ExecutionQueue.Policy.Immediate);
                        }
                    }
                    else if (String.Equals(pE.PropertyName, "SongsToAnalyzeBatchUploadReady"))
                    {
                        if ((pSender as DataModel).SongsToAnalyzeBatchUploadReady)
                        {
                            ExecutionQueue.Enqueue(
                                new WaitCallback(
                                    BeatMachine.Model.DataModel.DownloadAnalyzedSongs),
                                ExecutionQueue.Policy.Queued);
                        }
                    }
                    else if (String.Equals(pE.PropertyName, "SongsToAnalyzeBatchDownloadReady"))
                    {
                        if ((pSender as DataModel).SongsToAnalyzeBatchDownloadReady)
                        {
                            ExecutionQueue.Enqueue(
                                new WaitCallback(
                                    BeatMachine.Model.DataModel.AnalyzeSongs),
                                ExecutionQueue.Policy.Queued);
                        }
                    }
                });
        }
Esempio n. 2
0
 // Code to execute when the application is launching (eg, from Start)
 // This code will not execute when the application is reactivated
 private void Application_Launching(object sender, LaunchingEventArgs e)
 {
     Api = new EchoNestApi("R2O4VVBVN5EFMCJRP");
 }