Share via


Creating a Click-To-Record Request with the CreateScheduleRequest Method

The following attributes can be used when creating the XML request using the EventSchedule.CreateScheduleRequest method.

Note   Only the EventSchedule.CreateScheduleRequest method can correctly interpret these features of the input XML file. The deprecated ClickToRecord.Submit method for managed code, the MediaCenter.ScheduleRecording method for hosted HTML, and invoking the click-to-record feature from the Windows shell cannot accept this XML and may simply ignore these features.

  • The service element inside the key element can specify the service ID of the expecting service:

    <key field="urn:schemas-microsoft-com:ehome:epg:service#id">
    

    You can also specify a call sign (service#callsign), which is a string that is displayed in the EPG page in Windows Media Center. In some countries or regions, the service name is displayed in this field rather than an official call sign, or the service name may be left blank.

  • The keepUntil attribute of the programRecord element specifies how long to keep the recorded files. The following values are possible (if no value is specified, the computer's default value is used):

    -3: Latest recordings

    -2: Keep until I watch

    -1: Keep until space needed

    0: Keep until I delete

  • The quality attribute of the programRecord element specifies the quality of recording. The following values are possible (if no value is specified, the computer's default value is used):

    0: Fair

    1: Good

    2: Better

    3: Best

Example Code

// Example of Microsoft.MediaCenter.TV.Scheduling.EventSchedule.CreateScheduleRequest method.
// Create a recording request from "example.xml".

using Microsoft.MediaCenter.TV.Scheduling;
using System.IO;
using System.Collections.Generic;
using System.Xml;
using System;

namespace Microsoft.MediaCenter.TV.Scheduling.Example {

    public class ExampleClass {
        
        public static void Main()
        {           
            // Open XML file
            FileStream fsXml;
            XmlReader readerXml;
            try 
            {
                fsXml = new FileStream("example.xml", FileMode.Open, FileAccess.Read);
                readerXml = XmlReader.Create(fsXml);
            }
            catch (Exception e) 
            {
                Console.WriteLine("example.xml could not be read");
                Console.WriteLine(e.Message);
                return;
            }

            // Create EventSchedule object and create ScheduleRequest from XML.
            EventSchedule scheduler;
            ScheduleRequest request = null;
            CreateScheduleRequestResult result;
            try 
            {
                scheduler = new EventSchedule();
                result = scheduler.CreateScheduleRequest(readerXml, ConflictResolutionPolicy.AllowConflict, "example", out request);
                Console.WriteLine("Result: " + result.ToString());
            }
            catch (Exception e) 
            {
                Console.WriteLine("Exception from EventSchedule.CreateScheduleRequest()");
                Console.WriteLine(e.Message);
            }
            
            // Close the XML file.
            readerXml.Close();
            fsXml.Close();
            
            // Print the information about created ScheduleRequest.
            if (request != null)
            {
                try
                {
                    // ID of created ScheduleRequest.
                    Console.WriteLine("ScheduleRequest Id=" + request.Id);
                        
                    // ScheduleEvent(s) included in this ScheduleRequest.
                    ICollection<ScheduleEvent> events = request.GetScheduleEvents();
                    foreach (ScheduleEvent se in events)
                    {
                        Console.WriteLine("ScheduleEvent Id=" + se.Id);
                    }
                }
                catch (Exception e) 
                {
                    Console.WriteLine("Exception when getting ScheduleRequest information");
                    Console.WriteLine(e.Message);
                }                
            }
        }
    }
}

The following XML example specifies a manual one-time recording of channel 4 from 11:00 A.M. to 11:30 A.M. on May 15, 2006 (in UTC + 9 hours time zone).

<?xml version="1.0" encoding="utf-8" ?> 
<clickToRecord xmlns="urn:schemas-microsoft-com:ehome:clicktorecord">
    <body>
        <programRecord programDuration="30">
            <service>
                <key field="urn:schemas-microsoft-com:ehome:epg:service#mappedChannelNumber" match="exact">4</key>
            </service>
            <airing>
                <key field="urn:schemas-microsoft-com:ehome:epg:airing#starttime">2006-05-15T11:00:00+09:00</key>
            </airing>
        </programRecord>
    </body>
</clickToRecord>

See Also