using System; 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; // Leave the following "css_reference" lines in when running with CS-Script. They're // more than just comments - they tell CS-Script which DLLs to load if the DLL // name does not match the namespace that it implements. //css_reference Credentials.dll; //css_reference ServerUtil.dll; /// /// This sample shows how to play a live recording clip. The result /// a player playing within a 0.5 second of the record head position. /// Note: Playing in live mode only works if the asset is currently /// being recorded on a channel that is on the same Summit as the /// player channel. /// namespace K2Script { class Test { static int Main(string[] args) { try { // get the application's name string appName = Environment.GetCommandLineArgs()[0]; // if appName="cscs", use the next argument instead if (0 == appName.IndexOf("cscs")) appName = Environment.GetCommandLineArgs()[1]; // create a unique suite name string suiteName = appName + "_" + System.Guid.NewGuid().ToString("N"); // fill in these values for your connection (i.e. hardcode them, pass in // cmdline arguments, read from file, read from console, etc.) string host = "localhost"; string username = ""; string password = ""; string domain = ""; // Connect to host & pass in credentials. The "using" block disposes connection when done. using ( Connection connection = new Connection(appName, suiteName, host, username, password, domain) ) { // do work only if we have a valid connection if ( connection.IsConnected ) { // setup default volume & bin string volume = "V:"; string bin = "default"; // ask which recorder channel Console.Write("Which channel do you want to record on? [C1] "); string recordChannel = Console.ReadLine(); // if no input, default to C1 if (String.IsNullOrEmpty(recordChannel)) recordChannel = "C1"; // ask which player channel Console.Write("Which channel do you want to play on? [C2] "); string playerChannel = Console.ReadLine(); // if no input, default to C2 if (String.IsNullOrEmpty(recordChannel)) playerChannel = "C2"; // create a controller for the recorder bool isNewController = false; ISimpleController icontroller = connection.AppServer.CreateController( appName, recordChannel, out isNewController); // cast the controller to an ISimplePlayerRecorder interface. ISimplePlayerRecorder recorder = (ISimplePlayerRecorder) icontroller; recorder.SetCurrentBin(volume, bin); // create a controller for the player ISimpleController icontroller2 = connection.AppServer.CreateController( appName, playerChannel, out isNewController); // cast the controller to an ISimplePlayerRecorder interface. ISimplePlayerRecorder player = (ISimplePlayerRecorder) icontroller2; // create a media mgr for checking the asset's construction status below IMediaMgr mediaMgr = connection.AppServer.CreateMediaMgr(appName); // generate a new clip name string newclip = recorder.GenerateUniqueName("Clip", "_"); // create a URI for the clip string clipUri = String.Format("edl/cmf//local/{0}/{1}/{2}", volume, bin, newclip); // create a new clip to record recorder.New(newclip); // start recording recorder.Record(); // now wait until the clip says that it is under construction. // if you don't wait and you tell the player to go into live mode, // the player will cue to the start of the clip instead. you'll // also see this message in the log: // "Can't go live: not under construction. Cueing to 0." // wait until the clip is under construction... while ( true != (bool) mediaMgr.GetProperty(clipUri, "underConstruction") ) { Thread.Sleep(40); } // load the recording clip onto the player player.Load(clipUri); // Cue to the live position and start playing. in this case the command // name "cue" is a bit of a misnomer since this command does more than // just cueing here. it cues to the latest updated play position which // will be within a 0.5 second of the record position. // // note: playing live only works if the asset is currently being recorded // on a channel that is on the same Summit as the player channel. player.Cue("live"); // wait for a keypress from the user before continuing Console.WriteLine(Environment.NewLine + "press ENTER key to exit"); Console.ReadLine(); // stop the player player.Stop(); player.Eject(); // stop the recorder recorder.Stop(); recorder.Eject(); // close the player channel icontroller2.CloseChannel(); // close the recorder channel icontroller.CloseChannel(); } } } catch (SystemException se) { Console.WriteLine(se); } return 0; } } // Connection helper class: sets up credentials & hostname, connects to K2 public class Connection: IDisposable { private bool _connected = false; private AppServerMgrProxy _appServerMgrProxy = null; private IAppServer _appServer = null; /// /// Object that connects to the specified K2 credentials /// /// The application's name. /// The suite's name. /// The K2's host name. /// The username. /// The password. /// The domain. public Connection(string appname, string suitename, string host, string username, string password, string domain) { try { ////////////////////////// // SETUP ////////////////////////// if ( null == host || host.Length == 0) { Console.WriteLine("Empty host name passed to Connection object."); return; } ////////////////////////// // CONNECT TO K2 ////////////////////////// // create an AppServerMgr proxy object _appServerMgrProxy = new AppServerMgrProxy(); // tell it which K2 we're connecting to _appServerMgrProxy.SetHost(host); // give it the user credentials we want to use if ( username.Length > 0 ) _appServerMgrProxy.SetUserCredentials(username, password, domain, false); // connect to the K2's AppServerMgr if ( !_appServerMgrProxy.Connect() ) { // if the connection failed, report an error and exit Console.WriteLine("ERROR: Could not connect to AppService on host '" + host + "'. Check the host name."); _appServerMgrProxy = null; return; } // if we got here we're connected to K2 AppService ////////////////////////// // CREATE AN APPSERVER ////////////////////////// // now create an AppServer bool newConnection = false; _appServer = _appServerMgrProxy.CreateAppServer(suitename, appname, out newConnection); _connected = true; } catch (SystemException se) { Console.WriteLine(se); } } /// /// Gets a value indicating whether this instance is connected. /// /// /// true if this instance is connected; otherwise, false. /// public bool IsConnected { get { return _connected; } } /// /// Gets the AppServerMgr. /// /// The AppServerMgr public AppServerMgrProxy AppServerMgr { get { if ( _appServerMgrProxy == null ) Console.WriteLine("WARNING: AppServerMgrProxy object == null!"); return _appServerMgrProxy; } } /// /// Gets the AppServer /// /// The AppServer public IAppServer AppServer { get { if ( _appServerMgrProxy == null ) Console.WriteLine("WARNING: AppServerProxy object == null!"); return _appServer; } } /// /// Disposes this instance. /// public void Dispose() { if ( _appServer != null ) _appServer.CloseConnection(); } } }