All Products
Search
Document Center

Snapshot template

Last Updated: Jul 11, 2019

Initialize a client

Initialize a client before using the SDK. For more information, see InitVodClient.

Add a snapshot template

For more information about the request and response parameters, see AddVodTemplate.

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;
using Newtonsoft.Json.Linq;

namespace Aliyun.Acs.vod.Sdk.AddVodTemplate
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                AddVodTemplateResponse response = AddVodTemplate(client);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Adds a snapshot template.
        /// </summary>
        /// <returns>The snapshot template.</returns>
        /// <param name="client">The client.</param>
        public static AddVodTemplateResponse AddVodTemplate(DefaultAcsClient client)
        {
            // Constructs a request.
            AddVodTemplateRequest request = new AddVodTemplateRequest();
            // Sets the template name.
            request.Name = "addVodTemplate";
            // Sets the template type to Snapshot.
            request.TemplateType = "Snapshot";
            // Generates the snapshot template configuration.
            request.TemplateConfig = BuildSnapshotTemplateConfig();

            return client.GetAcsResponse(request);
        }

        /// <summary>
        /// Constructs the configuration of a snapshot template. Modify parameters as required.
        /// (The following sample code shows the complete sprite snapshot configuration.)
        /// </summary>
        /// <returns>The snapshot template configuration.</returns>
        public static string BuildSnapshotTemplateConfig()
        {
            JObject templateConfig = new JObject();
            JObject snapshotConfig = new JObject();
            snapshotConfig.Add("Count", "50");
            snapshotConfig.Add("Interval", "1");
            snapshotConfig.Add("SpecifiedOffsetTime", "0");
            snapshotConfig.Add("Width", "200");
            snapshotConfig.Add("Height", "200");
            // Specifies the normal snapshot configuration, which is shared with the original sprite snapshot configuration.
            templateConfig.Add("SnapshotConfig", snapshotConfig);
            // Specifies the sprite snapshot configuration, which must be constructed based on the normal snapshot configuration.
            JObject spriteSnapshotConfig = new JObject();
            spriteSnapshotConfig.Add("CellWidth", "120");
            spriteSnapshotConfig.Add("CellHeight", "68");
            spriteSnapshotConfig.Add("Columns", "3");
            spriteSnapshotConfig.Add("Lines", "10");
            spriteSnapshotConfig.Add("Padding", "20");
            spriteSnapshotConfig.Add("Margin", "50");
            spriteSnapshotConfig.Add("KeepCellPic", "keep");
            spriteSnapshotConfig.Add("Color", "tomato");
            snapshotConfig.Add("SpriteSnapshotConfig", spriteSnapshotConfig);

            // Sets the snapshot type. If the sprite snapshot is configured, set the value to SpriteSnapshot. If the sprite snapshot is not configured, set the value to NormalSnapshot.
            templateConfig.Add("SnapshotType", "SpriteSnapshot");

            return templateConfig.ToString();
        }
    }
}

Modify a snapshot template

For more information about the request and response parameters, see UpdateVodTemplate.

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;
using Newtonsoft.Json.Linq;

namespace Aliyun.Acs.vod.Sdk.UpdateVodTemplate
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                UpdateVodTemplateResponse response = UpdateVodTemplate(client);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Modifies a snapshot template.
        /// </summary>
        /// <returns>The response to the request for modifying a snapshot template.</returns>
        /// <param name="client">The client.</param>
        public static UpdateVodTemplateResponse UpdateVodTemplate(DefaultAcsClient client)
        {
            // Constructs a request.
            UpdateVodTemplateRequest request = new UpdateVodTemplateRequest();
            request.VodTemplateId = "53azf9d796fad9d7b862b2e5e5b";
            // Sets the template name.
            request.Name = "new template name";

            // Generates the snapshot template configuration.
            request.TemplateConfig = BuildSnapshotTemplateConfig();

            return client.GetAcsResponse(request);
        }

        /// <summary>
        /// Constructs the configuration of a snapshot template. Modify parameters as required.
        /// (The following sample code shows the complete normal snapshot configuration.)
        /// </summary>
        /// <returns>The snapshot template configuration.</returns>
        public static string BuildSnapshotTemplateConfig()
        {
            JObject templateConfig = new JObject();
            JObject snapshotConfig = new JObject();
            snapshotConfig.Add("Count", "50");
            snapshotConfig.Add("Interval", "1");
            snapshotConfig.Add("SpecifiedOffsetTime", "0");
            snapshotConfig.Add("Width", "200");
            snapshotConfig.Add("Height", "200");
            // Specifies the normal snapshot configuration, which is shared with the original sprite snapshot configuration.
            templateConfig.Add("SnapshotConfig", snapshotConfig);

            // Sets the snapshot type. If the sprite snapshot is configured, set the value to SpriteSnapshot. If the sprite snapshot is not configured, set the value to NormalSnapshot.
            templateConfig.Add("SnapshotType", "SpriteSnapshot");

            return templateConfig.ToString();
        }
    }
}

Delete a snapshot template

For more information about the request and response parameters, see DeleteVodTemplate.

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.DeleteVodTemplate
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                DeleteVodTemplateResponse response = DeleteVodTemplate(client);
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Deletes a snapshot template.
        /// </summary>
        /// <returns>The snapshot template.</returns>
        /// <param name="client">The client.</param>
        public static DeleteVodTemplateResponse DeleteVodTemplate(DefaultAcsClient client)
        {
            // Constructs a request.
            DeleteVodTemplateRequest request = new DeleteVodTemplateRequest();
            // Specifies the ID of the template to be deleted.
            request.VodTemplateId = "53azf9d796fad9d7b862b2e5e5b";

            return client.GetAcsResponse(request);
        }
    }
}

Query a list of snapshot templates

For more information about the request and response parameters, see ListVodTemplate.

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.ListVodTemplate
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                ListVodTemplateResponse response = ListVodTemplate(client);

                if (response.VodTemplateInfoList ! = null && response.VodTemplateInfoList.Count > 0) 
                {
                    foreach (ListVodTemplateResponse.ListVodTemplate_VodTemplateInfo templateInfo in response.VodTemplateInfoList) 
                    {
                        // The template ID.
                        Console.WriteLine("VodTemplateId = " + templateInfo.VodTemplateId);
                        // The template name. 
                        Console.WriteLine("Name = " + templateInfo.Name);
                    }
                }
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Queries a list of snapshot templates.
        /// </summary>
        /// <returns>The list of snapshot templates.</returns>
        /// <param name="client">The client.</param>
        public static ListVodTemplateResponse ListVodTemplate(DefaultAcsClient client)
        {
            // Constructs a request.
            ListVodTemplateRequest request = new ListVodTemplateRequest();
            // Sets the template type to Snapshot.
            request.TemplateType = "Snapshot";

            return client.GetAcsResponse(request);
        }
    }
}

Query a snapshot template

For more information about the request and response parameters, see GetVodTemplate.

using System;
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.vod.Model.V20170321;

namespace Aliyun.Acs.vod.Sdk.GetVodTemplate
{
    class MainClass
    {
        /// <summary>
        /// The main method.
        /// </summary>
        /// <param name="args">The command-line arguments.</param>
        public static void Main(string[] args)
        {
            try
            {
                DefaultAcsClient client = InitVodClient("<Your AccessKey ID>", "<Your AccessKey Secret>");
                // Initiates the request and obtains a response.
                GetVodTemplateResponse response = GetVodTemplate(client);
                if (response.VodTemplateInfo ! = null)
                {
                    // The template ID.
                    Console.WriteLine("VodTemplateId = " + templateInfo.VodTemplateId);
                    // The template name. 
                    Console.WriteLine("Name = " + templateInfo.Name);
                }
                Console.WriteLine("RequestId = " + response.RequestId);
            }
            catch (ServerException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (ClientException e)
            {
                if (e.RequestId ! = null)
                {
                    Console.WriteLine("RequestId = " + e.RequestId);
                }
                Console.WriteLine("ErrorCode = " + e.ErrorCode);
                Console.WriteLine("ErrorMessage = " + e.ErrorMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine("ErrorMessage = " + e.ToString());
            }
        }

        /// <summary>
        /// Queries a snapshot template.
        /// </summary>
        /// <returns>The snapshot template.</returns>
        /// <param name="client">The client.</param>
        public static GetVodTemplateResponse GetVodTemplate(DefaultAcsClient client)
        {
            // Constructs a request.
            GetVodTemplateRequest request = new GetVodTemplateRequest();
            // Specifies the ID of the template to be queried.
            request.VodTemplateId = "53azf9d796fad9d7b862b2e5e5b";

            return client.GetAcsResponse(request);
        }
    }
}