Beispiel #1
0
        /// <summary>
        /// Invoked when the application is activated to display search results.
        /// </summary>
        /// <param name="args">Details about the activation request.</param>
        protected async override void OnSearchActivated(Windows.ApplicationModel.Activation.SearchActivatedEventArgs args)
        {
            // TODO: Register the Windows.ApplicationModel.Search.SearchPane.GetForCurrentView().QuerySubmitted
            // event in OnWindowCreated to speed up searches once the application is already running
            // Reinitialize the app if a new instance was launched for search
            if (args.PreviousExecutionState == ApplicationExecutionState.NotRunning ||
                args.PreviousExecutionState == ApplicationExecutionState.ClosedByUser ||
                args.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {

                PodcastCollection pc = App.Current.Resources["podcastCollection"] as PodcastCollection;
                if (pc.Items.Count < 1)
                {
                    List<Podcast> podList = await Utils.loadLocalDataAsync();
                    PodcastCollection podcasts = new PodcastCollection();
                    foreach (Podcast pcast in podList)
                    {
                        //CHECK time w/o image 1969 with 2370 TDOD: add a async image download

                        podcasts.addItem(pcast);
                        // getEpisodes(pcast.url);
                        App.Current.Resources["podcastCollection"] = podcasts;
                    }
                    foreach (Podcast pcast in podcasts.Items)
                    {
                        //string imageurl = pcast.imageurl;
                        //if (!imageurl.Equals(String.Empty) && imageurl.StartsWith("http://"))
                        //{
                        //    pcast.thumbnail = new BitmapImage(new Uri(imageurl));
                        //}
                        //if (pcast.thumbnail == null)
                        //{
                        //    pcast.thumbnail = new BitmapImage(new Uri("ms-appx:/Assets/no-image-512-bg.png"));
                        //}
                    }
                }


                // Register handler for SuggestionsRequested events from the search pane
                SearchPane.GetForCurrentView().SuggestionsRequested += OnSuggestionsRequested;


            }
            // If the Window isn't already using Frame navigation, insert our own Frame
            var previousContent = Window.Current.Content;
            var frame = previousContent as Frame;

            

            // If the app does not contain a top-level frame, it is possible that this 
            // is the initial launch of the app. Typically this method and OnLaunched 
            // in App.xaml.cs can call a common method.
            if (frame == null)
            {
                // Create a Frame to act as the navigation context and associate it with
                // a SuspensionManager key
                frame = new Frame();
                BuildPodcast.Common.SuspensionManager.RegisterFrame(frame, "AppFrame");

                if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
                {
                    // Restore the saved session state only when appropriate
                    try
                    {
                        await BuildPodcast.Common.SuspensionManager.RestoreAsync();
                    }
                    catch (BuildPodcast.Common.SuspensionManagerException)
                    {
                        //Something went wrong restoring state.
                        //Assume there is no state and continue
                    }
                }
            }

            frame.Navigate(typeof(SearchResultsPage), args.QueryText);
            Window.Current.Content = frame;

            // Ensure the current window is active
            Window.Current.Activate();
        }
        async void setDataContext()
        {
            favecasts = new PodcastCollection();
            //progressRing.IsActive = true;
            StorageFile file = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(@"Assets\data\Favorites.xml"); //OpenForReadAsync();
            //StorageFile defaultImage = await Package.Current.InstalledLocation.GetFileAsync(@"Assets\face.jpg");
            string text = await FileIO.ReadTextAsync(file);

            //Debug.WriteLine(text);

            PodcastsXMLParser parser = new PodcastsXMLParser(text);
            Debug.WriteLine("total podcasts: " + parser.itemCount);

            foreach (Podcast pcast in parser.Podcasts)
            {
                //CHECK time w/o image 1969 with 2370 TDOD: add a async image download
                favecasts.addItem(pcast);
            }

            //foreach (Podcast pcast in favecasts.Items)
            //{
            //    string imageurl = pcast.imageurl;
            //    pcast.thumbnail = null;
            //    if (!imageurl.Equals(String.Empty) && (imageurl.StartsWith("http://") || imageurl.StartsWith("ms-appx:/")))
            //    {
            //        pcast.thumbnail = new BitmapImage(new Uri(imageurl));
            //        Debug.WriteLine("adding images with http");
            //    }
            //    if (pcast.thumbnail == null)
            //    {
            //        pcast.thumbnail = new BitmapImage(new Uri("ms-appx:/Assets/no-image-512-bg.png"));
            //        Debug.WriteLine("adding images no image");
            //    }
                
            //}
            //DEBUG
            
            //foreach (Podcast p in favecasts.Items)
            //{
            //    Debug.WriteLine(p.ToJson());

            //}
            string jsonStr = JsonSerialization.WriteFromObject(favecasts.Items);
            Debug.WriteLine("jason result" + jsonStr);

            IStorageFile fileout = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(@"data\fav.json", CreationCollisionOption.OpenIfExists);
            await FileIO.WriteTextAsync(fileout, jsonStr);
            text = await FileIO.ReadTextAsync(fileout);

            var podObj = JsonSerialization.ReadToObject(text);
            Debug.WriteLine("fav count" + podObj.Count);
            Debug.WriteLine("first object" + podObj[0]);
            //progressRing.IsActive = false;
        }