/// /// This is a sample C# app for controlling the Grass Valley K2 server. /// You can test it by running it with the runtime C# scripting host /// CS-Script as follows: /// /// cscs /// /// This will start and run the sample code in a runtime environment. /// The code is true C# rather than a scripting language. /// /// For more information about CS-Script go to: /// http://www.members.optusnet.com.au/~olegshilo/ /// using System; using System.Net; // needed for DNS.GetHostName call using System.Xml; // needed for creating XmlDocument using GrassValley.Mseries.AppServer; using GrassValley.Mseries.AppServerLog; using GrassValley.Mseries.ChanStatus; using GrassValley.Mseries.ConfigMgr; using GrassValley.Mseries.Control; using GrassValley.Mseries.DVCapture; using GrassValley.Mseries.Editor; using GrassValley.Mseries.MediaMgr; using GrassValley.Mseries.Security; using GrassValley.Mseries.Status; using GrassValley.Mseries.TransferQueue; // next lines needed only for running with CS-Script //css_reference Credentials.dll; //css_reference ServerUtil.dll; class K2Sample { [STAThread] static void Main() { try { // setup some variables AppServerMgrProxy appServerMgrProxy = null; string appName = Environment.GetCommandLineArgs()[0]; string suiteName = appName + "_" + System.Guid.NewGuid().ToString("N"); string userName = "Administrator"; string password = "adminK2"; string domain = ""; // which K2 should we connect to? Console.Write("Connect to AppService on which system? [" + Dns.GetHostName() + "]: "); string host = Console.ReadLine(); if (null == host || 0 == host.Length) host = Dns.GetHostName(); // create an AppServerMgr proxy object appServerMgrProxy = new AppServerMgrProxy(); // set the host name of the K2 server appServerMgrProxy.SetHost(host); // pass the credentials info appServerMgrProxy.SetUserCredentials(userName, password, domain, false); // connect to the AppServerMgr if ( !appServerMgrProxy.Connect() ) { appServerMgrProxy = null; Console.WriteLine("ERROR: Could not connect to AppService on " + host + "."); return; } string clipname = "V:/default/Clip"; string fullclipname = "edl/cmf//local/" + clipname; // create an AppServer bool newConnection = false; IAppServer iappServer = appServerMgrProxy.CreateAppServer(suiteName, appName, out newConnection); // get an editor for clip IMediaMgr mediaMgr = iappServer.CreateMediaMgr(appName); ITrackEditor trackEditor = (ITrackEditor) mediaMgr.CreateEditor(fullclipname); // get the clip's XML representation string xml; trackEditor.GetXml("", out xml); // load the xml string into a native XmlDocument XmlDocument xmlDoc = new XmlDocument(); xmlDoc.LoadXml(xml); // setup a namespace manager to parse the xml doc XmlNamespaceManager namespaceManager = new XmlNamespaceManager(xmlDoc.NameTable); namespaceManager.AddNamespace("ns", "PdrDB__1.0"); //////////////////////////////////////// // set track labels //////////////////////////////////////// // get all audio track nodes XmlNodeList trackList = xmlDoc.SelectNodes(("//ns:XML/ns:Data/ns:Movie/ns:Track[@TrackType='PdrAudioTrack']"), namespaceManager); // and set their track labels foreach (XmlNode track in trackList) { // get track number, ID, and label int trackNumber = Int32.Parse(track.Attributes.GetNamedItem("TrackNumber").Value); // track position like 1, 2, 3, 4 string trackId = track.Attributes.GetNamedItem("TrackId").Value; // GUID id like b7d4e12e8350425bbaa4eb16236fb0e0 // if first or second tracks, set label to English if (trackNumber == 1 || trackNumber == 2) trackEditor.SetTrackLabel(trackId, "ENG"); // if third or fourth tracks, set label to something else else if (trackNumber == 3 || trackNumber == 4) trackEditor.SetTrackLabel(trackId, "something else"); } //////////////////////////////////////// // get track labels //////////////////////////////////////// // Make sure you call GetXml again to get the *updated* XML. Load the XML document again. trackEditor.GetXml("", out xml); xmlDoc.LoadXml(xml); // get all audio track nodes trackList = xmlDoc.SelectNodes(("//ns:XML/ns:Data/ns:Movie/ns:Track[@TrackType='PdrAudioTrack']"), namespaceManager); // and print them foreach (XmlNode track in trackList) { // get track number, ID, and label int trackNumber = Int32.Parse(track.Attributes.GetNamedItem("TrackNumber").Value); // track position like 1, 2, 3, 4 string trackLabel = track.Attributes.GetNamedItem("TrackLabel").Value; // label like "ENG", "FRE", or anything you assign Console.WriteLine("track number: {0}, track label: {1}", trackNumber, trackLabel ); } // be sure to cleanup or you will leak these objects! trackEditor.Detach(); trackEditor.Dispose(); mediaMgr.Dispose(); iappServer.CloseConnection(); } catch (SystemException se) { Console.WriteLine(se); } } }