using System; using System.Net; // needed for DNS.GetHostName call using System.Runtime.InteropServices; // DllImport() 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 viewmovie { [DllImport("kernel32.dll")] public static extern bool SetConsoleTextAttribute(IntPtr hConsoleOutput, int wAttributes); [DllImport("kernel32.dll")] public static extern IntPtr GetStdHandle(uint nStdHandle); static uint STD_OUTPUT_HANDLE = 0xfffffff5; static IntPtr hConsole = GetStdHandle(STD_OUTPUT_HANDLE); static void Usage() { SetConsoleTextAttribute(hConsole, 0x000F); // bright white Console.WriteLine("Usage:"); SetConsoleTextAttribute(hConsole, 0x0007); // bright white Console.WriteLine("viewmovie complexMovieName : shows movie attributes"); Console.WriteLine("viewmovie -h hostname complexMovieName : shows movie attributes on "); Console.WriteLine("viewmovie : prompts for clip and host"); Console.WriteLine("viewmovie ? : prints this message"); Console.WriteLine("viewmovie help : prints this message"); Console.WriteLine("viewmovie usage : prints this message"); Console.WriteLine(""); SetConsoleTextAttribute(hConsole, 0x000F); // bright white Console.WriteLine("Examples:"); SetConsoleTextAttribute(hConsole, 0x0007); // regular white Console.WriteLine("viewmovie"); Console.WriteLine("viewmovie Clip"); Console.WriteLine("viewmovie V:/default/Clip"); Console.WriteLine("viewmovie -h MX-123 V:/default/Clip"); } [STAThread] static void Main(string[] args) { // 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 host = ""; // default to connect to this machine string clipname = ""; try { // bounds check if (args.Length > 3) { Usage(); return; } // check for help flags if ( args.Length >= 1 && ( 0 == String.Compare(args[0], @"?", true) || 0 == String.Compare(args[0], @"-?", true) || 0 == String.Compare(args[0], @"/?", true) || 0 == String.Compare(args[0], @"help", true) || 0 == String.Compare(args[0], @"-help", true) || 0 == String.Compare(args[0], @"--help", true) || 0 == String.Compare(args[0], @"usage", true) ) ) { Usage(); return; } // check if clipname passed in if ( args.Length == 1 ) { if ( 0 == String.Compare(args[0], "-h", true) ) { Usage(); return; } else clipname = args[0]; } // check if host passed in with "-h" options else if ( args.Length == 2 ) { if ( 0 == String.Compare(args[0], "-h", true) ) host = args[1]; else { Usage(); return; } } // check if host and clipname passed in else if ( args.Length == 3 ) { // check for "-h " if ( 0 == String.Compare(args[0], "-h", true) ) { host = args[1]; clipname = args[2]; } // check for " -h " else if ( 0 == String.Compare(args[1], "-h", true) ) { host = args[2]; clipname = args[0]; } else { Usage(); return; } } // if no host was passed on the command-line, verify which machine to connect to if ( host.Length == 0 ) { string defaulthost = Dns.GetHostName(); Console.Write("Connect to AppService on which system? [" + defaulthost + "]: "); host = Console.ReadLine(); if (null == host || 0 == host.Length) host = defaulthost; } // 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; SetConsoleTextAttribute(hConsole, 0x000C); // bright red Console.Write("ERROR:"); SetConsoleTextAttribute(hConsole, 0x0007); // white Console.Write(" Could not connect to AppService on host "); SetConsoleTextAttribute(hConsole, 0x000E); // bright yellow Console.Write(host); SetConsoleTextAttribute(hConsole, 0x0007); // white Console.WriteLine("."); Console.WriteLine("Double-check the host name."); return; } else Console.WriteLine("Successfully connected to AppService."); bool newConnection = false; IAppServer iappServer = appServerMgrProxy.CreateAppServer(suiteName, appName, out newConnection); // get a media mgr IMediaMgr mediaMgr = iappServer.CreateMediaMgr(appName); // use passed in clipname or ask for one if ( clipname.Length == 0 ) { // which clip? Console.Write("Which clip? [V:/default/Clip]: "); clipname = Console.ReadLine(); if ( 0 == clipname.Length ) clipname = "V:/default/Clip"; } // if clipname was passed in without dataset and bin, // use the default dataset and bin if ( -1 == clipname.IndexOf(@"/") && -1 == clipname.IndexOf(@"\") ) { string dataset = ""; string bin = ""; mediaMgr.GetCurrentBin(ref dataset, ref bin); SetConsoleTextAttribute(hConsole, 0x000F); // bright white Console.WriteLine("No bin specified for clip. Using current bin: \"{0}/{1}\"", dataset, bin); SetConsoleTextAttribute(hConsole, 0x0007); // regular white clipname = dataset + @"/" + bin + @"/" + clipname; } clipname = "edl/cmf//local/" + clipname; // first check if asset exists if ( !mediaMgr.AssetExists(clipname) ) { Console.WriteLine(); SetConsoleTextAttribute(hConsole, 0x000C); // bright red Console.Write("ERROR:"); SetConsoleTextAttribute(hConsole, 0x000E); // bright yellow Console.Write(" \"{0}\"", clipname); SetConsoleTextAttribute(hConsole, 0x0007); // regular white Console.Write(" does not exist on host "); SetConsoleTextAttribute(hConsole, 0x000E); // bright yellow Console.Write(host); SetConsoleTextAttribute(hConsole, 0x0007); // regular white Console.WriteLine("."); Console.WriteLine("Double-check the clip name and host name."); SetConsoleTextAttribute(hConsole, 0x0007); // regular white return; } // print clip summary string ViewMovieSummary = (string) mediaMgr.GetProperty(clipname, "summary"); Console.WriteLine(ViewMovieSummary); // cleanup mediaMgr.Dispose(); iappServer.CloseConnection(); } catch (Exception e) { SetConsoleTextAttribute(hConsole, 0x000C); // bright red Console.Write("ERROR:"); SetConsoleTextAttribute(hConsole, 0x000E); // bright yellow Console.Write(" Exception caught trying to view "); Console.WriteLine("clip \"{0}\" on host \"{1}\"", clipname, host); SetConsoleTextAttribute(hConsole, 0x0007); // regular white Console.WriteLine(); Console.WriteLine(e); } } }