///
/// 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.csscript.net/
///
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
{
// define the clip that we're going to inspect.
string clipname = "V:/default/Clip";
string fullclipname = "edl/cmf//local/" + clipname;
// 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;
}
// 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);
// NOTE: an example XML file is listed in comments at the bottom of this file for reference.
// Uncomment this line if you want to look at the XML representation of a clip.
// Console.WriteLine(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");
// get media segment nodes - notice this is filtering for track = "1", filetype = "FileTypeAudio".
// check the XML above to determine what you want to filter on...
XmlNodeList mediaSegmentList = xmlDoc.SelectNodes(("//ns:XML/ns:Data/ns:Movie/ns:Track[@TrackNumber='1']/ns:Segment/ns:MediaSegment[@FileType='FileTypeAudio']"), namespaceManager);
// this is a good sanity check to see the number of nodes returned
// Console.WriteLine("count = " + mediaSegmentList.Count);
foreach (XmlNode mediaSegment in mediaSegmentList)
{
// the clip's media segment filename
string fileName = mediaSegment.Attributes.GetNamedItem("FileName").Value;
Console.WriteLine(fileName);
// how to get an integer attribute value
// int sampleRate = Int32.Parse(mediaSegment.Attributes.GetNamedItem("SampleRate").Value); // sample rate like 4800
// Console.WriteLine("sample rate = " + sampleRate);
}
// be sure to cleanup or you will leak these objects!
trackEditor.Detach();
trackEditor.Dispose();
mediaMgr.Dispose();
iappServer.CloseConnection();
}
catch (SystemException se)
{
Console.WriteLine(se);
}
}
}
/*
Sample Clip XML file for reference
*/