/// <summary>
        /// Create a library.
        /// </summary>
        /// <returns>The created library.</returns>
        private async Task <Library> CreateLibrary()
        {
            var userID = await this.GetUserID().ConfigureAwait(false);

            var createLibraryRequest = new CreateLibraryRequest
            {
                Id          = $"CDMServicesDemo:PSet:Library-{Guid.NewGuid().ToString()}", // Optional (if not specified, the service will auto-generate it)
                Name        = "DemoLibrary",                                               // Optional
                Description = "A demo library",                                            // Optional
                Policy      = new Policy                                                   // Optional
                {
                    Statements = new PolicyStatement[]
                    {
                        new PolicyStatement
                        {
                            Effect    = "Allow",
                            Principal = new JValue($"user:{userID}"),
                            Action    = new JValue("*"),
                            Resource  = new JValue("*"),
                        },
                    },
                },
            };

            Console.WriteLine($"Creating library with Id={createLibraryRequest.Id}, Name={createLibraryRequest.Name}, Description={createLibraryRequest.Description}...");

            Library library = await this.psetClient.CreateLibraryAsync(createLibraryRequest).ConfigureAwait(false);

            Console.Write($"Created library: ");
            this.PrintLibrary(library);
            Console.WriteLine();

            return(library);
        }
Beispiel #2
0
        /// <summary>
        ///     Creates a new encrypted library with the given name, description and password
        /// </summary>
        /// <param name="name">The name of the library</param>
        /// <param name="description">The description of the library</param>
        /// <param name="password">
        ///     The password to encrypt the library with. Will be overwritten with zeroes as soon as the request
        ///     has been sent
        /// </param>
        /// <returns></returns>
        public async Task <SeafLibrary> CreateEncryptedLibrary(string name, string description, char[] password)
        {
            var request = new CreateLibraryRequest(AuthToken, name, description, password);
            var result  = await _webConnection.SendRequestAsync(ServerUri, request);

            return(await GetLibraryInfo(result.Id));
        }
        /// <summary>
        /// 创建 PaaS 服务媒体库
        /// </summary>
        /// <param name="req"><see cref="CreateLibraryRequest"/></param>
        /// <returns><see cref="CreateLibraryResponse"/></returns>
        public CreateLibraryResponse CreateLibrarySync(CreateLibraryRequest req)
        {
            JsonResponseModel <CreateLibraryResponse> rsp = null;

            try
            {
                var strResp = this.InternalRequestSync(req, "CreateLibrary");
                rsp = JsonConvert.DeserializeObject <JsonResponseModel <CreateLibraryResponse> >(strResp);
            }
            catch (JsonSerializationException e)
            {
                throw new TencentCloudSDKException(e.Message);
            }
            return(rsp.Response);
        }
        /// <summary>
        /// Create a new library by using additional properties in the request.
        /// </summary>
        /// <returns>The created library.</returns>
        private async Task <Library> CreateLibraryUsingAdditionalProperties()
        {
            var createLibraryRequest = new CreateLibraryRequest
            {
                AdditionalProperties = new Dictionary <string, JToken>
                {
                    { "Name", "Demo library " },
                    { "Description", "Demo library" },
                },
            };

            Console.WriteLine($"Creating library (using additional properties) with Name={createLibraryRequest.AdditionalProperties["Name"]}, " +
                              $"Description={createLibraryRequest.AdditionalProperties["Description"]}...");

            Library createdLibrary = await this.psetClient.CreateLibraryAsync(createLibraryRequest).ConfigureAwait(false);

            Console.Write("Created library: ");
            this.PrintLibrary(createdLibrary);
            Console.WriteLine();

            return(createdLibrary);
        }