Example #1
0
        /// <summary>
        /// Create a single episode details page command.
        /// </summary>
        private void CreateEpisodeDetailsCommand(DetailsPage page, string description, int type, string value, int itemId)
        {
            DetailsCommand command = new DetailsCommand(page, description);

            command.Type   = type;
            command.Value  = value;
            command.ItemId = itemId;

            // Hook up the event handler.  This handler will disambiguate
            // what the actual action that should occur based on the item's
            // action type.
            command.Invoked += delegate(object sender, EventArgs e)
            {
                OnEpisodeDetailsActionInvoked((DetailsCommand)sender);
            };

            page.Commands.Add(command);
        }
Example #2
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;
            }
        }
        /// <summary>
        /// Called when one of the custom actions on a details page is clicked.
        /// </summary>
        private void OnDetailsActionInvoked(DetailsCommand command)
        {
            MoviesDetailsActionType actionType = (MoviesDetailsActionType)command.Type;
            string value   = command.Value;
            int    movieId = command.ItemId;

            //
            // Interpret the action.
            //

            switch (actionType)
            {
            case MoviesDetailsActionType.Preview:
                //
                // Preview = Play the movie
                //

                string path = VideosDirectory + value;
                Debug.WriteLine(path);

                if (Application.Current.MediaCenterEnvironment != null)
                {
                    Application.Current.MediaCenterEnvironment.PlayMedia(Microsoft.MediaCenter.MediaType.Video, path, false);
                }
                else
                {
                    Debug.WriteLine("DetailsAction: Play " + path);
                }
                break;

            case MoviesDetailsActionType.Purchase:
                //
                // Purchase = Download the movie
                //

                // Only download if the item is not actively being downloaded
                //
                // FUTURE: Z should maintain a persisted list of all media items
                // downloaded;  that way, the end-user wouldn't end up buying and
                // downloading the same media item twice.
                // When implementing this, the UI for already downloaded items
                // should replace "purchase" with "play"

                bool alreadyDownloading = false;
                foreach (SearchResult item in ActiveDownloads)
                {
                    if (item.Id == movieId)
                    {
                        alreadyDownloading = true;
                        break;
                    }
                }
                if (!alreadyDownloading)
                {
                    DataRow movieData = GetMovieData(movieId);
                    string  title     = (string)movieData["Movie_Title"];

                    if (Application.Current.MediaCenterEnvironment != null)
                    {
                        //
                        // Display a dialog telling the user that download was started.
                        //

                        string dialogText = String.Format(Z.Resources.Movies_DownloadDialog_Text, title);

                        Application.Current.MessageBox(dialogText, Z.Resources.Movies_DownloadDialog_Caption);
                    }

                    // Create a search result for the movie that the
                    // Downloads page can use to show downloads
                    SearchResult item = CreateSearchResult(movieData);

                    // The source location was retrieved from the data table
                    // and stored in the Value property of the DetailsCommand
                    // that initiated this download.  Convert that to a Uri.
                    Uri source = new Uri(command.Value);

                    // Construct the destination path by appending the file
                    // name from the source onto the path for the Z
                    // subdirectory in the public videos folder
                    string[] segments = source.Segments;
                    string   fileName = segments[segments.Length - 1];

                    Debug.WriteLine("DetailsAction: Downloading " + movieId);
                }
                else
                {
                    Debug.WriteLine("DetailsAction: Already downloading " + movieId);
                }
                break;

            default:
                Debug.WriteLine(String.Format("DetailsAction: {0}({1}): NOT YET IMPLEMENTED", actionType, value));
                break;
            }
        }