private PostVodPlaylistCommand(IServiceClient client, Uri endpoint,
                                ExecutionContext context,
                                PostVodPlaylistRequest request)
     : base(client, endpoint, context)
 {
     _request = request;
 }
 public static PostVodPlaylistCommand Create(IServiceClient client, Uri endpoint,
                                             ExecutionContext context,
                                             PostVodPlaylistRequest request)
 {
     OssUtils.CheckBucketName(request.BucketName);
     return(new PostVodPlaylistCommand(client, endpoint, context, request));
 }
        public static void BuildVodPlaylist(string bucketName)
        {
            string liveChannelName = "rtmp-test";

            try
            {
                var request = new PostVodPlaylistRequest(bucketName, liveChannelName);
                request.PlaylistName = "vod.m3u8";
                request.StartTime    = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1594286406);
                request.EndTime      = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1594286524);
                client.PostVodPlaylist(request);
            }
            catch (OssException ex)
            {
                Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}",
                                  ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed with error info: {0}", ex.Message);
            }
        }
        public void LiveChannelBasicTest()
        {
            string liveChannelName = "live-channel";
            var    clcRequest      = new CreateLiveChannelRequest(_bucketName, liveChannelName);

            clcRequest.Description  = "just for test";
            clcRequest.Status       = "enabled";
            clcRequest.FragDuration = 10;
            clcRequest.FragCount    = 5;
            clcRequest.PlaylistName = "playlist1.m3u8";
            var clcResult = _ossClient.CreateLiveChannel(clcRequest);

            Assert.AreEqual(clcResult.PublishUrl.Contains("live/live-channel"), true);
            Assert.AreEqual(clcResult.PlayUrl.Contains("live-channel/playlist1.m3u8"), true);


            var infoResult = _ossClient.GetLiveChannelInfo(new GetLiveChannelInfoRequest(_bucketName, liveChannelName));

            Assert.AreEqual(infoResult.Description, "just for test");
            Assert.AreEqual(infoResult.Status, "enabled");
            Assert.AreEqual(infoResult.Type, "HLS");
            Assert.AreEqual(infoResult.FragDuration, 10);
            Assert.AreEqual(infoResult.FragCount, 5);
            Assert.AreEqual(infoResult.PlaylistName, "playlist1.m3u8");

            _ossClient.SetLiveChannelStatus(new SetLiveChannelStatusRequest(_bucketName, liveChannelName, "disabled"));

            infoResult = _ossClient.GetLiveChannelInfo(new GetLiveChannelInfoRequest(_bucketName, liveChannelName));
            Assert.AreEqual(infoResult.Status, "disabled");

            var statResult = _ossClient.GetLiveChannelStat(new GetLiveChannelStatRequest(_bucketName, liveChannelName));

            Assert.AreEqual(statResult.Status, "Disabled");

            var historyResult = _ossClient.GetLiveChannelHistory(new GetLiveChannelHistoryRequest(_bucketName, liveChannelName));
            var LiveRecords   = OssTestUtils.ToArray(historyResult.LiveRecords);

            Assert.AreEqual(LiveRecords.Count, 0);

            var gvpRequest = new GetVodPlaylistRequest(_bucketName, liveChannelName);

            gvpRequest.StartTime = DateTime.Now;
            gvpRequest.EndTime   = DateTime.Now.AddMinutes(100);
            try
            {
                var gvpResult = _ossClient.GetVodPlaylist(gvpRequest);
                Assert.IsTrue(false, "should not here.");
            }
            catch (OssException e)
            {
                Assert.AreEqual(e.ErrorCode, "InvalidArgument");
                Assert.AreEqual(e.Message, "No ts file found in specified time span.");
            }

            var pvpRequest = new PostVodPlaylistRequest(_bucketName, liveChannelName);

            pvpRequest.PlaylistName = "test-playlist.m3u8";
            pvpRequest.StartTime    = DateTime.Now;
            pvpRequest.EndTime      = DateTime.Now.AddMinutes(100);
            try
            {
                _ossClient.PostVodPlaylist(pvpRequest);
                Assert.IsTrue(false, "should not here.");
            }
            catch (OssException e)
            {
                Assert.AreEqual(e.ErrorCode, "InvalidArgument");
                Assert.AreEqual(e.Message, "No ts file found in specified time span.");
            }

            _ossClient.DeleteLiveChannel(new DeleteLiveChannelRequest(_bucketName, liveChannelName));
        }