Пример #1
0
        /// <summary>
        /// An example program to generate the ImageService URL for a given Unumber
        /// </summary>
        public static void Main(string[] args)
        {
            /// Set to the connection type for ImageService server
            string imageServiceScheme = "http";
            /// Set to the hostname of your ImageService server.
            string imageServiceHost = "localhost";
            /// Set to the port of your ImageService server
            int imageServicePort = 8080;
            /// Set to the path of the ImageService path
            string imageServicePath = "/ImageService";
            /// Set to the name of the key you will be sending.
            string keyName = "test";
            /// Set to the value of the key you will using for encryption.
            string keyData = "AfoaKlDM4AjVyjo38f0NOs4O6hXM1T32";
            /// Set to the Unumber you want to get the image for
            string usfid = "U44989263";
            /// Custom plaintext separator (default is |)
            string separator = "-";

            string url = ImageServiceClient.getImageUrl(imageServiceHost, imageServicePath, keyName, keyData, usfid);

            Console.WriteLine("Normal image: " + url);
            string resized = ImageServiceClient.getResizedImageUrl(imageServiceHost, imageServicePath, keyName, keyData, usfid, 300, 300);

            Console.WriteLine("Resized to 300x300: " + resized);
            string httpUrl = ImageServiceClient.getImageUrl(imageServiceScheme, imageServiceHost, imageServicePort, imageServicePath, separator, keyName, keyData, usfid);

            Console.WriteLine("Normal image or HTTP: " + httpUrl);
        }
        /// <summary>
        /// Construct a URL to retreive an image for the specified USFid and resize the image to specific height/width values.
        /// </summary>
        /// <param name="scheme">The scheme of the ImageService server connection (http/https).</param>
        /// <param name="host">The hostname of the ImageService server.</param>
        /// <param name="port">The port of the ImageService service.</param>
        /// <param name="path">The base path of the ImageService service.</param>
        /// <param name="separator">Separtor charctore between itimestamp and identifier</param>
        /// <param name="keyName">Name of the encryption key that will be used.</param>
        /// <param name="keyData">Encryption key.</param>
        /// <param name="identifier">identifier for the requested image.</param>
        /// <param name="width">Image width in pixels.</param>
        /// <param name="height">Image height in pixels.</param>
        public static String getResizedImageUrl(String scheme, String host, int port, String path, String separator, String keyName, String keyData, String identifier, int width, int height)
        {
            String unixTimestamp = ((int)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds).ToString();

            String plaintext = unixTimestamp + separator + identifier;

            String encryptedToken = ImageServiceClient.encrypt(keyData, plaintext);

            UriBuilder uri = new UriBuilder();

            uri.Host   = host;
            uri.Port   = port;
            uri.Path   = path + "/view/" + keyName + "/" + width + "/" + height + "/" + encryptedToken + ".jpg";
            uri.Scheme = scheme;
            return(uri.ToString());
        }