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 some variables AppServerMgrProxy appServerMgrProxy = null; string appName = Environment.GetCommandLineArgs()[0]; string suiteName = appName + "_" + System.Guid.NewGuid().ToString("N"); string userName = ""; string password = ""; string domain = ""; string volume = "V:"; string bin = "default"; string playlist = "playlist"; string clipUri = @"edl\cmf\\local\" + volume + "\\" + bin + "\\" + playlist; // 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 appServer = appServerMgrProxy.CreateAppServer(suiteName, appName, out newConnection); Console.Write("Which channel? [C1] "); string channel = Console.ReadLine(); if (null == channel || 0 == channel.Length) channel = "C1"; // create a two-head player recorder bool isNewController = false; ITwoHeadPlayerRecorder player = (ITwoHeadPlayerRecorder) appServer.CreateController( appName, channel, out isNewController); // set loop play mode to false player.LoopPlayMode = false; // enable list pauses in case play app disables it (see config.xml) player.SetChannelProperty("listpauses", "true"); // enable list repeats in case play app disables it (see config.xml) player.SetChannelProperty("listrepeats", "true"); // set current bin player.SetCurrentBin(volume, bin); // generate a unique name for the playlist playlist = player.GenerateUniqueName (playlist, "_"); // eject the play first to make sure we're clean player.Eject(); // create the new playlist (which also loads it) player.New(playlist); // get an event editor IEventEditor editor = (IEventEditor) player.GetEditor(); // insert the first section string section1 = editor.InsertSection(""); // set the starting timecode editor.SetStartingTimecode("01:00:00,00"); // insert several play events and get properties back string editID_A = editor.InsertPlayEvent(@"edl/cmf//local/V:/default/ClipA", section1, 0, ""); object[] array = (object[]) editor.GetEventProperty (editID_A, "name+startpos+duration"); // your code to do something with event properties string editID_B = editor.InsertPlayEvent(@"edl/cmf//local/V:/default/ClipB", section1, 0, ""); array = (object[]) editor.GetEventProperty (editID_B, "name+startpos+duration"); // your code to do something with event properties // insert another section string section2 = editor.InsertSection(""); // insert several more play events and get properties back string editID_C = editor.InsertPlayEvent(@"edl/cmf//local/V:/default/ClipC", section2, 0, ""); array = (object[]) editor.GetEventProperty (editID_C, "name+startpos+duration"); // your code to do something with event properties string editID_D = editor.InsertPlayEvent(@"edl/cmf//local/V:/default/ClipD", section2, 0, ""); array = (object[]) editor.GetEventProperty (editID_D, "name+startpos+duration"); // your code to do something with event properties // play the list for awhile player.Play(); Thread.Sleep(30000); player.Stop(); // delete events editor.DeleteEvent(editID_C); editor.DeleteEvent(editID_D); // delete section 2 editor.DeleteSection(section2); // note: you cannot delete all sections. Since this is a playlist // it will force you to keep at least one section in it. // editor.DeleteSection(section2); // this would error // eject the clip player.Eject(); // close the channel player.CloseChannel(); // cleanup editor.Detach(); // close AppServer appServer.CloseConnection(); } catch (Exception e) { Console.WriteLine(e); } } }