示例#1
0
        /// <summary>
        /// Navigate to the specified gallery page.
        /// </summary>
        /// <param name="page">The state object for the gallery page</param>
        public void GoToGallery(GalleryPage page)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page", "Must specify the model for the gallery page");
            }

            // If we have no page session, just spit out a trace statement.
            if (session == null)
            {
                Debug.WriteLine("GoToGallery: " + page.Description);
                return;
            }


            //
            // Construct the arguments dictionary and then navigate to the
            // gallery page template.
            //

            Dictionary <string, object> properties = new Dictionary <string, object>();

            properties["Page"]        = page;
            properties["Application"] = this;

            session.GoToPage("resx://Z/Z.Resources/GalleryPage", properties);
        }
        /// <summary>
        /// Create a music gallery.
        /// NOTE: This is public to enable debug markup access.
        /// </summary>
        public GalleryPage CreateGalleryPage(string path)
        {
            GalleryPage page = new GalleryPage();

            // Create the virtual list and enable slow data.
            VirtualList galleryList = new VirtualList(page, null);

            galleryList.EnableSlowDataRequests = true;
            galleryList.RequestSlowDataHandler = new RequestSlowDataHandler(CompleteGalleryItem);
            page.Content = galleryList;

            DirectoryInfo directory = GetDirectory(path);

            if (directory != null)
            {
                //
                // Populate the gallery with the contents of this folder.
                //

                page.Description = directory.Name;

                PopulateGallery(page, page.Content, directory);
            }
            else
            {
                //
                // This directory does not exist.
                // Present an empty gallery.
                //

                page.Description = Z.Resources.Music;
            }

            return(page);
        }
示例#3
0
        /// <summary>
        /// Create a gallery of episodes from a show.
        /// NOTE: This is public to enable debug markup access.
        /// </summary>
        public GalleryPage CreateEpisodeGalleryPage(int showId)
        {
            DataRow showData = GetShowData(showId);

            GalleryPage page = new GalleryPage();

            page.Description = (string)showData["TV_Show_Title"];

            // Create the virtual list and enable slow data.
            VirtualList galleryList = new VirtualList(page, null);

            galleryList.EnableSlowDataRequests = true;
            galleryList.RequestSlowDataHandler = new RequestSlowDataHandler(CompleteEpisodeGalleryItem);
            page.Content = galleryList;

            // No filters in the episode gallery
            page.Filters = null;

            //
            // Create all the gallery items.
            //

            DataTable tbl_TV_Episode = dataSet.Tables["tbl_TV_Episode"];

            string query = String.Format("TV_Show_ID = '{0}'", showId);

            DataRow[] matches = tbl_TV_Episode.Select(query);
            foreach (DataRow episodeData in matches)
            {
                page.Content.Add(CreateEpisodeGalleryItem(episodeData));
            }

            return(page);
        }
示例#4
0
        /// <summary>
        /// Create a gallery item from a row in the table.
        /// </summary>
        private GalleryItem CreateShowGalleryItem(DataRow showData)
        {
            GalleryItem item = new GalleryItem();

            item.Description = (string)showData["TV_Show_Title"];
            item.ItemId      = (int)showData["TV_Show_ID"];

            // Display the show provider in the metadata
            DataRow providerData = Z.DataSetHelpers.GetIDMappedDataRow(showData, "TV_Provider_ID",
                                                                       dataSet.Tables["tbl_TV_Provider"], "TV_Provider_ID");

            item.Metadata = (string)providerData["TV_Provider"];

            //
            // Hook up an event for when the gallery item is invoked.
            //

            item.Invoked += delegate(object sender, EventArgs args)
            {
                GalleryItem galleryItem = (GalleryItem)sender;

                // Navigate to a gallery page for this show.
                GalleryPage page = CreateEpisodeGalleryPage(galleryItem.ItemId);
                Application.Current.GoToGallery(page);
            };

            return(item);
        }
示例#5
0
        /// <summary>
        /// Create the main menu category entry for this experience.
        /// </summary>
        public override MenuCategory CreateMenuCategory()
        {
            MenuCategory category = new MenuCategory();

            // Title
            category.Title = Description;

            // Subtitle (extracted from the total episode count)
            DataTable tbl_TV_Show = dataSet.Tables["tbl_TV_Show"];
            string    subTitle    = String.Format(Z.Resources.TV_Category_SubTitle, tbl_TV_Show.Rows.Count);

            category.SubTitle = subTitle;


            //
            // Featured items
            //

            VirtualList items = new VirtualList(category, null);

            items.EnableSlowDataRequests = true;
            items.RequestSlowDataHandler = new RequestSlowDataHandler(CompleteEpisodeGalleryItem);
            category.Items = items;

            DataTable tbl_TV_Episode_And_Highlight = dataSet.Tables["tbl_TV_Episode_And_Highlight"];
            DataTable tbl_TV_Episode = dataSet.Tables["tbl_TV_Episode"];

            foreach (DataRow highlightData in tbl_TV_Episode_And_Highlight.Rows)
            {
                int     episodeId   = (int)highlightData["TV_Episode_ID"];
                DataRow episodeData = GetEpisodeData(episodeId);

                GalleryItem item = CreateEpisodeGalleryItem(episodeData);
                items.Add(item);

                // Stop once we've found 3 items.
                if (category.Items.Count >= 3)
                {
                    break;
                }
            }


            //
            // Set up a handler for when this category is clicked.
            //

            category.Invoked += delegate(object sender, EventArgs args)
            {
                // Go to our show gallery page.
                GalleryPage page = CreateShowGalleryPage();
                Application.Current.GoToGallery(page);
            };

            return(category);
        }
示例#6
0
        /// <summary>
        /// Creat the filters on the gallery.
        /// </summary>
        private void CreateShowGalleryFilters(GalleryPage page)
        {
            //
            // Put together a list of filters on the content.
            //

            ArrayListDataSet list = new ArrayListDataSet(page);

            // Create the unfiltered "All" filter
            ModelItem filterAll = new Filter(page, Z.Resources.TV_Filter_All, -1);

            list.Add(filterAll);

            // Get the rest of the filters out of the genre list.
            DataTable tbl_TV_Genre = dataSet.Tables["tbl_TV_Genre"];

            foreach (DataRow genreData in tbl_TV_Genre.Rows)
            {
                string genreName = (string)genreData["TV_Genre"];
                int    genreId   = (int)genreData["TV_Genre_ID"];

                ModelItem filter = new Filter(page, genreName, genreId);
                list.Add(filter);
            }

            // FUTURE: There's information in the data table for us to implement
            // a "featured" filter.  Its implementation would go here.

            Choice filters = new Choice(page, null, list);

            filters.Chosen = filterAll;

            //
            // Hook up the "filter changed" event so that we can apply the
            // active filter to our gallery.
            //
            // As soon as this Filters list is set, we will get an OnActiveFilterChanged
            // event which will cause us to populate the gallery.
            //

            page.ActiveFilterChanged += delegate(object sender, EventArgs e)
            {
                GalleryPage galleryPage  = (GalleryPage)sender;
                Filter      activeFilter = (Filter)galleryPage.Filters.Chosen;
                FilterContent(galleryPage, activeFilter.FilterId);
            };
            page.Filters = filters;
        }
示例#7
0
        /// <summary>
        /// Create the gallery page for this exprience.
        /// NOTE: This is public to enable debug markup access.
        /// </summary>
        public GalleryPage CreateShowGalleryPage()
        {
            GalleryPage page = new GalleryPage();

            page.Description = Description;


            // Create the virtual list and enable slow data.
            VirtualList galleryList = new VirtualList(page, null);

            galleryList.EnableSlowDataRequests = true;
            galleryList.RequestSlowDataHandler = new RequestSlowDataHandler(CompleteShowGalleryItem);
            page.Content = galleryList;

            // Create and apply the filters.
            CreateShowGalleryFilters(page);

            return(page);
        }
        /// <summary>
        /// Create a gallery item to represent a directory.
        /// </summary>
        private ThumbnailCommand CreateDirectoryGalleryItem(IModelItemOwner owner, DirectoryInfo info)
        {
            // Create the command
            ThumbnailCommand item = new ThumbnailCommand(owner);

            item.Description  = info.Name;
            item.Image        = directoryImage;
            item.Data["Path"] = info.FullName;

            // Hook up the invoked handler
            item.Invoked += delegate(object sender, EventArgs args)
            {
                ThumbnailCommand invokedDirectory = (ThumbnailCommand)sender;
                string           path             = (string)invokedDirectory.Data["Path"];

                // When invoked navigate to a new gallery page for this directory
                GalleryPage newPage = CreateGalleryPage(path);
                Application.Current.GoToGallery(newPage);
            };

            return(item);
        }
        /// <summary>
        /// Create the main menu category entry for this experience.
        /// </summary>
        public override MenuCategory CreateMenuCategory()
        {
            MenuCategory category = new MenuCategory();

            category.Title = Description;

            //
            // Featured items
            //

            VirtualList items = new VirtualList(category, null);

            items.EnableSlowDataRequests = true;
            items.RequestSlowDataHandler = new RequestSlowDataHandler(CompleteGalleryItem);
            category.Items = items;

            DirectoryInfo directory = GetDirectory(MusicDirectory);

            if (directory != null)
            {
                PopulateGallery(category, items, directory);
            }


            //
            // Set up a handler for when this category is clicked.
            //

            category.Invoked += delegate(object sender, EventArgs args)
            {
                // Go to our root gallery page.
                GalleryPage page = CreateGalleryPage(MusicDirectory);
                Application.Current.GoToGallery(page);
            };

            return(category);
        }
示例#10
0
        /// <summary>
        /// Populate the gallery's content given the current filer.
        /// </summary>
        private void FilterContent(GalleryPage page, int filterId)
        {
            page.Content.Clear();

            //
            // Populate the list with items according to the filter.
            //

            DataTable tbl_TV_Show = dataSet.Tables["tbl_TV_Show"];

            if (filterId < 0)
            {
                //
                // A negative filter Id signifies no filter ("All").
                // Populate the list with all entries in the table.
                //

                foreach (DataRow showData in tbl_TV_Show.Rows)
                {
                    page.Content.Add(CreateShowGalleryItem(showData));
                }
            }
            else
            {
                //
                // Fetch only the entries that have the matching genre type.
                //

                string    query   = String.Format("TV_Genre_ID = '{0}'", filterId);
                DataRow[] matches = tbl_TV_Show.Select(query);
                foreach (DataRow showData in matches)
                {
                    page.Content.Add(CreateShowGalleryItem(showData));
                }
            }
        }
示例#11
0
        /// <summary>
        /// Return Commands for items that match the search string.
        /// </summary>
        public override IList <SearchResult> Search(string value)
        {
            IList <SearchResult> results = new List <SearchResult>();

            //
            // Episodes
            //
            // Search the episode table for items that have this search
            // string in their title.
            //

            DataTable tbl_TV_Episode = dataSet.Tables["tbl_TV_Episode"];
            string    query          = String.Format("TV_Episode_Title LIKE '*{0}*'", value);

            DataRow[] matches = tbl_TV_Episode.Select(query);

            foreach (DataRow episodeData in matches)
            {
                int episodeId = (int)episodeData["TV_Episode_ID"];

                // Create the search result object
                SearchResult item = new SearchResult(episodeId);
                item.Description = (string)episodeData["TV_Episode_Title"];
                item.Type        = Z.Resources.TV_Search_Type_Episode;

                string imageName = (string)episodeData["TV_Episode_Gallery_Image"];
                item.Image = LoadImage(imageName);

                // Hook up an invoked handler
                item.Invoked += delegate(object sender, EventArgs args)
                {
                    SearchResult searchResult = (SearchResult)sender;

                    // Navigate to a details page for this item.
                    DetailsPage page = CreateEpisodeDetailsPage(searchResult.Id);
                    Application.Current.GoToDetails(page);
                };

                results.Add(item);
            }


            //
            // Shows
            //
            // Search the show table for items that have this search
            // string in their title.
            //

            DataTable tbl_TV_Show = dataSet.Tables["tbl_TV_Show"];

            query   = String.Format("TV_Show_Title LIKE '*{0}*'", value);
            matches = tbl_TV_Show.Select(query);

            foreach (DataRow showData in matches)
            {
                int showId = (int)showData["TV_Show_ID"];

                // Create the search result object
                SearchResult item = new SearchResult(showId);
                item.Description = (string)showData["TV_Show_Title"];
                item.Type        = Z.Resources.TV_Search_Type_Show;

                string imageName = (string)showData["TV_Show_Image"];
                item.Image = LoadImage(imageName);

                // Hook up an invoked handler
                item.Invoked += delegate(object sender, EventArgs args)
                {
                    SearchResult searchResult = (SearchResult)sender;

                    // Navigate to a gallery page for this item.
                    GalleryPage page = CreateEpisodeGalleryPage(searchResult.Id);
                    Application.Current.GoToGallery(page);
                };

                results.Add(item);
            }

            return(results);
        }
示例#12
0
        /// <summary>
        /// Called when one of the custom actions on a details page is clicked.
        /// </summary>
        private void OnEpisodeDetailsActionInvoked(DetailsCommand command)
        {
            TVEpisodeDetailsActionType actionType = (TVEpisodeDetailsActionType)command.Type;
            string value     = command.Value;
            int    episodeId = command.ItemId;

            //
            // Interpret the action.
            //

            switch (actionType)
            {
            case TVEpisodeDetailsActionType.WatchNow:
            {
                // Placeholder...
                break;
            }

            case TVEpisodeDetailsActionType.Record:
            {
                //
                // TODO: Grab the xml from the database
                //
                // As is this code schedules a manual 30 minute recording to
                // occur 1 hour from now on channel 4.
                //

                string   xmlRecordingInfoFormat = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<clickToRecord xmlns=\"urn:schemas-microsoft-com:ehome:clicktorecord\">\n\t<body>\n\t\t<programRecord programDuration=\"30\">\n\t\t\t<service>\n\t\t\t\t<key field=\"urn:schemas-microsoft-com:ehome:epg:service#mappedChannelNumber\" match=\"exact\">{0}</key>\n\t\t\t</service>\n\t\t\t<airing>\n\t\t\t\t<key field=\"urn:schemas-microsoft-com:ehome:epg:airing#starttime\">{1}</key>\n\t\t\t</airing>\n\t\t</programRecord>\n\t</body>\n</clickToRecord>";
                int      channelNumber          = 4;
                DateTime time             = DateTime.UtcNow.AddHours(1);
                string   xmlRecordingInfo = String.Format(xmlRecordingInfoFormat, channelNumber, time.ToString("o"));

                XmlReader reader = XmlReader.Create(new StringReader(xmlRecordingInfo));


                CreateScheduleRequestResult scheduleResult = CreateScheduleRequestResult.NoConfiguredResource;
                try
                {
                    //
                    // Create EventSchedule object and create ScheduleRequest from XML.
                    //

                    EventSchedule   scheduler = new EventSchedule();
                    ScheduleRequest request   = null;
                    scheduleResult = scheduler.CreateScheduleRequest(reader, ConflictResolutionPolicy.AllowConflict, "example", out request);

                    Debug.WriteLine("DetailsAction: Record: " + scheduleResult);
                }
                catch (EventScheduleException)
                {
                    // TV may not be configured - handle that exception.
                    Application.Current.MessageBox(Z.Resources.TV_NotSetUpDialog_Text, Z.Resources.TV_NotSetUpDialog_Caption);
                }


                //
                // Display a dialog to notify the user.
                //

                if ((scheduleResult != CreateScheduleRequestResult.NoConfiguredResource) &&
                    (Application.Current.MediaCenterEnvironment != null))
                {
                    EpisodeMetadata metadata = ExtractEpisodeMetadata(GetEpisodeData(episodeId), episodeId);

                    // Two options: "View Scheduled" or "OK"
                    IEnumerable buttons = new object[] {
                        Z.Resources.TV_RecordDialog_ViewScheduled,
                        (int)DialogButtons.Ok
                    };

                    // Use the gallery image in the dialog.
                    // Note that the Dialog API requires a standard Uri, so we
                    // need to specificy the system drive letter.
                    string systemDrive = Environment.GetEnvironmentVariable("SystemDrive");
                    string imagePath   = "file://" + systemDrive + ImagesDirectory + metadata.GalleryImagePath;

                    Application.Current.MediaCenterEnvironment.Dialog(
                        Z.Resources.TV_RecordDialog_Text,
                        metadata.Title,
                        buttons,
                        0, true,
                        imagePath,
                        delegate(DialogResult dialogResult)
                        {
                            // Custom button #1 = 100 = "View Scheduled"
                            // Navigate to the scheduled recordings page
                            if ((int)dialogResult == 100)
                            {
                                Application.Current.MediaCenterEnvironment.NavigateToPage(PageId.ScheduledTVRecordings, null);
                            }

                            Debug.WriteLine("Dialog closed:" + dialogResult);
                        }
                        );
                }
                break;
            }

            case TVEpisodeDetailsActionType.Related:
            {
                //
                // Go to this episode's show gallery.
                //

                EpisodeMetadata metadata = ExtractEpisodeMetadata(GetEpisodeData(episodeId), episodeId);
                GalleryPage     page     = CreateEpisodeGalleryPage(metadata.ShowId);
                Application.Current.GoToGallery(page);
                break;
            }


            default:
                Debug.WriteLine(String.Format("DetailsAction: {0}({1}): NOT YET IMPLEMENTED", actionType, value));
                break;
            }
        }
 public Filter(GalleryPage page, string description, int id)
     : base(page, description)
 {
     filterId = id;
 }