grass valley developers

Home > APIs > Event Scheduler API > Event Scheduler Developers Page > Working with the Event and Change Notice XML Structures

 

Introduction

Event Scheduler uses xml to describe events and change notices.

 

You can create, update, and poll information on events using the xml. Using the same xml schema, you can use the GetListXml() function to get back the entire list of events for that entire K2 Summit channel. For an example of an event's xml, click here. For an example of an event lists xml, click here.

 

Change notices provide feedback on list changes and event changes, so that you can keep your event list sync'd up with the K2 client's list, without querying the entire list repeatedly. For an example of a change notice xml, click here.

 

While writing test code for the Event Scheduler interface, we needed to be able to work quickly and efficiently with the Event and Notices XML. We used the Micosoft XSD tool to create a class that would allow us to easily serialize and deserialize the xml to and from objects that are easy to work with in our tests. We also added some helper functions in the class for our testing. You're welcome to use this example and the helper classes themselves, to help you get started with Event Scheduler.

EventInfo.cs

XMLNotices.cs

 

 

1. Retrieving A List

Using EventInfo.cs, the entire event list can be easily enumerated and stored in the EventList object below. Assuming we have a connection to a K2 and have gotten a IScheduleEditor object from the controller class (called 'connection' in the examples below), we can quickly make this call. (For more details on setting up a connection, refer to the API document.)

 

EventList obj = new EventList(connection.GetListXml());

 

The Event Scheduler GetListXml() function returns the XML, the contructor for the EventList class takes the xml and stores it in the EventList object, which can then be easily enumerated.

 

if (obj.Items != null)
{
    for (int i = 0; i < obj.Items.Length; i++)
    {
        string clipname = obj.Items[i].EventData[0].strUri;
        string startTime = obj.Items[i].EventData[0].startTime;
        string duration = obj.Items[i].EventData[0].duration;
        Console.WriteLine(clipname + " - " + startTime + " - " + duration);
    }
}

 

2. Inserting An Event

The above example "Retrieving a List" is not very exciting if there is no events in the list. So let's insert an event using the EventInfo helper class. We'll use it to build an event, then pass xml to the CreateEventFromXml() function call.

First, we create a new EventList. Since we are simply inserting one event in this example, well call the object 'item' and we will create an EventList that only has 1 event.

 

EventList item = new EventList(1);

 

Next, lets fill in the neccessary information to insert the event. In fact, let's create a helper function called GetBasicEvent() to help us with further examples. It has one parameter called secondsTillExecute that will be a easy way to insert an event that will execute a few seconds in the future.

 

 

public EventList GetBasicEvent(int secondsTillExecute)
{
    Thread.CurrentThread.CurrentCulture = new CultureInfo("es-ES");

    EventList item = new EventList(1);
    item.Items[0].EventData.SetValue(new EventInfoEventData(), 0);
    item.Items[0].EventData[0].strUri = "edl/cmf//localhost/V:/default/#21";
    item.Items[0].EventData[0].trigger = "Absolute";
    item.Items[0].EventData[0].eventType = "Play";
    item.Items[0].EventData[0].startDate = string.Format("{0}-{1:00}-{2:00}",
    DateTime.Now.AddSeconds(secondsTillExecute).Year, DateTime.Now.AddSeconds(secondsTillExecute).Month, DateTime.Now.AddSeconds(secondsTillExecute).Day);
    string time = (string)Controller2.GetStatus("timeofdaystr");
    DateTime start = Convert.ToDateTime(time.Substring(0, 8));
    item.Items[0].EventData[0].startTime = start.AddSeconds(secondsTillExecute).ToString("HH:mm:ss:00", CultureInfo.InvariantCulture);
    item.Items[0].EventData[0].duration = "00:00:10:00";
    item.Items[0].EventData[0].purgeDate = string.Format("{0}-{1:00}-{2:00}",
                DateTime.Now.AddDays(1).Year, DateTime.Now.AddDays(1).Month, DateTime.Now.AddDays(1).Day);
     item.Items[0].EventData[0].purgeTime = "00:00:00:00";
     item.Items[0].EventData[0].purgeCount = "0";
     item.Items[0].EventData[0].channel = "0";
     item.Items[0].EventData[0].repeatMode = "None";
     item.Items[0].EventData[0].childUuid = string.Empty;
     item.Items[0].EventData[0].parentUuid = string.Empty;
     item.Items[0].PlayEventData[0].markIn = "00:00:00:00";
     item.Items[0].PlayEventData[0].isMarkInAbs = "FALSE";

     return item;
}

 

Let's now use our helper function to insert an event using a EventList object.

string bstrAfterEventId = string.Empty;
EventList item = _setup.GetBasicEvent(30); //get an event to start 30 seconds from now.
string eventId = connection.CreateEventFromXml(eventXml, bstrAfterEventId);

 

As you can see, it's pretty simple to add an event, once you fill in all the appropriate fields in the EventXml structure.

 

 

3. Getting Details of a Single Event

Once an event is added, you can simply call GetEventXml() to retrieve the properties of the event again. As the event executes, you may want to update the event properties to get status information. And again, we simply store take the event XML returned from GetEventXML() and pass it into the constructor for EventList.

 

EventList obj = new EventList(connection.GetEventXml(eventId));

 

 

4. XML Change Notices

The Event Scheduler interface has a function called GetXmlChanges() which returns a list of changes to the list. A client application can make this call periodically to sync there list, and all events status with the K2 Summit Client. The function simply has two parameters, a maximum number of notices to be returned (we recomend 100) and a 'ref' parameter which returns the number of notices actually returned. 

Assuming an event was just inserted, had just played, or had been deleted, you will get back some xml change notices. 

const int lMaxCount = 100;
int pCount = 0;
string returnedXml = connection.GetXmlChanges(lMaxCount, ref pCount);

 

To work with the returned xml, we use the XMLNotices class. In this example, if a client application detected that an event had been instered, such as the event id's that we print with the "Console.WriteLine", the client application could then turn around and call GetEventXml() on that event id, to update the it's list of events.

 

int count = 0;
const int lMaxCount = 100;
XmlNotices notices;

notices = new XmlNotices(connection.GetXmlChanges(lMaxCount, ref count));

if (notices.Items != null)
{
    for (int i = 0; i < count; i++)
    {
          if (notices.Items[i] != null && (notices.Items[i].GetType() == typeof(NoticeType))
                            && ((NoticeType)notices.Items[i]).EventType == "NoticeInsertEvent")
          {
                            Console.WriteLine(((NoticeType)notices.Items[i]).eventid);
          }
    }
}