예제 #1
0
        /// <summary>
        /// Simple multi request example showing how to start session and list media in a single HTTP request
        /// </summary>
        static void MultiRequestExample()
        {
            KalturaClient client = new KalturaClient(GetConfig());

            client.StartMultiRequest();

            client.SessionService.Start(ADMIN_SECRET, "", KalturaSessionType.ADMIN, PARTNER_ID, 86400, "");
            client.KS = "{1:result}"; // for the current multi request, the result of the first call will be used as the ks for next calls

            KalturaMediaEntryFilter filter = new KalturaMediaEntryFilter();

            filter.OrderBy = KalturaMediaEntryOrderBy.CREATED_AT_DESC;
            client.MediaService.List(filter, new KalturaFilterPager());

            KalturaMultiResponse response = client.DoMultiRequest();

            // in multi request, when there is an error, an exception is NOT thrown, so we should check manually
            if (response[1].GetType() == typeof(KalturaAPIException))
            {
                Console.WriteLine("Error listing media " + ((KalturaAPIException)response[1]).Message);

                // we can throw the exception if we want
                //throw (KalturaAPIException)response[1];
            }
            else
            {
                KalturaMediaListResponse mediaList = (KalturaMediaListResponse)response[1];
                Console.WriteLine("Total media entries: " + mediaList.TotalCount);
                foreach (KalturaMediaEntry mediaEntry in mediaList.Objects)
                {
                    Console.WriteLine("Media Name: " + mediaEntry.Name);
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Shows how to start session, create a mix, add media, and append it to a mix timeline using multi request
        /// </summary>
        private static void AdvancedMultiRequestExample()
        {
            KalturaClient client = new KalturaClient(GetConfig());

            client.StartMultiRequest();

            // Request 1
            client.SessionService.Start(ADMIN_SECRET, "", KalturaSessionType.ADMIN, PARTNER_ID, 86400, "");
            client.KS = "{1:result}"; // for the current multi request, the result of the first call will be used as the ks for next calls

            FileStream fileStream = new FileStream("DemoVideo.flv", FileMode.Open, FileAccess.Read);

            // Request 2
            KalturaUploadToken uploadToken = client.UploadTokenService.Add();

            // Request 3
            uploadToken = client.UploadTokenService.Upload("{2:result}", fileStream);

            // Request 4
            KalturaMediaEntry mediaEntry = new KalturaMediaEntry();

            mediaEntry.Name      = "Media Entry Using C#.Net Client To Test Flavor Replace";
            mediaEntry.MediaType = KalturaMediaType.VIDEO;
            mediaEntry           = client.MediaService.Add(mediaEntry);

            // Request 5
            KalturaUploadedFileTokenResource mediaResource = new KalturaUploadedFileTokenResource();

            mediaResource.Token = "{2:result:id}";
            mediaEntry          = client.MediaService.AddContent("{4:result}", mediaResource);

            // map paramters from responses to requests according to response calling order and names to request calling order and C# method parameter name
            client.MapMultiRequestParam(2, ":id", 3, "uploadTokenId");
            client.MapMultiRequestParam(4, ":id", 5, "entryId");

            KalturaMultiResponse response = client.DoMultiRequest();

            foreach (object obj in response)
            {
                if (obj.GetType() == typeof(KalturaAPIException))
                {
                    Console.WriteLine("Error occurred: " + ((KalturaAPIException)obj).Message);
                }
            }

            // when accessing the response object we will use an index and not the response number (response number - 1)
            if (response[4].GetType() == typeof(KalturaMediaEntry))
            {
                KalturaMediaEntry newMediaEntry = (KalturaMediaEntry)response[4];
                Console.WriteLine("Multirequest newly added entry id: " + newMediaEntry.Id);
            }
        }
예제 #3
0
        /// <summary>
        /// Shows how to start session, create a mix, add media, and append it to a mix timeline using multi request
        /// </summary>
        private static void AdvancedMultiRequestExample()
        {
            FileStream fileStream = new FileStream("DemoVideo.flv", FileMode.Open, FileAccess.Read);

            KalturaMediaEntry mediaEntry = new KalturaMediaEntry();

            mediaEntry.Name      = "Media Entry Using C#.Net Client To Test Flavor Replace";
            mediaEntry.MediaType = KalturaMediaType.VIDEO;

            KalturaUploadedFileTokenResource mediaResource = new KalturaUploadedFileTokenResource();

            mediaResource.Token = "{1:result:id}";

            KalturaClient client = new KalturaClient(GetConfig());

            client.KS = client.GenerateSession(ADMIN_SECRET, "", KalturaSessionType.ADMIN, PARTNER_ID);
            client.StartMultiRequest();
            client.UploadTokenService.Add();
            client.MediaService.Add(mediaEntry);
            client.UploadTokenService.Upload("{1:result:id}", fileStream);
            client.MediaService.AddContent("{2:result:id}", mediaResource);

            KalturaMultiResponse response = client.DoMultiRequest();

            foreach (object obj in response)
            {
                if (obj is KalturaAPIException)
                {
                    Console.WriteLine("Error occurred: " + ((KalturaAPIException)obj).Message);
                }
            }

            // when accessing the response object we will use an index and not the response number (response number - 1)
            if (response[3] is KalturaMediaEntry)
            {
                KalturaMediaEntry newMediaEntry = (KalturaMediaEntry)response[3];
                Console.WriteLine("Multirequest newly added entry id: " + newMediaEntry.Id + ", status: " + newMediaEntry.Status);
            }
        }
예제 #4
0
        static void PlaylistExecuteMultiRequestExample()
        {
            KalturaClient client = new KalturaClient(GetConfig());

            client.StartMultiRequest();

            // Request 1
            client.SessionService.Start(ADMIN_SECRET, "", KalturaSessionType.ADMIN, PARTNER_ID, 86400, "");
            client.KS = "{1:result}"; // for the current multi request, the result of the first call will be used as the ks for next calls

            // Request 2
            client.MediaService.List();

            KalturaMultiResponse response = client.DoMultiRequest();

            foreach (object obj in response)
            {
                if (obj.GetType() == typeof(KalturaAPIException))
                {
                    Console.WriteLine("Error occurred: " + ((KalturaAPIException)obj).Message);
                }
            }

            String twoEntries = "";

            if (response[1].GetType() == typeof(KalturaMediaListResponse))
            {
                KalturaMediaListResponse mediaListResponse = (KalturaMediaListResponse)response[1];
                twoEntries = mediaListResponse.Objects[0].Id + ", " + mediaListResponse.Objects[1].Id;
                Console.WriteLine("We will use the first 2 entries we got as a reponse: " + twoEntries);
            }

            if (twoEntries.Equals(""))
            {
                return;
            }

            string ks = client.GenerateSession(ADMIN_SECRET, USER_ID, KalturaSessionType.ADMIN, PARTNER_ID, 86400, "");

            client.KS = ks;

            KalturaPlaylist newPlaylist = new KalturaPlaylist();

            newPlaylist.Name            = "Test Playlist";
            newPlaylist.PlaylistContent = twoEntries;
            newPlaylist.PlaylistType    = KalturaPlaylistType.STATIC_LIST;

            KalturaPlaylist kPlaylist = client.PlaylistService.Add(newPlaylist);

            // new multirequest
            client.StartMultiRequest();

            client.PlaylistService.Execute(kPlaylist.Id);
            client.PlaylistService.Execute(kPlaylist.Id);

            response = client.DoMultiRequest();

            foreach (object obj in response)
            {
                if (obj.GetType() == typeof(KalturaAPIException))
                {
                    Console.WriteLine("Error occurred: " + ((KalturaAPIException)obj).Message);
                }
            }

            foreach (var currentResponse in response)
            {
                if (currentResponse.GetType() != typeof(KalturaMultiResponse))
                {
                    throw new Exception("Unexpected multirequest response");
                }
            }
        }