Posted on

Today Microsoft released version 3.0.0.2  of Windows Azure Media Services .NET SDK which is hosted in nuget.org  MediaServicesCredentials mediaServicesCredentials = new MediaServicesCredentials("myaccount", "mykey"); CloudMediaContext cntx = new CloudMediaContext(mediaServicesCredentials); //At this point token is null since no request issued to ACS yet string token = mediaServicesCredentials.AccessToken; //We are sending Request to ACS and Detecting endpoint only when we first time accessing our entities from collections var asset = cntx.Assets.FirstOrDefault(); DateTime exprires = mediaServicesCredentials.TokenExpiration; //You can save token to cache and reassign it later in order to avoid request to ACS //Example: // MediaServicesCredentials mediaServicesCredentials = new MediaServicesCredentials("myaccount", "mykey"); // mediaServicesCredentials.AccessToken == token; //You can also force token Refresh earlier. Please note that refresh happen automatically if token has been expired mediaServicesCredentials.RefreshToken();

 

As you can see from example above newly added constructor allows you to create credential object and have direct access to acs token value and it’s expiration. Once you get these values in session memory or distributed db you will be able to use it in order to recreate MediaServicesCredentials and CloudMediaContext in multiple threads without hitting ACS over and over again. Please note that you need to provide account name and key since these values are used in order to refresh token once it will be expired.

Using OrderBy in LINQ statements

In  3.0.0.2 we fixed issues related to usage of  LINQ queries with OrderBy statements:

Example:

  var asset1 = _mediaContext
                .Assets
                .OrderByDescending(c => c.Created)
                .Where(a => a.Name.Length > 1)
                .Skip(10)
                .Take(5)
                .First();

            var asset2 = _mediaContext
                .Assets
                .Where(a => a.Name.Length > 1)
                .Skip(10)
                .Take(5)
                .First();

            var asset3 = _mediaContext
                .Assets
                .Where(a => a.Name.Length > 1)
                .OrderByDescending(c => c.Created)
                .Skip(10)
                .Take(5)
                .First();

 

For those who forking and running tests

As you might know all WAMS SDK code is hosted in github at https://github.com/WindowsAzure/azure-sdk-for-media-services giving  developers ability to fork, explore and contribute.

Test solution has been splited into 2 separate solutions:

  • Unit tests. Tests which are not require connection to REST API
  • Scenario tests. End 2 end test which are talking with REST API.

Also there were several refactoring within code base to make code more modular and mockable.