// This file shows the calls necessary to efficiently build
// a clip cache. The steps are broken up into two sections:
// 1. Getting an initial view of all files in a bin.
// 2. Getting all future clip changes.
using System;
using System.Net; // needed for DNS.GetHostName call
using System.Threading;
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;
///
/// This is a sample CS-Script app for controlling the Grass Valley K2 server.
/// The code is regular C# code, but it's written for CS-Script which can
/// run it as a script from a DOS command prompt.
///
/// Go to the K2 AppServer Developer's Guide for more information:
/// http://www.gvgdevelopers.com/K2DevGuide/K2DevGuide.html#%5B%5BCS-Script%20Sample%20Scripts%5D%5D
///
/// For more information about CS-Script go to:
/// http://www.members.optusnet.com.au/~olegshilo/
///
class K2Sample
{
[STAThread]
static void Main()
{
try
{
// setup variables
AppServerMgrProxy appServerMgrProxy = null;
string appName = Environment.GetCommandLineArgs()[0];
string suiteName = appName + "_" + System.Guid.NewGuid().ToString("N");
string userName = "";
string password = "";
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);
////////////////////////////////////////////////////////////////
// STEP 1: Get all information about the clips in a bin.
// Use these calls for building up your clip cache data model.
///////////////////////////////////////////////////////////////
Console.WriteLine("Get all asset data from bin V:\\default...\n");
// get a MediaMgr object for asset management
IMediaMgr mediaMgr = iappServer.CreateMediaMgr(appName);
// enumerate the assets in the v:\default bin. this returns a cookie and
// a count that represents the number of assets in the bin
// NOTE: EnumerateAssets is a very expensive call and should be used sparingly
// Abusing this call against bins with large numbers of clips could cause slows downs
// and/or unexpected behavior. Read link below for more information:
// http://www.gvgdevelopers.com/concrete/apis/appserver_api/examples/programming_tips/
int count = 0;
int cookie = mediaMgr.EnumerateAssets("V:", "default", ref count);
// when collecting the asset data, you should iterate thru the results
// in chunks. this prevents a call from blocking for a long time as it
// collects data for all assets. 512 assets is a good size to use. the
// code below loop continually in blocks of 512 assets until all data
// is retrieved.
int maxCount = 512;
int iteration = 0;
object dataObj = null;
// setup an array of property names. These are the properties you can get using
// GetResultProperty.
// See http://www.gvgdevelopers.com/K2DevGuide/K2DevGuide.html#%5B%5BAsset%20properties%5D%5D
// asset property descriptions.
string[] propertyName = {"uri", "name", "assettype", "created", "modified", "attributes1",
"attributes2", "videoformat", "videocompressiontype", "firsttimecodemask",
"lengthstr", "maxlength", "markin", "markout", "markinstr", "markoutstr",
"dropframe", "locked", "hidef" };
// setup a query of properties to get for each clip
string query = "uri+name+assettype+created+modified+attributes1+attributes2+videoformat+videocompressiontype+firsttimecodemask+lengthstr+maxlength+markin+markout+markinstr+markoutstr+dropframe+locked+hidef";
// loop thru all assets
count = maxCount;
while (count == maxCount)
{
// query the results for properties. do this for up to 512 clips at a time
mediaMgr.GetResultProperty( cookie, query, iteration * maxCount, maxCount, out count, out dataObj);
// we get back an array (clip) of arrays (clip properties).
// get the array of clips
object[] clipArray = (object[]) dataObj;
foreach (object clip in clipArray)
{
// get the array of properties for each clip
object[] propertyArray = (object[]) clip;
for (int k=0; k 0)
Console.WriteLine(xmlData);
Thread.Sleep(500);
}
// cleanup
mediaMgr.CloseResults(cookie);
mediaMgr.Dispose();
iappServer.CloseConnection();
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
}