Example #1
0
        static void Main(string[] args)
        {
            //新建Catalog

               var createCatalog = catalogService.Add("catalog");
               Console.WriteLine("create catalog...");
               Console.WriteLine("name:" + createCatalog.Name + " id:" + createCatalog.Id);

               //根据Id查询Catalog

               var getCatalog = catalogService.Get(3);
               Console.WriteLine("get catalog...");
               Console.WriteLine("name:" + getCatalog.Name + " videoNumber:" + getCatalog.VideoNumber);

            //列出Catalog

            CatalogListRequest catalogRequest = new CatalogListRequest();
            var listCatalog = catalogService.List(catalogRequest);
            Console.WriteLine("list catalog...");
            foreach (var cata in listCatalog)
            {
                Console.WriteLine("id:" + cata.Id + " name:" + cata.Name);
            }

            //删除一个Catalog
            /**
            catalogService.Delete(41);
            Console.WriteLine("delete catalog...");
            **/

            //根据Id获取一个视频

            /**
            var getVideo = videoService.Get("322");
            Console.WriteLine("get video...");
            Console.WriteLine("name:" + getVideo.Name + " status:" + getVideo.Status + " size:"
                    + getVideo.Size + " type:" + getVideo.Type + " duration:" + getVideo.Duration
                    + " description:" + getVideo.Description + " catalogId:" + getVideo.CatalogId
                    + " catalogName:" + getVideo.CatalogName);

            foreach (var embedCode in getVideo.EmbedCodes)
            {
                Console.WriteLine("autoAdaptionCode:" + embedCode.AutoAdaptionCode + " Clarity:"
                        + embedCode.Clarity + " FlashCode:" + embedCode.FlashCode + " Html5Code:"
                        + embedCode.Html5Code + " Resolution:" + embedCode.Resolution + " filePath:"
                        + embedCode.FilePath  + " portableCode:" + embedCode.PortableCode);
            }
               **/

            //上传一个视频
            /**
            var fileInfo = new System.IO.FileInfo(@"d:\wangjj\Prince.flv");
            var uploadRequest = new VideoUploadRequest();

            uploadRequest.Name = "name";
            uploadRequest.Description = "desc";
            uploadRequest.FileInfo = fileInfo;
            var uploadVideo = videoService.Upload(uploadRequest);
            Console.WriteLine("upload video...");
            Console.WriteLine("name:" + uploadVideo.Name + " status:" + uploadVideo.Status + " size:"
                       + uploadVideo.Size + " type:" + uploadVideo.Type + " duration:" + uploadVideo.Duration
                       + " catalogId:" + uploadVideo.CatalogId + " catalogName:" + uploadVideo.CatalogName);
             foreach (var embedCode in uploadVideo.EmbedCodes)
             {
                 Console.WriteLine("autoAdaptionCode:" + embedCode.AutoAdaptionCode + " Clarity:"
                         + embedCode.Clarity + " FlashCode:" + embedCode.FlashCode + " Html5Code:"
                         + embedCode.Html5Code + " Resolution:" + embedCode.Resolution + " filePath:"
                         + embedCode.FilePath + " portableCode:" + embedCode.PortableCode);
             }
             **/

             //列出视频
             /**
             var listRequest = new VideoListRequest();

             var listVideo = videoService.List(listRequest);
             Console.WriteLine("list video...");
             foreach (var video in listVideo)
             {
                 Console.WriteLine("name:" + video.Name + " id:" +  video.Id + " status:" + video.Status + " size:"
                            + video.Size + " type:" + video.Type + " duration:" + video.Duration
                            + " catalogId:" + video.CatalogId + " catalogName:" + video.CatalogName);

             }
             **/

             //更新视频信息
             /**
             var updateRequest = new VideoUpdateRequest();
             updateRequest.Name = "testName";
             updateRequest.VideoId = 341;
             updateRequest.Description = "testDescription";
             videoService.Update(updateRequest);
             Console.WriteLine("update video...");
             **/

             //删除一个视频
             /**
             videoService.Delete(236);
             Console.WriteLine("delete video...");
             **/

             //断点续传
             /**
             var file = new System.IO.FileInfo(@"d:\wangjj\Prince.flv");
             int partSize = 2 * 1024 * 1024; // 4M

             var fileUploadRequest = new FileUploadRequest();
             fileUploadRequest.PartSize = partSize;
             fileUploadRequest.FileInfo = file;
             var video = multipartService.Upload(fileUploadRequest);

             Console.WriteLine("multipart upload...");
             Console.WriteLine("name:" + video.Name + " status:" + video.Status + " size:"
                       + video.Size + " type:" + video.Type + " duration:" + video.Duration
                       + " catalogId:" + video.CatalogId + " catalogName:" + video.CatalogName);
             foreach (var embedCode in video.EmbedCodes)
             {
                 Console.WriteLine("autoAdaptionCode:" + embedCode.AutoAdaptionCode + " Clarity:"
                        + embedCode.Clarity + " FlashCode:" + embedCode.FlashCode + " Html5Code:"
                        + embedCode.Html5Code + " Resolution:" + embedCode.Resolution + " filePath:"
                        + embedCode.FilePath + " portableCode:" + embedCode.PortableCode);
             }

             **/
        }
        /// <summary>
        /// 列出Catalog
        /// </summary>
        /// <param name="request"></param>
        /// <returns>Catalog列表,包含id,name字段,但videoNumber字段的值为空</returns>
        public List<Catalog> List(CatalogListRequest request)
        {
            var qs = new QueryString();
            if (null != request.NameLike && !"".Equals(request.NameLike))
            {
                qs.Add("nameLike", request.NameLike);
            }
            if (request.Page > 0)
            {
                qs.Add("page", request.Page.ToString());
            }
            if (request.MaxResult > 0)
            {
                qs.Add("maxResult", request.MaxResult.ToString());
            }

            var listCata = client.HttpGet("/catalog/list.api", qs);

            var jo = JObject.Parse(listCata);
            if (jo["statusCode"].ToString().CompareTo("0") == 0)
            {
                var catalogs = jo["catalogs"];
                var list = new List<Catalog>();
                foreach (Object obj in catalogs)
                {
                    var jObj = (JObject)obj;
                    var cata = new Catalog();
                    cata.Id = System.Int32.Parse(jObj["id"].ToString());
                    cata.Name = jObj["name"].ToString();

                    list.Add(cata);
                }
                return list;
            }
            else
            {
                throw new PispowerAPIException(System.Int32.Parse(jo["statusCode"].ToString()), jo["message"].ToString());
            }
        }