Skip to content

Instantly share code, notes, and snippets.

@fdelponte
Last active June 15, 2016 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdelponte/e6e327636a3a4d0b1c05b59ae956600b to your computer and use it in GitHub Desktop.
Save fdelponte/e6e327636a3a4d0b1c05b59ae956600b to your computer and use it in GitHub Desktop.
Vidispine .NET clients - Check how to use them on Vidispine blog: http://howto.vidispine.com/insight/three-simple-methods-to-invoke-the-vidispine-api-from-net-code/
using System;
using System.IO;
using System.Net;
using System.Net.Http;
using Vidispine.VidiNET;
namespace Binagora.Vidispine.ConsoleTest
{
class Program
{
#region Private Constants
private const string address = "http://xxx.xxx.xxx.xxx:8080/API"; // Remeber to update the VS IP address.
private const string userName = "admin";
private const string password = "admin";
#endregion
#region Private Methods
private static string GetUsingWebRequest(string requestUri)
{
var request = (HttpWebRequest)WebRequest.Create(requestUri);
request.Credentials = new NetworkCredential(userName, password);
using(var response = (HttpWebResponse)request.GetResponse())
{
var stream = response.GetResponseStream();
var reader = new StreamReader(stream);
string result = reader.ReadToEnd();
return result;
}
}
private static string GetUsingHttpClient(string requestUri)
{
var handler = new HttpClientHandler()
{
Credentials = new NetworkCredential(userName, password)
};
var client = new HttpClient(handler);
client.BaseAddress = new Uri(address);
string message = client.GetStringAsync(requestUri).Result;
return message;
}
private static string GetUsingVidispineSdk()
{
var rootResource = new VidispineResource(address).Authenticate(userName, password);
var itemResource = rootResource.Item;
string result = itemResource.SearchPlainGET.Number(1).CallText();
return result;
}
private static void WriteMessage(string option, string message)
{
Console.ForegroundColor = ConsoleColor.Yellow;
Console.WriteLine(option);
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine(message);
}
private static void WriteTitle()
{
Console.ForegroundColor = ConsoleColor.Green;
Console.WriteLine("Invoking Vidispine...");
Console.ForegroundColor = ConsoleColor.Gray;
Console.WriteLine();
}
#endregion
#region Public Methods
static void Main(string[] args)
{
string requestUri = address + "/item;number=1";
string message = "";
WriteTitle();
message = GetUsingWebRequest(requestUri);
WriteMessage("Option #1: Using WebRequest class.", message);
message = GetUsingHttpClient(requestUri);
WriteMessage("Option #2: Using HtpClient class.", message);
message = GetUsingVidispineSdk();
WriteMessage("Option #3: Using Vidispine SDK.", message);
Console.WriteLine("Press [ENTER] to exit...");
Console.ReadLine();
}
#endregion
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment