ComputeChecksum() public static method

public static ComputeChecksum ( byte bytes ) : uint
bytes byte
return uint
Ejemplo n.º 1
0
        private static string Shard(string input)
        {
            uint hash = Crc32.ComputeChecksum(Encoding.UTF8.GetBytes(input));

            return(((hash % 5 + 5) % 5 + 1).ToString());
        }
Ejemplo n.º 2
0
        public string BuildUrl(string source)
        {
            if (String.IsNullOrEmpty(m_cloudName))
                throw new ArgumentException("cloudName must be specified!");

            if (source == null) return null;

            if (m_action == "fetch" && !String.IsNullOrEmpty(FormatValue))
            {
                Transformation.FetchFormat(FormatValue);
                FormatValue = null;
            }

            string transformationStr = Transformation.Generate();

            if (Regex.IsMatch(source.ToLower(), "^https?:/.*"))
            {
                if (m_action == "upload" || m_action == "asset")
                {
                    return source;
                }
                source = Encode(source);
            }
            else
            {
                source = Encode(Decode(source));
                if (!String.IsNullOrEmpty(FormatValue))
                {
                    source += "." + FormatValue;
                }
            }


            string prefix;
            bool sharedDomain = !m_usePrivateCdn;
            string privateCdn = m_privateCdn;
            if (m_secure)
            {
                if (String.IsNullOrEmpty(privateCdn) || Cloudinary.OLD_AKAMAI_SHARED_CDN == privateCdn)
                {
                    privateCdn = m_usePrivateCdn ? m_cloudName + "-res.cloudinary.com" : Cloudinary.SHARED_CDN;
                }
                sharedDomain |= privateCdn == Cloudinary.SHARED_CDN;
                prefix = String.Format("https://{0}", privateCdn);
            }
            else
            {
                if (Regex.IsMatch(m_cloudinaryAddr.ToLower(), "^https?:/.*"))
                {
                    prefix = m_cloudinaryAddr;
                }
                else
                {
                    uint hash = Crc32.ComputeChecksum(Encoding.UTF8.GetBytes(source));
                    string subDomain = m_cSubDomain ? "a" + ((hash % 5 + 5) % 5 + 1) + "." : String.Empty;
                    string host = m_cName != null ? m_cName : (m_usePrivateCdn ? m_cloudName + "-" : String.Empty) + m_cloudinaryAddr;

                    prefix = "http://" + subDomain + host;
                }
            }

            List<string> urlParts = new List<string>(new string[] { prefix });
            if (!String.IsNullOrEmpty(m_apiVersion))
            {
                urlParts.Add(m_apiVersion);
                urlParts.Add(m_cloudName);
            }
            else if (sharedDomain)
            {
                urlParts.Add(m_cloudName);
            }

            if (m_shorten && m_resourceType == "image" && m_action == "upload")
            {
                m_resourceType = String.Empty;
                m_action = "iu";
            }

            urlParts.Add(m_resourceType);
            urlParts.Add(m_action);
            urlParts.AddRange(m_customParts);
            urlParts.Add(transformationStr);

            if (source.Contains("/") && !Regex.IsMatch(source, "^v[0-9]+/") && !Regex.IsMatch(source, "https?:/.*") && String.IsNullOrEmpty(m_version))
            {
                m_version = "1";
            }

            if (!String.IsNullOrEmpty(m_version))
                urlParts.Add(String.Format("v{0}", m_version));

            urlParts.Add(source);

            string uriStr = String.Join("/", urlParts.ToArray());
            uriStr = Regex.Replace(uriStr, "([^:])\\/+", "$1/");
            return Regex.Replace(uriStr, "/$", String.Empty);
        }
Ejemplo n.º 3
0
 private static string Shard(string input)
 {
     return(((Crc32.ComputeChecksum(Encoding.UTF8.GetBytes(input)) % 5U + 5U) % 5U + 1U).ToString());
 }
Ejemplo n.º 4
0
        public string BuildUrl(string source)
        {
            if (String.IsNullOrEmpty(m_cloudName))
            {
                throw new ArgumentException("cloudName must be specified!");
            }

            if (source == null)
            {
                return(null);
            }

            if (m_action == "fetch" && !String.IsNullOrEmpty(FormatValue))
            {
                Transformation.FetchFormat(FormatValue);
                FormatValue = null;
            }

            string transformationStr = Transformation.Generate();

            string original_source = source;

            if (Regex.IsMatch(source.ToLower(), "^https?:/.*"))
            {
                if (m_action == "upload" || m_action == "asset")
                {
                    return(original_source);
                }

                source = Encode(source);
            }
            else if (!String.IsNullOrEmpty(FormatValue))
            {
                source += "." + FormatValue;
            }

            if (m_secure && String.IsNullOrEmpty(m_privateCdn))
            {
                m_privateCdn = Cloudinary.SHARED_CDN;
            }

            string prefix;

            if (m_secure)
            {
                prefix = String.Format("https://{0}", m_privateCdn);
            }
            else
            {
                if (Regex.IsMatch(m_cloudinaryAddr.ToLower(), "^https?:/.*"))
                {
                    prefix = m_cloudinaryAddr;
                }
                else
                {
                    uint   hash      = Crc32.ComputeChecksum(Encoding.UTF8.GetBytes(source));
                    string subDomain = m_cSubDomain ? "a" + ((hash % 5 + 5) % 5 + 1) + "." : String.Empty;
                    string host      = m_cName != null ? m_cName : (m_usePrivateCdn ? m_cloudName + "-" : String.Empty) + m_cloudinaryAddr;

                    prefix = "http://" + subDomain + host;
                }
            }

            List <string> urlParts = new List <string>(new string[] { prefix });

            if (!String.IsNullOrEmpty(m_apiVersion))
            {
                urlParts.Add(m_apiVersion);
                urlParts.Add(m_cloudName);
            }
            else if (!m_usePrivateCdn || (m_secure && Cloudinary.AKAMAI_SHARED_CDN.Equals(m_privateCdn)))
            {
                urlParts.Add(m_cloudName);
            }

            urlParts.Add(m_resourceType);
            urlParts.Add(m_action);
            urlParts.AddRange(m_customParts);
            urlParts.Add(transformationStr);

            if (!String.IsNullOrEmpty(m_version))
            {
                urlParts.Add(String.Format("v{0}", m_version));
            }

            urlParts.Add(source);

            string uriStr = String.Join("/", urlParts.ToArray());

            uriStr = Regex.Replace(uriStr, "([^:])\\/+", "$1/");
            return(Regex.Replace(uriStr, "/$", String.Empty));
        }
Ejemplo n.º 5
0
        private static string Shard(string input)
        {
            uint hash = Crc32.ComputeChecksum(Encoding.UTF8.GetBytes(input));

            return(((((hash % 5) + 5) % 5) + 1).ToString(CultureInfo.InvariantCulture));
        }