I’m working on a csharp app we have that interacts with the Kaltura API. Adapting it from CE 5 to Kaltura 12. It seems much has changed in the way the client library works, however, the code examples in the Developer section seem to not mimic what I’m seeing in Visual Studio.
For example, the code examples for a simple Media list look like this. This looks pretty much the same as it did in CE 5
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace Kaltura{
class CodeExample{
static void Main(string[] args){
KalturaConfiguration config = new KalturaConfiguration(partnerId);
config.ServiceUrl = "http://kaltura-prod.intranet.hdr/";
KalturaClient client = new KalturaClient(config);
KalturaMediaEntryFilter filter = null;
KalturaFilterPager pager = null;
Object result = client.MediaService.List(filter, pager);
}
}
}
However, in the code examples provided with the new client library, this may look something like this.
On a related note, this doesn’t actually do what I want it too. The videos object is not populated as I would expect it to be, which leads me to believe there is something wrong with my client library, how I’m using it, or both. There seems to be no exception generated either. I haven’t checked the log files on the server end yet.
InitClient is another function that seems to be working fine. I get what looks like a valid KS
Client client;
client = InitClient();
List<string> videoIds = new List<string>();
List<MediaEntry> results = new List<MediaEntry>();
List<MediaEntry> resultsTemp = new List<MediaEntry>();
FilterPager pager = new FilterPager();
MediaEntryFilter filter = new MediaEntryFilter();
pager.PageSize = 500;
ListResponse<MediaEntry> videos = new ListResponse<MediaEntry>();
//get a count of videos
MediaListRequestBuilder countrequest = MediaService.List(filter, pager);
APIException error = null;
countrequest.OnComplete(videos,error);
countrequest.Execute(client);
int videocount = videos.Objects.Count();
The C# client should work correctly against CE 12 but it’s always best to generate the client on your own server with:
# php /opt/kaltura/app/generator/generate.php csharp
The client includes some tests too and these can be used as reference. Take a look at /opt/kaltura/web/content/clientlibs/csharp/KalturaClientTester/ClientTester.cs as a start point.
If you’re still having issues, please paste your full code snippet as well as a link to the client you generated and I’ll gladly take a look.
I indeed am using a client library generated from the Kaltura 12 install so no worries there. I guess I was confused because if you log into the admin_console, go to the developer tab and click on Show Code Examples, they’re not consistent with the client library.
In any event, here is a test application I wrote that should be pretty straight forward.
I’ve done some logging where I can see the request going out and coming back with the correct media list, but I think perhaps my use of the Client library isn’t correct.
I see in the Client Tester app delegate style functions are used extensively in processing the responses to the requests. This doesn’t really fit the pattern by which my app is written, so I would like to avoid them if possible.
The client you are using complies with the examples from developer.kaltura.com [it’s basically the same version].
I realise the fact the code sample generator in Admin Console’s testMe was not updated accordingly is confusing, we’re working on that.
Below is a full example of a modified Program.cs that calls MediaService.List() and iterates over the results.
Note that this C# client is thread safe and makes async HTTPs requests.
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Kaltura;
using Kaltura.Enums;
using Kaltura.Types;
using Kaltura.Request;
using Kaltura.Services;
using System.Threading;
namespace Kaltura {
class Program {
static void Main(string[] args) {
Client client = Program.createKalturaClient();
bool done = false;
MediaEntryFilter filter = new MediaEntryFilter();
filter.OrderBy = MediaEntryOrderBy.WEIGHT_DESC;
FilterPager pager = new FilterPager();
OnCompletedHandler<ListResponse<MediaEntry>> handler = new OnCompletedHandler<ListResponse<MediaEntry>>(
(ListResponse<MediaEntry> result, Exception e) =>
{
foreach (MediaEntry entry in result.Objects)
{
Program.PrintObject(entry);
}
done = true;
});
MediaService.List(filter, pager)
.SetCompletion(handler)
.Execute(client);
while (!done) {
Thread.Sleep(100);
}
}
static Client createKalturaClient() {
Configuration config = new Configuration();
config.ServiceUrl = "https://www.kaltura.com/";
Client client = new Client(config);
int partnerId = ;
string secret = "";
string userId = "";
SessionType type = SessionType.ADMIN;
int expiry = 86400;
string privileges = "";
client.KS = client.GenerateSession(partnerId, secret, userId, type, expiry, privileges);
return client;
}
public static void PrintObject<T>(T obj) {
var t = typeof(T);
var props = t.GetProperties();
StringBuilder sb = new StringBuilder();
foreach (var item in props)
{
try {
sb.Append(item.Name+ ": " +item.GetValue(obj,null)+"\n");
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
}
}
sb.AppendLine();
Console.WriteLine(sb.ToString());
}
}
}
Yes, this does help. Essentially I was looking to verify that the c# client library had indeed gone mostly async. The previous version did not work in this manner.
As it is right now, my application is more synchronous in nature. Thus meshing the two is going to take some adaption on the part of my application, perhaps.